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

What's the name of the event on the game tick?

Comments in 'Plugin Development' started by Calrizer, Mar 2, 2015.

  1. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Hi again good people of PocketMine,
    I am making a plugin that will need to constantly update data every second, and I need to know the event that allows code to occur every second.

    Any replys much appreciated!

    -Calrizer
  2. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    You need to create a class that extends plugintask:
    In your main class:
    PHP:
    public function onEnable(){
      
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new UpdateData($this), 20); //20 ticks
    }
    Then create in another file the other class:
    PHP:
    <?php
    namespace Yournamespace;

    use 
    pocketmine\scheduler\PluginTask;

    class 
    UpdateData extends PluginTask{

      public function 
    __construct(MainClass $plugin){
        
    parent::__construct($plugin);
      }

      public function 
    onRun($currentTick){
          
    //update your data $this->getOwner() returns your main class
      
    }
    }
    Last edited by a moderator: Mar 3, 2015
  3. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Thanks for replying.
    I'm having trouble with the error: syntax error, unexpected '$plugin'
    Which has something to do with the third line of this section of code.
    PHP:
    public function __construct(EnderWarsCore $plugin){
        
    $this->plugin $plugin;
        
    parent::__construct(EnderWarsCore $plugin);
        }
    Any suggestions??
  4. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    I don't know, maybe try this:
    PHP:
    public function __construct(EnderWarsCore $plugin){
        
    $this->plugin $plugin;
        
    parent::__construct($plugin);
        }
    PEMapModder, iksaku and Calrizer like this.
  5. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Thanks that worked!

    I was wondering if you knew the code to detect all the players in a certain world and send them a message??
  6. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    If you have the level object already:
    PHP:
    $level->getPlayers();
  7. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Then how do I broadcast a message to only the players in that world?
  8. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Lol, just use a callback task to use a function in the same class! (or will that cause lag?)
  9. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Callback functions are not recommended
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That's not relevant at all.
    Foreach the players and sendMessage($msg) for each of them.
  11. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    It was lol
    iJoshuaHD likes this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How can callbacks be related to looping through players and simply sending a message to each of them?
    Why?
  13. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    I think he meant to reply on the first thread not with sendMessage()
    PEMapModder likes this.
  14. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    read... The original question. And cough.. Cough... The post title
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Well... blame people who put different questions into one thread. He should have started another thread.
    iJoshuaHD likes this.
  16. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Yep, that's what you should have done (with the blaming) :p
  17. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    ?
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Me? I don't even have a question, why should I start a new thread?
  19. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Nooo.... Lol read what's in the brackets ._.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I don't get what you mean.
    xFlare likes this.

Share This Page

Advertisement