Results 1 to 7 of 7

Thread: Joe's Scripts - Staff/Players Commands

  1. #1
    Soldier
    Join Date
    Jun 2013
    Location
    France
    Posts
    55

    Post Joe's Scripts - Staff/Players Commands

    Hi Graalians,

    I am Joe (leader of Les Frenchies on iEra), and today I wanna share my scripting skills.
    I script in many langages like HTML/CSS, PHP/SQL, C++, JAVA and actually I am working on Android Apps.
    I also learnt few years ago how to script in GS2 which haven't been hard due to my knowledge in others scripting langages.

    Today, I just wanna share my Staff/Player Commands script.

    So you need to add to Staff the Staff Commands weapon and by default to player, the Player Commands weapon.

    Here is the Staff Commands weapon: -Staff/StaffCmd
    This weapon include few commands: /warp playerId, /summon playerId, /freeze playerId, /unfreeze playerId, /gag playerId, /ungag playerId, /ani ganiName, setap apNumber, /reconnect, /tag gangName, sethat hatName, and also if you press "C" you get your coords.

    PHP Code:
    // Scripted by Joe
    function onActionServerSide(cmdSendtokens)
    {
      if(
    cmdSend.starts("/summon") || cmdSend.starts("/warp") || cmdSend.starts("/freeze") || cmdSend.starts("/unfreeze") || cmdSend.starts("/gag") || cmdSend.starts("/ungag"))
      {
        for(
    temp.pl allplayers){
          if(
    tokens == temp.pl.substring(0,tokens.length())|| tokens == temp.pl.nick.substring(0,tokens.length()))
          {
            if (
    temp.pl.level!=NULL)
            {
              
    this.fnd=temp.pl;
              
    temp.foundplayer.add(temp.pl);
            }
          }
        }
        if (
    temp.foundplayer.size()==1){
          if (
    cmdSend.starts("/summon")){
            
    this.fnd.setlevel2(player.level,player.x,player.y);
            
    this.fnd.unfreezeplayer();
            
    updateboard(0,0,64,64);
            
    this.fnd.chat="Summoned!";
          }
          if (
    cmdSend.starts("/warp")){
            
    setlevel2(this.fnd.level,this.fnd.x,this.fnd.y);
            
    player.chat="Warped!";
          }
          if (
    cmdSend.starts("/freeze")){
            
    this.fnd.setlevel2(player.level,player.x,player.y);
            
    this.fnd.freezeplayer2();
            
    updateboard(0,0,64,64);
            
    this.fnd.chat="I'm Frozen!";
          }
          if (
    cmdSend.starts("/unfreeze")){
            
    this.fnd.setlevel2(player.level,player.x,player.y);
            
    this.fnd.unfreezeplayer();
            
    updateboard(0,0,64,64);
            
    this.fnd.chat="I'm unfrozen!";
          }
          if (
    cmdSend.starts("/gag")){
            if(
    this.fnd.clientr.player_gagged != null){
            
    player.chat="This player already gagged!";
            return;
            }
            
    this.fnd.chat "*Gagged*";
            
    this.fnd.clientr.player_gagged=timevar2+(params[2]*60);
            
    this.fnd.addweapon("-Players/PlayersCmd");
          }
          if (
    cmdSend.starts("/ungag")){
            if(
    this.fnd.clientr.player_gagged == null){
              
    player.chat="This player isn't gagged!";
              return;
            }
            
    player.chat "done.";
            
    this.fnd.chat "*Ungagged by *" player.nick;
            
    this.fnd.clientr.player_gagged=0;
            
    this.fnd.addweapon("-Players/PlayersCmd");
          }
        }
        else if(
    temp.playerfound.size==0){
          
    player.chat="No Players 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!");
        }
      }
      if(
    cmdSend.starts("setap"))
      {
        
    player.ap tokens[1];
      }
      if (
    params[0] == "guildself")
      {
        if(
    isStaffGuild(params[1]))
        {
          if(
    params[1] == player.clientr.staffGuild)
          {
            
    player.guild params[1];
          }
          else
          {
            
    player.chat "You aren't allowed to set that tag!";
          }
        }
        else
        {
          
    player.guild params[1];
        }
      }
    }

    function 
    isStaffGuild(Plguild)
    {
      
    temp.guildstaff serveroptions.staffguilds.tokenize(",");
      
    temp.guildstaff temp.guildstaff.upper();
      
    temp.Plguild Plguild.upper();

      if(
    temp.Plguild in temp.guildstaff){
        if(
    temp.Plguild != "Admin")
        {
          return 
    true;
        }
      }
    }

    //#CLIENTSIDE
    function onPlayerChats(){
      if(
    player.chat.starts("/warp"))
      {
        
    cmdSend player.chat;
        
    tokens=player.chat.substring(6);
        
    triggerserver("weapon",this.name,cmdSend,tokens);
      }
      if(
    player.chat.starts("/summon"))
      {
        
    cmdSend player.chat;
        
    tokens=player.chat.substring(8);
        
    triggerserver("weapon",this.name,cmdSend,tokens);
      }
      if(
    player.chat.starts("/freeze"))
      {
        
    cmdSend player.chat;
        
    tokens=player.chat.substring(8);
        
    triggerserver("weapon",this.name,cmdSend,tokens);
      }
      if(
    player.chat.starts("/unfreeze"))
      {
        
    cmdSend player.chat;
        
    tokens=player.chat.substring(10);
        
    triggerserver("weapon",this.name,cmdSend,tokens);
      }
      if(
    player.chat.starts("/gag"))
      {
        
    cmdSend player.chat;
        
    tokens=player.chat.tokenize();
        if(
    tokens[2]<1||tokens[2]>30)return;
        
    triggerserver("weapon",this.name,cmdSend,tokens[1],tokens[2]);
      }
     if(
    player.chat.starts("/ungag"))
      {
        
    cmdSend player.chat;
        
    tokens=player.chat.tokenize();
        
    triggerserver("weapon",this.name,cmdSend,tokens[1]);

      }
      if (
    player.chat.starts("/ani")) {
         
    tokens player.chat.tokenize();
         
    setani(tokens[1],tokens[2]);
      }
      if (
    player.chat.starts("setap")) {
        
    cmdSend player.chat;
        
    tokens player.chat.tokenize();
        
    triggerserver("weapon",this.name,cmdSend,tokens);
      }
      if(
    player.chat == "/reconnect") {
        
    ServerWarp(ServerName);
      }
      if (
    player.chat.starts("/tag ")) {
        
    triggerserver("weapon"this.name"guildself"player.chat.substring(5, -1));
      }
       if (
    player.chat.starts("sethat")) {
        
    player.attr[1] = player.chat.substring(7);
      }
    }
    function 
    onKeyPressed(code,key)
    {
      if(
    key == "c" || key == "C"){
        
    player.chat player.level SPC "," SPC player.x SPC player.y;
      }

    And here is the Player Commands weapon: -Players/PlayersCmd
    It includes: /reconnect, showlag and if you press "A" you grab.

    PHP Code:
    function onActionServerSide(cmd
    {
      if(
    cmd == "showlag"){
        
    getPing();
      } 
      if(
    cmd == "checkGag"){
        if (
    player.clientr.player_gagged timevar2) {
         
    temp.msg formattimestring("Timers Remain Gagged: %M Min's %S Sec's",player.clientr.player_gagged timevar2);
         
    player.chat=temp.msg;
         return;
        }
         
    player.clientr.player_gagged 0;
      }
    }

    function 
    getPing() {
      
    temp.obj player.sendping();
      
    this.catchevent(obj"onReceivePing""onGPingReply");
    }

    function 
    onGPingReply(objplyrtime) {
      
    plyr.chat int(time 1000) @ "ms";
    }


    //#CLIENTSIDE

    function onKeyPressed(code,key)
    {
      if(
    key == "a" || key == "A"){
        
    setAni("grab"NULL);
      }
    }
    function 
    onPlayerChats() {
      if(
    player.chat == "/reconnect") {
        
    ServerWarp(ServerName);
        
    player.chat "";
      }
      if(
    player.chat == "showlag"){
        
    triggerserver("weapon"this.name"showlag");
      }
      if (
    clientr.player_gagged != null) {
            
    player.chat "*Gagged*";
            
    triggerserver("weapon"this.name"checkGag""");
            return 
    true;
          }

    Well, I hope you understood everything but if you have any questions about that script or just about scripting, don't hesitate to ask, I'll do my best to help you.

    See you Graalians!

  2. #2
    I can understand the approach you took here:
    PHP Code:
    if(cmdSend.starts("/summon") || cmdSend.starts("/warp") || cmdSend.starts("/freeze") || cmdSend.starts("/unfreeze") || cmdSend.starts("/gag") || cmdSend.starts("/ungag"))
      {
        for(
    temp.pl allplayers){
          if(
    tokens == temp.pl.substring(0,tokens.length())|| tokens == temp.pl.nick.substring(0,tokens.length()))
          {
            if (
    temp.pl.level!=NULL)
            {
              
    this.fnd=temp.pl;
              
    temp.foundplayer.add(temp.pl);
            }
          }
        } 
    However, it is not really the most practical approach. Although I do not believe there is a command that can find player accounts by nickname, there does exist a command called findplayer2(acc OR community name) -- it is equivalent to 'findPlayerByCommunityName(str)'. If this would be used on servers with a huge population, like the iServers, this would eat up an unnecessary amount of CPU for something so simple. To have the (almost) the same functionality, I would replace the blocked code with:
    PHP Code:
    if (!(cmdSend in {"/freeze""/warp""etc"})) return;
    temp.pl findPlayer2(tokens);
    if (
    temp.pl == null) {
      
    player.chat "Player Offline!";
      return;
    }
    //command handling here (could still be better optimized from the way you have it) 
    To suit this change, you can simplify your triggers under function onPlayerChats() [You also repeat a lot of the same code here]:
    PHP Code:
    //#CLIENTSIDE
    function onPlayerChats() { 
    temp.tokens player.chat.tokenize(" "); // A space is essentially acting as a delimiter, creating tokens in an array.
    temp.cmdSend tokens[0]; // First token, in index 0 of the array tokens, is going to be your command. (i.e.   /freeze Kenny 10 ==>  tokens[0] = /freeze, tokens[1] = Kenny, tokens[2] = 10)
    if (temp.tokens.size() > 2) {
      for (
    temp.1temp.< (temp.tokens.size() - 1); temp.++) { // Subtract off tokens[0]
        
    temp.parameters.add(tokens[i]); // Add the rest of the tokens into a new array (if any), to be later sorted serverside as needed
      
    }
    } else if (
    temp.tokens.size() > 1) {
      
    temp.parameters tokens[1];
    } else {
      
    player.chat "Not enough parameters!";
      return;
    }
    //CHECK IF CMDSEND IS VALID, MATCH TO AN ARRAY? if (cmdsend in ARRAYNAMEOFCMDS), etc

    // If you only plan on having ONE parameter pass all the data, as you plan on sorting it on serverside, I would then just group the tokens, and use one trigger for everything:
    triggerServer("weapon"this.nametemp.cmdSendtemp.parameters);

    // If command doesn't require sending serverside, add an exception and handle below. 
    EDIT: Sorry for not commenting about your code & functionality, and essentially just criticizing off the bat, but it's a good start .
    To be honest, I didn't thoroughly look through it, but there are definitely places you can slim down some. Like in each command serverside, you have setting a players chat.
    Well, instead, you can wait until the end:
    In the command, just set "temp.plyr_cht = "blah"; Then, before the function ends, send: player.chat = temp.plyr_chat;

  3. #3
    Soldier
    Join Date
    Jun 2013
    Location
    France
    Posts
    55
    Hi Dan,
    I totally agree with your critics, I had just forgot this important "in" which is really helpful to check in arrays
    You are also right about my gagging commands, it's better to make a check before sending it to server.
    Thanks for it, I will take it in care in future.

    PS: Here is my new code for -Staff/StaffCmd
    PHP Code:
    // Scripted by Joe (Les Frenchies)
    function onActionServerSide(cmdSendtokens)
    {
      if(
    cmdSend in {"/summon""/warp""/freeze""/unfreeze""/gag""/ungag"})
      {
        for(
    temp.pl allplayers){
          if(
    tokens == temp.pl.substring(0,tokens.length())|| tokens == temp.pl.nick.substring(0,tokens.length()))
          {
            if (
    temp.pl.level!=NULL)
            {
              
    this.fnd=temp.pl;
              
    temp.foundplayer.add(temp.pl);
            }
          }
        }
        if (
    temp.foundplayer.size()==1){
          if (
    cmdSend.starts("/summon")){
            
    this.fnd.setlevel2(player.level,player.x,player.y);
            
    this.fnd.unfreezeplayer();
            
    updateboard(0,0,64,64);
            
    this.fnd.chat="Summoned!";
          }
          if (
    cmdSend.starts("/warp")){
            
    setlevel2(this.fnd.level,this.fnd.x,this.fnd.y);
            
    player.chat="Warped!";
          }
          if (
    cmdSend.starts("/freeze")){
            
    this.fnd.setlevel2(player.level,player.x,player.y);
            
    this.fnd.freezeplayer2();
            
    updateboard(0,0,64,64);
            
    this.fnd.chat="I'm Frozen!";
          }
          if (
    cmdSend.starts("/unfreeze")){
            
    this.fnd.setlevel2(player.level,player.x,player.y);
            
    this.fnd.unfreezeplayer();
            
    updateboard(0,0,64,64);
            
    this.fnd.chat="I'm unfrozen!";
          }
          if (
    cmdSend.starts("/gag")){
            if(
    this.fnd.clientr.player_gagged != null){
            
    player.chat="This player already gagged!";
            return;
            }
            
    this.fnd.chat "*Gagged*";
            
    this.fnd.clientr.player_gagged=timevar2+(params[2]*60);
            
    this.fnd.addweapon("Public/Graal1612898/PlayersCmd");
          }
          if (
    cmdSend.starts("/ungag")){
            if(
    this.fnd.clientr.player_gagged == null){
              
    player.chat="This player isn't gagged!";
              return;
            }
            
    player.chat "Done";
            
    this.fnd.chat "*Ungagged by *" player.nick;
            
    this.fnd.clientr.player_gagged=0;
            
    this.fnd.addweapon("Public/Graal1612898/PlayersCmd");
          }
        }
        else if(
    temp.playerfound.size==0){
          
    player.chat="No Players 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!");
        }
      }
      if(
    cmdSend.starts("setap"))
      {
        
    player.ap tokens[1];
      }
      if (
    params[0] == "/tag")
      {
        if(
    isStaffGuild(params[1]))
        {
          if(
    params[1] == player.clientr.staffGuild)
          {
            
    player.guild params[1];
          }
          else
          {
            
    player.chat "You aren't allowed to set that tag!";
          }
        }
        else
        {
          
    player.guild params[1];
        }
      }
    }

    function 
    isStaffGuild(Plguild)
    {
      
    temp.guildstaff serveroptions.staffguilds.tokenize(",");
      
    temp.guildstaff temp.guildstaff.upper();
      
    temp.Plguild Plguild.upper();

      if(
    temp.Plguild in temp.guildstaff){
        if(
    temp.Plguild != "Admin")
        {
          return 
    true;
        }
      }
    }

    //#CLIENTSIDE
    function onCreated(){
      
    this.commands = { "/warp","/summon","/freeze""/unfreeze""/gag""/ungag""setap""/tag" };
    }
    function 
    onPlayerChats(){
      
    temp.tokens player.chat.tokenize(" ");
      
    temp.cmdSend tokens[0];
      
      if(
    cmdSend in this.commands)
      {
        if(
    temp.tokens.size() > 2)
        {
          for(
    temp.1temp.< (temp.tokens.size() - 1); temp.i++){
            
    temps.parameters.add(tokens[i]);
          }
        }
        else if(
    temp.tokens.size() > 1){
          
    temp.parameters tokens[1];
        }
        else{
          
    player.chat "Not enough parameters!";
          return;
        }
        
    triggerServer("weapon"this.nametemp.cmdSendtemp.parameters); 
      }
      


      if (
    player.chat.starts("/ani")) {
         
    tokens player.chat.tokenize();
         
    setani(tokens[1],tokens[2]);
      }
      if(
    player.chat == "/reconnect") {
        
    ServerWarp(ServerName);
      }
      if (
    player.chat.starts("sethat")) {
        
    player.attr[1] = player.chat.substring(7);
      }
    }
    function 
    onKeyPressed(code,key)
    {
      if(
    key == "c" || key == "C"){
        
    player.chat player.level SPC "," SPC player.x SPC player.y;
      }

    Last edited by Joe; 07-02-2015 at 11:55 AM.

  4. #4
    Street Boss Mr LebJoe S's Avatar
    Join Date
    Aug 2014
    Location
    liechtestein
    Posts
    781
    ... Nice work Joe! ...
    ineffable.

  5. #5
    Soldier
    Join Date
    Jun 2013
    Location
    France
    Posts
    55
    Thanks Mr. LebJoe S.
    If you need any help in your server, I would enjoy to help you.

  6. #6
    Big Cheese Captain
    Join Date
    Jun 2013
    Posts
    1,029
    One thing that isn't needed is this:
    PHP Code:
    if(key == "a" || key == "A") { 
    You don't need that extra or statement.

    Another thing you should get into is having a switch and case as such for organization (instead of having if(temp.cmd == "") {

    PHP Code:
    //Example Code
    function onActionServerSide(temp.cmd,acc) {
      switch(
    temp.cmd) {
      case
    "gag":
        
    //do stuff
        
    break;

      case
    "ungag":
        
    //do stuff
        
    break;
      }
    }
    //#CLIENTSIDE
    function onPlayerChats() {
      
    temp.tokens player.chat.tokenize();
      if (
    temp.tokens[0] == "/gag") {
        
    triggerserver("gui",this.name,"gag",temp.tokens[1]);
      }
      if (
    temp.tokens[0] == "/ungag") {
        
    triggerserver("gui",this.name,"ungag",temp.tokens[1]);
      }

    But overall, very good job
    Last edited by iMask; 07-05-2015 at 04:49 PM.
    iEra Developer / SFX Admin

    Need help? Contact me:
    Email: [email protected]

  7. #7
    Soldier
    Join Date
    Jun 2013
    Location
    France
    Posts
    55
    Hi iMask,
    About the key part, I think I'm right because I tried it a while ago and it wasn't working if the key was "A" but maybe they updated gs2 (I'll check later to be sure).

    Second way, the switch would be stupid because a part of the code is the same for a part of the script (where I find players) and then others doesnt need that part, it would make a longer script which isn't really great.
    Or I should do it in another way (not like yours because it would be much longer, because there is others commands.
    But if you wanna do it like that, you should do:

    PHP Code:
    // Scripted by Joe (Les Frenchies) 
    function onActionServerSide(cmdSendtokens

      if(
    cmdSend in {"/summon""/warp""/freeze""/unfreeze""/gag""/ungag"}) 
      { 
        for(
    temp.pl allplayers){ 
          if(
    tokens == temp.pl.substring(0,tokens.length())|| tokens == temp.pl.nick.substring(0,tokens.length())) 
          { 
            if (
    temp.pl.level!=NULL
            { 
              
    this.fnd=temp.pl
              
    temp.foundplayer.add(temp.pl); 
            } 
          } 
        } 
        if (
    temp.foundplayer.size()==1){ 
          
    //iMask, I would put here the switch
          
    switch(cmdSend){
            case 
    "/summon":
              
    this.fnd.setlevel2(player.level,player.x,player.y); 
              
    this.fnd.unfreezeplayer(); 
              
    updateboard(0,0,64,64); 
              
    this.fnd.chat="Summoned!"
            break;

            case 
    "/warp":
              
    setlevel2(this.fnd.level,this.fnd.x,this.fnd.y); 
              
    player.chat="Warped!";
            break;

            case 
    "/freeze":
              
    this.fnd.setlevel2(player.level,player.x,player.y); 
              
    this.fnd.freezeplayer2(); 
              
    updateboard(0,0,64,64); 
              
    this.fnd.chat="I'm Frozen!"
            break;
            
            case 
    "/unfreeze":
              
    this.fnd.setlevel2(player.level,player.x,player.y); 
              
    this.fnd.unfreezeplayer(); 
              
    updateboard(0,0,64,64); 
              
    this.fnd.chat="I'm unfrozen!"
            break;

            case 
    "/gag":
              if(
    this.fnd.clientr.player_gagged != null){ 
                
    player.chat="This player already gagged!"
                return; 
              } 
              
    this.fnd.chat "*Gagged*"
              
    this.fnd.clientr.player_gagged=timevar2+(params[2]*60); 
              
    this.fnd.addweapon("Public/Graal1612898/PlayersCmd"); 
            break;
            
            case 
    "/ungag":
              if(
    this.fnd.clientr.player_gagged == null){ 
                
    player.chat="This player isn't gagged!"
                return; 
              } 
              
    player.chat "Done"
              
    this.fnd.chat "*Ungagged by *" player.nick
              
    this.fnd.clientr.player_gagged=0
              
    this.fnd.addweapon("Public/Graal1612898/PlayersCmd"); 
            break;
          }
        } 
        else if(
    temp.playerfound.size==0){ 
          
    player.chat="No Players 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!"); 
        } 
      } 
      if(
    cmdSend == "setap"
      { 
        
    player.ap tokens[1]; 
      } 
      if (
    cmdSend == "/tag"
      { 
        if(
    isStaffGuild(tokens[1])) 
        { 
          if(
    tokens[1] == player.clientr.staffGuild
          { 
            
    player.guild tokens[1]; 
          } 
          else 
          { 
            
    player.chat "You aren't allowed to set that tag!"
          } 
        } 
        else 
        { 
          
    player.guild tokens[1]; 
        } 
      } 


    function 
    isStaffGuild(Plguild

      
    temp.guildstaff serveroptions.staffguilds.tokenize(","); 
      
    temp.guildstaff temp.guildstaff.upper(); 
      
    temp.Plguild Plguild.upper(); 

      if(
    temp.Plguild in temp.guildstaff){ 
        if(
    temp.Plguild != "Admin"
        { 
          return 
    true
        } 
      } 


    //#CLIENTSIDE 
    function onCreated(){ 
      
    this.commands = { "/warp","/summon","/freeze""/unfreeze""/gag""/ungag""setap""/tag" }; 

    function 
    onPlayerChats(){ 
      
    temp.tokens player.chat.tokenize(" "); 
      
    temp.cmdSend tokens[0]; 
       
      if(
    cmdSend in this.commands
      { 
        if(
    temp.tokens.size() > 2
        { 
          for(
    temp.1temp.< (temp.tokens.size() - 1); temp.i++){ 
            
    temps.parameters.add(tokens[i]); 
          } 
        } 
        else if(
    temp.tokens.size() > 1){ 
          
    temp.parameters tokens[1]; 
        } 
        else{ 
          
    player.chat "Not enough parameters!"
          return; 
        } 
        
    triggerServer("weapon"this.nametemp.cmdSendtemp.parameters);  
      } 
       


      if (
    player.chat.starts("/ani")) { 
         
    tokens player.chat.tokenize(); 
         
    setani(tokens[1],tokens[2]); 
      } 
      if(
    player.chat == "/reconnect") { 
        
    ServerWarp(ServerName); 
      } 
      if (
    player.chat.starts("sethat")) { 
        
    player.attr[1] = player.chat.substring(7); 
      } 

    function 
    onKeyPressed(code,key

      if(
    key == "c" || key == "C"){ 
        
    player.chat player.level SPC "," SPC player.x SPC player.y
      } 

    Well, thanks for the critics even if I don't totally agree with it. You should look at my other thread which is a script a little bit more complicated than this noob one xD.
    Have a nice day.
    Last edited by Joe; 07-07-2015 at 12:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •