Results 1 to 6 of 6

Thread: Public Functions Problem

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

    Public Functions Problem

    Hello Graalians,

    I'm doing a staff tools system but the public functions I use do not work (and they are both in Clientside). It say in F2 that the function aren't found.

    Here is my code of -Staff/Tools:
    PHP Code:
    // Scripted by Joe (Developer)
    this.join("function_staff");

    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.");
        }
      }
    }

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

      
    //Basics Variables
      
    this.equipweapon false;

      
    //Create Tools Array
      
    this.buttonArray = {
        {
    0,"default","-Staff/Tools","Open/Close Staff Tools"},
        {
    1,"boots","-Staff/Boots","Boots"},
        {
    2,"stealth","-Staff/Stealth","Stealth"},
        {
    3,"drag","-Staff/Drag","Drag"},
        {
    4,"staffstick","-Staff/Stick","Staff Stick"},
        {
    5,"punish","-Staff/Punish","Punish"}
      };

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

    function 
    createStaffToolsWindow(buttonArrayTabs){

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

        for (
    temp.0buttonArrayTabs.size(); i++)
        {
          new 
    GuiBitmapButtonCtrl("StaffToolsW_Button_" temp.i) {
            
    temp.staffToolX;
            
    temp.staffToolY;
            
    width height 44;
            
    normalbitmap "peria_stafftools-button-" buttonArrayTabs[i][1] @ "-off.png";
            
    mouseoverbitmap "peria_stafftools-button-" buttonArrayTabs[i][1] @ "-hover.png";
            
    pressedbitmap "peria_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(
    buttonArray[i][1] == "boots"){
              new 
    GuiMLTextCtrl("StaffTools_Button_Boots_Text") {
                
    profile GuiBlueMLTextProfile;
                
    28;
                
    3;
                
    text "";
              }
            }

            
    //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);
      }  
    }

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

            
    obj.normalbitmap "peria_stafftools-button-" obj.getName "-off.png";
            
    obj.mouseoverbitmap "peria_stafftools-button-" obj.getName "-hover.png";
            
    obj.pressedbitmap "peria_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{

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

            
    player.chat obj.getWeapon 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();
          }
        }
      }
    }

    function 
    closeTool() {
      
    this.equipweapon false;
      
    //this.onCreated();
    }
    function 
    openTool() {
      
    this.equipweapon true;
    }
    function 
    isOpenTool() {
      if(
    this.equipweapon true){
        return 
    true;
      }
      else{
        return 
    false;
      }

    and here the -Staff/Boots (which contains public function used in -Staff/Tools):
    PHP Code:
    // Scripted by Joe

    //#CLIENTSIDE
    function onCreated(){
      
    this.equipweapon false;
      
    this.speed 1;
      
    setTimer(0);
    }
    function 
    onKeyPressed(code,key)
    {
     if (
    this.isOpenTool())
      {
        
    this.openTool();
        
    setTimer(0.05);

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

    function 
    onTimeOut()
    {
     if (
    this.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;
    }
    public function 
    isOpenTool() {
      if(
    this.equipweapon true){
        return 
    true;
      }
      else{
        return 
    false;
      }

    Thanks for your help,
    Joe.

  2. #2
    Street Boss John's Avatar
    Join Date
    Jun 2013
    Location
    Lebanon
    Posts
    825
    which?
    -Johnaudi

  3. #3
    Soldier
    Join Date
    Jun 2013
    Location
    France
    Posts
    55
    This one to open -Staff/Boots :
    PHP Code:
    //Create Tools Array: to get all weapons
      
    this.buttonArray = { 
        {
    0,"default","-Staff/Tools","Open/Close Staff Tools"}, 
        {
    1,"boots","-Staff/Boots","Boots"}, 
        {
    2,"stealth","-Staff/Stealth","Stealth"}, 
        {
    3,"drag","-Staff/Drag","Drag"}, 
        {
    4,"staffstick","-Staff/Stick","Staff Stick"}, 
        {
    5,"punish","-Staff/Punish","Punish"
      };

    //Then at bottom of code there is the script on staff tools button pressed
    function onStaffToolsButtonAction(obj

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

            
    obj.normalbitmap "peria_stafftools-button-" obj.getName "-off.png"
            
    obj.mouseoverbitmap "peria_stafftools-button-" obj.getName "-hover.png"
            
    obj.pressedbitmap "peria_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{ 

            
    obj.normalbitmap "peria_stafftools-button-" obj.getName "-on.png"
            
    obj.mouseoverbitmap "peria_stafftools-button-" obj.getName "-on.png"
            
    obj.pressedbitmap "peria_stafftools-button-" obj.getName "-off.png"

            
    player.chat obj.getWeapon 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(); 
          } 
        } 
      } 

    and at top you saw the public function of -Staff/Boots but idk why they aren't linked. Also on others scripts, I can't join classes to weapon :O Idk why but I think its probably a prob in the server.

  4. #4
    In a couple of places in '-Staff/Tools' I see:
    (@ obj.getWeapon)
    It looks like a custom function, possibly from the joined class at the top (function_staff). If that is the case, for it to correctly call the function, it requires the syntax: obj.getWeapon() - adding the parenthesis.
    Also, in both of the listed weapons are 'isOpenTool()' functions, in which the first line is:
    if(this.equipweapon = true){
    It should have two equal signs, since one is an assignment operator while two equal signs are conditional. So basically, it is always true at this point.
    I'm not really sure if I have answered your question, so try to be more specific when asking for help!

  5. #5
    Soldier
    Join Date
    Jun 2013
    Location
    France
    Posts
    55
    so first (@ obj.getWeapon) is assigned to getWeapon in the object called onAction, and it reffers to the array which reffers to the weapons name so it's nothing about that.

    and the class function_staff is only used to check if the players is staff.

    Then ty for the equal things, I hadn't see it

    But it don't make any change, the function are still not called

    - - - Updated - - -

    Sorry, I feel so bad when I discover that I had forget to add to my own the -Staff/Boots weapons. Sorry about everything thats a newb error.

    Thanks for your help

  6. #6
    When you use (@ obj.getWeapon), it is trying to read a variable called 'getWeapon', instead of calling the function getWeapon(). You need to include parenthesis for the weapon to differentiate the two. Once you do that, I think the rest should work.

Posting Permissions

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