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

Solved PluginTask

Comments in 'Plugin Development' started by Kvetinac97, Jul 1, 2015.

  1. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    I want to use timer in my plugin. When I type command, it'll start 30s timer and after 30s "something" will happen. How do this?
  2. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Do you mean a delayed task?
  3. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    I don't know what delayed task is... I want use this in my minigame -> i type command /start and it starts in 30 seconds
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Create a plugin task (extends pocketmine\scheduler\PluginTask and schedule it with ServerScheduler->scheduleDelayedTask for 600 ticks. One tick = 1/20 second.
  5. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    I need some example... so can anybody send here p.e. script: when you type command /msgtime it'll send you message "Message" in 30s after typing it.
  6. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Nobody can help?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    To start the timer:
    PHP:
    $this->getServer()->getScheduler()->scheduleDelayedTask(new SendMessageTask($this$player), 30*20);
    In SendMessageTask.php:
    PHP:
    <?php
    namespace your\name\space;
    use 
    pocketmine\scheduler\PluginTask;
    class 
    SendMessageTask extends PluginTask {
      private 
    $player;
      public function 
    __construct($plugin,  $player) {
        
    parent::__construct($plugin) ;
        
    $this->player $player;
      } 
      public function 
    onRun($t) {
        if(
    $this->player->isOnline())  $this->player->sendMessage("Message") ;
    }
    HotFireyDeath likes this.
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    You could create a repeating task that repeats every second (20 ticks) when you run the command and use if statements or case's to check the time so you can do things like broadcast messages every so many seconds.

Share This Page

Advertisement