I just created this script and thought it was nice. It is my first actual code so I come here seeking advice, suggestions, and
perhaps ways to make the script simpler. I am in no way trying to show off the usefulness of this script, I was merely making it for practice. I know it may be pointless, however, that is not what is in question here. Save yourself some time and a post if you are going to say that
Functions:
-Obvious summon and warping ability ("/warp name" or "/summon name")
-Can find players based on partial names (instead of "PhilSmith" it could work with "Phil" or "P")
-when using a partial name, it logs all the names found in an array. If one name is found, it warps/summons. If zero names are found, it says"No Players Found". If more than one name are found, it pms the array to the player.
PHP Code:
// Scripted by Phil Smith
function onActionServerSide(){
//for loop to find all players and their partial nicks
for(temp.pl : allplayers){
if(params[0]==temp.pl.substring(0,params[0].length())|| params[0]==temp.pl.nick.substring(0,params[0].length())){
if (temp.pl.level!=NULL){ //if player is not on rc
this.fnd=temp.pl;
temp.foundplayer.add(temp.pl); //logs the player into the array
}
}
}
if (temp.foundplayer.size()==1){
onPlayerFound();
}
else if(temp.playerfound.size==0){
player.chat="No Players Found!";
}
//more than one players are found
else{ player.chat="More than one player found! Check your PM for options.";
player.sendPM(temp.foundplayer.size() SPC "players were found:" NL temp.foundplayer NL "" NL "" NL "Tip: Be sure to type in the player's name/account as specific as possible in order to find them easier!");
}
}
//carries out the warp/summon
function onPlayerFound(){
if (params[1].starts("/summon")){
this.fnd.setlevel2(player.level,player.x,player.y);
updateboard(0,0,64,64);
this.fnd.chat="Summoned!";
}
if (params[1].starts("/warp")){
setlevel2(this.fnd.level,this.fnd.x,this.fnd.y);
player.chat="Warped!";
}
}
//#CLIENTSIDE
function onPlayerChats(){
if(player.chat.starts("/warp")){
tokens=player.chat.substring(6);
triggerserver("weapon",this.name,tokens,player.chat);
}
if(player.chat.starts("/summon")){
tokens=player.chat.substring(8);
triggerserver("weapon",this.name,tokens,player.chat);
}
}
Thanks for taking the time to submit useful feedback and suggestions!
