So I was scripting in an online editor and was annoyed by the people popping into the level to see what I was working on. So I scripted a system to remove players froma level in the offline editor in GS1. As part of my practice learning GS2 I want input on mistakes I made, how to make the script more efficient, design security for the NPC, and finally convert the script into GS2. Any advice is appreciated.
PHP Code:
// Script to add/remove players from ban list
if (playerchats) {
if (strequals(#a,maximus_asinus)) {
if (startswith(/add,#c)) {
tokenize #c;
this.duplicate = false;
if (strequals(#t(1),#a)) {
setplayerprop #c,You cannot ban yourself.;
}
else {
for (i=0;i<sarraylen(server.warp);i++;) {
if (strequals(#I(server.warp,i),#t(1))) {
this.duplicate = true;
}
}
if (this.duplicate == true) {
setplayerprop #c,"#t(1)" is already on the ban list.;
}
else {
addstring server.warp,#t(1);
setplayerprop #c,Added "#t(1)" to the ban list.;
}
}
}
if (startswith(/remove,#c)) {
tokenize #c;
for (i=0;i<sarraylen(server.warp);i++;) {
if (strequals(#I(server.warp,i),#t(1))) {
deletestring server.warp,i;
setplayerprop #c,Removed "#t(1)" from the ban list.;
}
}
}
}
}
PHP Code:
// Script that removes the player
if (created) timeout = 0.05;
if (timeout) {
for (i=0;i<sarraylen(server.warp);i++;) {
if (strequals(#I(server.warp,i),#a)) {
setplayerprop #c,You're banned from this level.;
setlevel2 onlinestartlocal.nw,30,30;
}
}
timeout = 0.05;
}
I'm assuming placing a for loop inside a never ending timeout is bad practice and possibly process intensive. Can you manipulate another player's level and coordinates through a script like this? That way I could remove the player when I add them to the list and only have a playerenters check to see if they're on the list which would eliminate the timeout completely. This would also help me understand how you can manipulate other players via script.
Also I think I read that variables can now be assigned text values in GS2 like how strings work in GS1. Can you manipulate those variables in the same way as I am doing it in my script? If so, how?