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 Tools system.

Here is how to use it:
First, you must be in the staff list on the serveroptions.
Secondly, I included an admin ranking system to know which tools you are allowed to have with the client variable: clientr.staffRank.
You can also define your based staff guild with that variable: clientr.staffGuild.
There is also two array:
-temp.arrayStaffTools (toolId, toolName, toolWeapon, toolHint, toolRank) (toolRank is the rank you need to have this tool)
-this.buttonArray (Same array but on clientSide)

Well, here is my script:

PHP Code:
//Scripted by Joe (Les Frenchies)

function isStaff(account) {
  return 
serveroptions.staff.tokenize(",").index(@ account) > (- 1);
}

function 
onActionServerSide(){
  if (
params[0] == "check")
  {
    if(!
isStaff(player.account))
    {
      
findplayer(player.account).removeweapon(this.name);
      echo(
"StaffTools:" player.nick "(" player.communityname "(" player.account ")) tried to use Staff Tools,but his not staff.");
    }
    else{

      
//Create Tools Array
      //(toolId, toolName, toolWeapon, toolHint, toolRank) -> You can add your own staff tools by creating the rights weapons
      
temp.arrayStaffTools = {
        {
0,"default","Staff/Tools","Open/Close Staff Tools",1},
        {
1,"boots","Staff/StaffBoots","Boots",1},
        {
2,"typewriter","Staff/StaffTypeWritter","TypeWriter",1},
        {
3,"stealth","Staff/StaffStealth","Stealth",1},
        {
4,"drag","Staff/StaffDrag","Drag",1},
        {
5,"staffstick","Staff/StaffStick","Staff Stick",1},
        {
6,"punish","Staff/StaffPunish","Punish",1},
        {
7,"leveleditor","Staff/StaffTileEditor","Tile Editor",6},
        {
8,"staffcmd","Staff/StaffCmd","Staff Commands",1},
        {
9,"staffnpceditor","Staff/StaffNPCEditor","Staff Npc Editor",8}
      };

      
temp.getWeaponsGave = {};

      for (
temp.0temp.arrayStaffTools.size(); i++)
      {
        if(
arrayStaffTools[i][4] =< player.clientr.staffRank){
          
player.addweapon(arrayStaffTools[i][2]);
          
temp.getWeaponsGave.add(arrayStaffTools[i][2]);
        }else{
          
player.removeweapon(arrayStaffTools[i][2]);
        }
      }

       echo(
"StaffTools:" player.account " get: " temp.getWeaponsGave);

    }
  }
  if(
params[0] == "setStaffParams"){
    if(
isStaff(player.account))
    {
      if(
player.guild == "Events Team"){
        
player.ap 100;
      }
      else{
        if(
player.clientr.staffGuild == 0){
          
clientr.staffGuild "Staff";
        }
        
player.guild clientr.staffGuild;
        
player.ap 100;
      }
    }
  }
  if(
params[0] == "unsetStaffParams"){
    if(
player.guild == "Events Team"){
        
player.ap random(1,99);
      }
      else{
        
player.guild "";
        
player.ap random(1,99);
      }
  }
}

//#CLIENTSIDE
function onCreated()
{
  
//Checking if player is Staff
  
triggerserver("weapon"this.name,"check");

  
//Basics Variables
  
this.equipweapon false;

  
//Create Tools Array
  //(toolId, toolName, toolWeapon, toolHint, toolRank)
  
this.buttonArray = {
    {
0,"default","Staff/Tools","Open/Close Staff Tools",1},
    {
1,"boots","Staff/StaffBoots","Boots",1},
    {
2,"typewriter","Staff/StaffTypeWritter","TypeWriter",1},
    {
3,"stealth","Staff/StaffStealth","Stealth",1},
    {
4,"drag","Staff/StaffDrag","Drag",1},
    {
5,"staffstick","Staff/Stick","Staff Stick",1},
    {
6,"punish","Staff/StaffPunish","Punish",1},
    {
7,"leveleditor","Staff/StaffTileEditor","Tile Editor",6}
  };

  
//Create GUI
  
createStaffToolsWindow(this.buttonArray);
}

function 
createStaffToolsWindow(buttonArrayTabs){

    
//Basics Variables
    
temp.staffToolX screenwidth 60;
    
temp.staffToolY 20;

    for (
temp.0buttonArrayTabs.size(); i++)
    {
      if(
buttonArrayTabs[i][4] =< player.clientr.staffRank)
      {
        new 
GuiBitmapButtonCtrl("StaffToolsW_Button_" temp.i) {
          
temp.staffToolX;
          
temp.staffToolY;
          
width height 44;
          
normalbitmap "stafftools-button-" buttonArrayTabs[i][1] @ "-off.png";
          
mouseoverbitmap "stafftools-button-" buttonArrayTabs[i][1] @ "-hover.png";
          
pressedbitmap "stafftools-button-" buttonArrayTabs[i][1] @ "-on.png";
          
hint buttonArrayTabs[i][3];
          
alpha .85;
          
this.getId buttonArrayTabs[i][0];
          
this.getName buttonArrayTabs[i][1];
          
this.getWeapon buttonArrayTabs[i][2];
          
this.toolOpen false;

          
thiso.catchevent(this"onAction""onStaffToolsButtonAction");

          if(
buttonArrayTabs[i][1] == "boots"){
            new 
GuiMLTextCtrl("StaffTools_Button_Boots_Text") {
              
useownprofile true;
              
profile.fontColor "255 255 255";
              
profile.fontSize 14;
              
28;
              
3;
              
text "";
              
this.show();
            }
          }
        
//Hide all Button, not the first

        
if(temp.0){
          
this.hide();
        }
        else{
          
this.show();
        }
      }

      
//Increment y
      
temp.staffToolY += 50;
    }
  }
}

