Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

TPA plugin dev

Comments in 'Plugin Development' started by Tim // robske Büba, Jan 8, 2016.

  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    First of all CODE:
    screenshot.png
    Ok, I want to make an TPA Plugin.
    And I want to save the ISSUER and the AIM of the /tpa plugin in an array!
    I do understand arrays in C# and C++ and that code would work there.
    But I just don't understand why in every array there is still NULL?
    Is there an better way to do this?
    On /tpa accept i would have to search through the array AIM to search if he is aimed and then search at the Same REQUEST_RQ for his SENDER to teleport!
    But I don't think that will work in php
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
  3. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    When the sender runs /tpa <name> you can add their name to the array like this:
    PHP:
    $this->REQUEST_ISSUER[$sender->getName()] = $sender->getName();
    Tim // robske Büba likes this.
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    But i won't be able to get the "AIM" on /tpa accept then... :(
    I need an index
    PHP:
                            //D O  N O T  L O O K  A T  T H I S (That code is messy)
                            
    global $REQUEST_ISSUER;
                            global 
    $REQUEST_AIM;
                            global 
    $REQUEST_ID;
                            
    var_dump($REQUEST_ISSUER); //DEBUG
                            
    var_dump($REQUEST_AIM); //DEBUG
                            
    var_dump($REQUEST_ID); //DEBUG
                           
                            
    $REQUEST_ISSUER[$REQUEST_ID] = $sender->getName();
                            
    $REQUEST_AIM[$REQUEST_ID] = $args[0];
                            
    $REQUEST_ID++;
                           
                            
    var_dump($REQUEST_ISSUER); //DEBUG
                            
    var_dump($REQUEST_AIM); //DEBUG
                            
    var_dump($REQUEST_ID); //DEBUG
                            //N O W  Y O U  C A N  L O O K  A G A I N
                            
    return true;
    Will try that...
  5. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    When players join you need to add them to an array.
    When someone runs /tpa <playername> you have to set the players name to the object of the requester. Then when the player runs /tpaccept you can simply tp their value in the array to them.

    for example:
    PHP:
    class YourClass {
      public 
    $players= [];

      
    //onJoin
      
    $this->players[$player->getName()] = null;

      
    //onCommand: tpa
      
    $target $sever->getPlayer($args[1]);
      
    $this->players->[$target->getName()] = $sender->getName();

      
    //onCommand: tpaccept
      
    $requester $this->players[$sender->getName()];
      if(
    $requester !== null) {
        
    $requester->teleport($playerPos);
      }
    }
    Tim // robske Büba likes this.
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ok that helps a lot
    But i need some time
    And one question: WHY ARE GLOBALS SAVED WITHIN AN RESTART AND WHERE? My globals where still there after an restart (there was still old data in them)
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Don't use globals in plugins. They keep old data after server restart.
  8. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Where do they save that data?
  9. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    In the main PocketMine process.
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    But on Server RESTART the process is being killed, RAM is freed up... But nevermind tomorrow i will try to finish that array thingy
  11. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Just don't use globals.
    HotFireyDeath likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, they are not saved after server restart (not /reload).
    Just don't use them, ok? Only very few parts of PocketMine uses globals, and it's when using globals is necessary, which you aren't facing this case now.

    I don't know what you are trying to do, but I think you swapped $args[0] and $REQUEST_AIM[...]?

    Also, what is $REQUEST_RQ?
  13. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I don't think he'll listen. He seems like one of those people that don't know when to give up.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It appears that he simply doesn't know how to use them. But anyway, this kind of plugins that use globals needlessly would not get approved in the plugin repo.

    You simply need to delete the global $blah lines, and them change all occurrences of $globalVariable to $this->globalVariable, that works. But to make it more memory efficient, declare the properties by adding a line at the beginning of a class: private $globalVariable.
  15. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Thanks for the explanations :)
    REQUEST_RQ (now it is renamed to REQUEST_ID) is the number of the request.
    I will soon try to use $this->Bla!
    And @Hotshot_9930 I will listen, I am new to php and come from C# where much is different (as example you don't even need to define globals, every variable is ^global^)
    Hotshot_9930 likes this.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP is more like C++ except that it is not typestrict and that all variables are automatically dereferenced when they are used (you can make a variable point to another variable's address, but you don't need to * it)
  17. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    screenshot.png Ok, tried this but it keeps crashing saying: Variable not found! Did I do something wrong?
  18. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Try removing the $ sign for the class variables.
    So it's var_dump($this->REQUEST_ID) instead of var_dump($this->$REQUEST_ID).
  19. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Mind posting the error?
    HotFireyDeath likes this.
  20. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    That did fix it!
    Thanks

Share This Page

Advertisement