Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-29-2011, 07:29 PM
PhilSmith PhilSmith is offline
Workin' on It
PhilSmith's Avatar
Join Date: Mar 2011
Location: Chicago
Posts: 38
PhilSmith is on a distinguished road
I think i covered most of your edits. I was confused by two of them:

1) check in all lowercase. I'm not really sure what the point of this was. Could you elaborate a little more on its purpose please?

2) the filter. I understand that it is a quicker way of checking than mine, but i just couldnt get it to work.

aside from those, I corrected the other parts and added the community name and clientside shared.chat.

PHP Code:
// Scripted by Phil Smith
function onActionServerSide(searchtemp.action){
//for loop to find all players and their partial nicks
  
temp.foundPlayers.destroy();
  for(
temp.pl allplayers){
    if(
temp.pl.account.starts(search)|| temp.pl.communityName.starts(search) || temp.pl.nick.starts(search)){
      if (
temp.pl.level!=NULL){ //if player is not on rc
        
temp.foundPlayers.add(temp.pl); //logs the player into the array
      
}
    }
  } 
  if (
temp.foundPlayers.size()==1){
    
onPlayerFound(temp.actiontemp.foundPlayers[0]);
  }
  if(
temp.foundPlayers.size()<1){
    
player.chat="No Players Found!";
  }
  if(
temp.foundPlayers.size()>1){
    
triggerclient("weapon",this.name,"NoneFound",temp.foundPlayers);
  }
}
function 
onPlayerFound(temp.functemp.pl){
  if (
temp.func=="summon"){
    
temp.pl.setlevel2(player.level.name,player.x,player.y);
  }
  else if(
temp.func=="warp"){
    
setlevel2(temp.pl.level,temp.pl.x,temp.pl.y);
  }
}
//#CLIENTSIDE
function onActionClientSide(temp.actiontemp.chatarray){
  if(
temp.action=="NoneFound"){
    
shared.chat(temp.chatarray.size() SPC "Players Were Found!:");
    
sleep(2);
    for(
temp.i==0;temp.i<temp.chatarray.size();temp.i++){
      
shared.chat(temp.chatarray[temp.i]);
      
sleep(4);
    }
  }
}
function 
onPlayerChats(){
  if(
player.chat.starts("/warp")){
    
triggerserver("weapon",this.name,player.chat.substring(6),"warp");
  }
  if(
player.chat.starts("/summon")){

    
triggerserver("weapon",this.name,player.chat.substring(8),"summon");
  }

__________________
Nothing to say...
Reply With Quote
  #2  
Old 03-29-2011, 08:58 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
Quote:
Originally Posted by PhilSmith View Post
[New Version]
Don't be afraid of using } else if {. It is best to be explicit about how your program 'branches' than force whoever is reading it to think about it themselves.

For example, temp.foundPlayers.size()==1 and temp.foundPlayers.size()<1 both clearly can never be true at the same time, but you should always make that clear just in case the conditions are not so clearly disjoint like they are here.


Also, temp.foundPlayers.destroy(); at the start of a function makes no sense. temp.foundPlayers won't even exist then. If you are going to use it as an array, it is best to create one at that point: temp.foundPlayers = {};


Regarding the filter thing, it's just an interesting note. Most people don't program like that in GS2, but I think more people should. The less code you write, the less that can go wrong.

If you're curious about it, let me know what you tried and I can hopefully tell you what went wrong.
Reply With Quote
  #3  
Old 03-29-2011, 09:52 PM
PhilSmith PhilSmith is offline
Workin' on It
PhilSmith's Avatar
Join Date: Mar 2011
Location: Chicago
Posts: 38
PhilSmith is on a distinguished road
First, I normally do use else ifs. I dont know what i was doing with this one, but i must have forgot.
Second, my temp.foundPlayers.destroy() was me being dumb. I looked up on the wiki what i actually needed to put and fixed it. Idk why it is still there in this one...
third, i believe i put something like this:
PHP Code:
temp.= function (temp.pl,search) {
    return (
temp.pl.account.starts(search)|| temp.pl.communityname.starts(search)|| temp.pl.nick.starts(search) && temp.pl.level != NULL;
  };
  
temp.foundPlayers filter(temp.fallplayers); 
search in this case was the string for the substring player.chat. In otherwords, the player i was searching for.
__________________
Nothing to say...
Reply With Quote
  #4  
Old 03-29-2011, 10:00 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by WhiteDragon View Post
Regarding the filter thing, it's just an interesting note. Most people don't program like that in GS2, but I think more people should. The less code you write, the less that can go wrong.
I would totally use functions like filter more if they were built-in or at least able to implemented un-obtrusively.
__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.