PHP Code:
function onActionServerSide() {
temp.foundPlayers = {};
for (temp.pl : allplayers) {
if ( ( params[0] == temp.pl.account.substring(0, params[0].length())
|| params[0] == temp.pl.nick.substring(0, params[0].length())
) && temp.pl.level != NULL) {
temp.foundPlayers.add(temp.pl);
}
}
temp.s = temp.foundPlayers.size();
if (temp.s > 1) {
player.chat = "More than one player found! Check your PM for options.";
player.sendPM("Multiple players were found:" NL temp.foundPlayers NL "" NL "" NL "Tip: Be sure to type in the player's name/account as specific as possible in order to find them easier!");
} else if (temp.s == 1) {
playerFound(params[1], temp.foundPlayers[0]);
} else {
player.chat = "No Players Found!";
}
}
function playerFound(temp.actionType, temp.pl) {
if (temp.actionType == "summon") {
temp.pl.setlevel2(player.level, player.x, player.y);
updateboard(0, 0, 64, 64);
temp.pl.chat = "Summoned!";
} else if (temp.actionType == "warp") {
setlevel2(temp.pl.level, temp.pl.x, temp.pl.y);
player.chat = "Warped!";
}
}
//#CLIENTSIDE
function onPlayerChats(){
if (player.chat.starts("/warp")) {
triggerserver("weapon", this.name, player.chat.substring(6), "warp");
} else if (player.chat.starts("/summon")) {
triggerserver("weapon", this.name, player.chat.substring(8), "summon");
}
}
Here is my "code clarity" edit (I kept the logic the same). Feel free to ask any questions.
Note: interestingly enough, that loop at the beginning of the code has a name:
filter. I have wrapped up some common patterns such as
filter in this thread. With my code the first loop would simply be:
PHP Code:
temp.f = function (temp.pl) {
return (params[0] == temp.pl.account.substring(0, params[0].length()) || params[0] == temp.pl.nick.substring(0, params[0].length())) && temp.pl.level != NULL;
};
temp.foundPlayers = filter(temp.f, allplayers);