It's not bad at all, but there are some things that can be improved.
PHP Code:
if(params[0]==temp.pl.substring(0,params[0].length())|| params[0]==temp.pl.nick.substring(0,params[0].length())){
There are a couple of issues with this line.
You can improve the substring check by using
str.starts(substring). I doubt it's really any more efficient but it's semantically better as it makes your purpose clearer to the reader.
PHP Code:
if(temp.pl.starts(params[0]) || temp.pl.nick.starts(params[0])){
The other problem is that
temp.pl is referring to the actual player object right now, not their account. The reason it works as-is is that Graal internally converts objects to strings when necessary by using the object's name, which happens to be the player's account name. It's better practice to do it like so (note I'm using
temp.pl.communityName):
PHP Code:
temp.pl.communityName.starts(params[0])
You should also fix this where you're sending a PM.
It's also better practice to pass parameters to functions instead of setting variables. For example, in your player found function:
PHP Code:
function onPlayerFound(){
you would use
PHP Code:
function onPlayerFound(playerFound) {
When calling it you would pass the player object to it.
PHP Code:
if (temp.foundplayer.size()==1){
onPlayerFound(temp.foundplayer[0]);
}
Since
setlevel2's first parameter is a level name, not a level object, you should do this (note
player.level.name; this is similar to the issue with the account):
PHP Code:
this.fnd.setlevel2(player.level.name,player.x,player.y);
I would also recommend reorganizing the script so that you're not sending the player's chat but rather the just the command ("summon" or "warp") and the account. Then you would want to do something like this:
PHP Code:
function onActionServerSide(cmd, search) {
if (cmd == "warp") {
temp.pl = searchForPlayer(search);
if (pl == null) {
return pl.chat = "Found multiple players!"; // ends the function
}
player.setlevel2(pl.level.name, pl.x, pl.y);
} else if (cmd =="summon") {
temp.pl = searchForPlayer(search);
if (pl == null) {
return pl.chat = "Found multiple players!"; // ends the function
}
pl.setlevel2(player.level.name, player.x, player.y);
}
}
function searchForPlayer(search) {
for (temp.pl : allplayers) {
// your search code here
}
return temp.foundPlayer;
}
Let me know if any of this doesn't make sense.
edit: sorry for the repeats, all of the posts except the OP were while I wrote this
There is a way to keep a player's chat from resetting after a few seconds but it can only be done on clientside, so you would have to trigger back.
PHP Code:
shared.chat("chat here");