View Single Post
  #4  
Old 03-29-2011, 04:38 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
PHP Code:
function onActionServerSide() {
  
temp.foundPlayers = {};
  for (
temp.pl allplayers) {
    if ( (     
params[0] == temp.pl.account.substring(0params[0].length())
            || 
params[0] == temp.pl.nick.substring(0params[0].length())
          ) && 
temp.pl.level != NULL) {
      
temp.foundPlayers.add(temp.pl);
    }
  }
  
temp.temp.foundPlayers.size();
  if (
temp.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.== 1) {
    
playerFound(params[1], temp.foundPlayers[0]);
  } else {
    
player.chat "No Players Found!";
  }
}
function 
playerFound(temp.actionTypetemp.pl) {
  if (
temp.actionType == "summon") {
    
temp.pl.setlevel2(player.levelplayer.xplayer.y);
    
updateboard(006464);
    
temp.pl.chat "Summoned!";
  } else if (
temp.actionType == "warp") {
    
setlevel2(temp.pl.leveltemp.pl.xtemp.pl.y);
    
player.chat "Warped!";
  }
}

//#CLIENTSIDE
function onPlayerChats(){
  if (
player.chat.starts("/warp")) {
    
triggerserver("weapon"this.nameplayer.chat.substring(6), "warp");
  } else if (
player.chat.starts("/summon")) {
    
triggerserver("weapon"this.nameplayer.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.= function (temp.pl) {
    return (
params[0] == temp.pl.account.substring(0params[0].length()) || params[0] == temp.pl.nick.substring(0params[0].length())) && temp.pl.level != NULL;
  };
  
temp.foundPlayers filter(temp.fallplayers); 

Last edited by WhiteDragon; 03-29-2011 at 05:16 PM..
Reply With Quote