function 
onKeyPressed(code,key) {
  if (
key == "t")
  {
    
temp.ButtonDefault = new GuiBitmapButtonCtrl("StaffToolsW_Button_" this.buttonArray[0][0]);
    
onStaffToolsButtonAction(temp.ButtonDefault);
  }
}

public function 
onStaffToolsButtonAction(obj)
{
  for (
temp.0this.buttonArray.size(); i++)
  {
    if(
this.buttonArray[i][0] == obj.getID)
    {
      if((@ 
obj.getWeapon).isOpenTool()){

        
obj.normalbitmap "stafftools-button-" obj.getName "-off.png";
        
obj.mouseoverbitmap "stafftools-button-" obj.getName "-hover.png";
        
obj.pressedbitmap "stafftools-button-" obj.getName "-on.png";

        
player.chat obj.getName SPC ": Off";

        if((@ 
obj.getWeapon) == this.name)
        {
          for (
temp.1this.buttonArray.size(); e++){
            
temp.Window = new GuiBitmapButtonCtrl("StaffToolsW_Button_" temp.e);
            
temp.Window.hide();
          }
        }

        (@ 
obj.getWeapon).closeTool();

      }
      else{

        if(
obj.getName != "punish")
        {
          
obj.normalbitmap "stafftools-button-" obj.getName "-on.png";
          
obj.mouseoverbitmap "stafftools-button-" obj.getName "-on.png";
          
obj.pressedbitmap "stafftools-button-" obj.getName "-off.png";
        }
        
player.chat obj.getName SPC ": On";

        if((@ 
obj.getWeapon) == this.name)
        {
          for (
temp.1this.buttonArray.size(); e++){
            
temp.Window = new GuiBitmapButtonCtrl("StaffToolsW_Button_" temp.e);
            
temp.Window.show();
          }
        }

        (@ 
obj.getWeapon).openTool();
      }
    }
  }
}

public function 
closeTool() {
  
this.equipweapon false;
  
triggerserver("weapon"this.name,"unsetStaffParams");
  
//this.onCreated();
}
public function 
openTool() {
  
this.equipweapon true;
  
triggerserver("weapon"this.name,"setStaffParams");
}
public function 
isOpenTool() {
  if(
this.equipweapon == true){
    return 
true;
  }
  else{
    return 
false;
  }

Well, now to add your tools you need to create the weapons with the right toolName. For example, if I create the weapon: Staff/StaffBoots, I will also need to add few functions to make it working fine. I will have to add 3 functions on each staff tools weapon I create:
PHP Code:
public function closeTool() {
  
this.equipweapon false;
  
this.onCreated();
}
public function 
openTool() {
  
this.equipweapon true;
  
StaffTools_Button_Boots_Text.text this.speed;
}
public function 
isOpenTool() {
  if(
this.equipweapon == true){
    return 
true;
  }
  else{
    return 
false;
  }

So for our example, the Staff/Tools weapon would be:

PHP Code:
// Scripted by Joe

//#CLIENTSIDE
function onCreated(){
  
this.equipweapon false;
  
this.speed 1;
  
StaffTools_Button_Boots_Text.text "";
  
setTimer(0.05);
}

function 
onKeyPressed(code,key)
{
 if (
this.isOpenTool() && ("Staff/Tools").isOpenTool())
  {
    
this.openTool();
    
setTimer(0.05);

    if (
code == 187)
    {
      if (
this.speed+<= 20)
      {
        
this.speed+=1;
        
player.chat "Speed: " this.speed;
        
StaffTools_Button_Boots_Text.text this.speed;
      }
    }
    else if (
code == 109)
    {
      if (
this.speed->= -10)
      {
        
this.speed-=1;
        
player.chat "Speed: " this.speed;
        
StaffTools_Button_Boots_Text.text this.speed;
      }
    }
  }
}

function 
onTimeOut()
{
 if (
this.isOpenTool() && ("Staff/Tools").isOpenTool())
  {
   for (
a=0a<4a++)
    {
     if (
keydown(a))
      {
       switch(
a)
        {
          case 
"0":
           
player.y-=this.speed;
           break;
          case 
"1":
           
player.x-=this.speed;
           break;
          case 
"2":
           
player.y+=this.speed;
           break;
          case 
"3":
           
player.x+=this.speed;
           break;
        }
      }
    }
  }
 
setTimer(0.05);
}

public function 
closeTool() {
  
this.equipweapon false;
  
this.onCreated();
}
public function 
openTool() {
  
this.equipweapon true;
  
StaffTools_Button_Boots_Text.text this.speed;
}
public function 
isOpenTool() {
  if(
this.equipweapon == true){
    return 
true;
  }
  else{
    return 
false;
  }

Well, and you do that for each staff tools weapon you create (Don't forget to modify the both array we made).
Also, still about the main weapon Staff/Tools, don't forget about the button to make them on a square shape and don't forget to name them like that:
- stafftools-button-" @ toolName(from the array) @ "-off.png -> Uncliked graphic
- stafftools-button-" @ toolName(from the array) @ "-hover.png -> Hovered graphic
- stafftools-button-" @ toolName(from the array) @ "-on.png -> Clicked graphic

I think I told you everything about my Staff/Tools weapon.
Also if I made it using much weapons, it's too make your scripts easier to read, faster and also you can easily add new staff tools without being confused with all the main script.

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!