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

Pocketmine Timer Code

Comments in 'Plugin Development' started by SM11, Jul 28, 2015.

  1. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Hello, I could use some help figuring out how a timer would work for pocketmine, I know of time commander but that expands what I want to do, Could anyone supply me with a few lines of code,
  2. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    Add this to your main:
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new TaskName($this$player), 20);
    This will create a task that will run every second.
    Then create a new file and call it TaskName
    And add this to the the file:
    PHP:
    <?php
    namespace yournamespace;
    use 
    pocketmine\scheduler\PluginTask;
    class 
    TaskName extends PluginTask {
      public function 
    __construct($plugin,  $player) {
        
    parent::__construct($plugin) ;
      }
      public function 
    onRun($tick) {
        
    //Code here
    }
    Hope it helps :)
    Don't screw up the namespaces!
    SM11 and iiDeathStrokeii like this.
  3. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Thanks
  4. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    Is it possible to freeze player movement for a certain time limit,if so could anyone please help me with this
    Last edited: Jul 29, 2015
  5. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    In your main declare two public variables:
    PHP:
    public $time 0;

    public 
    $canmove true;
    Now add this code in the player move event:
    PHP:
    public function onMove(PlayerMoveEvent$event){
      if(
    $this->canmove === false){
        
    $event->setCancelled();
      }
    }
    Now in your task in the //Code here section, add this:
    PHP:
    $this->plugin $this->getOwner();

    if(
    $this->plugin->time 59){
      
    $this->plugin->canmove true;
    }else{
      
    $this->plugin->canmove false;
      
    $this->plugin->time++;
    }
    This will disable the players movement until a minute is up. This gives you an idea of turning things off and on using Booleans (true and false). Hope this helps!
  6. SM11
    Offline

    SM11 Active Member

    Joined:
    Jun 21, 2015
    Posts:
    117
    Minecraft User:
    SM11
    One question just one question, What do you mean by Main?
  7. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    How do u cancel the time ? https://forums.pocketmine.net/threa...er-function-cancel-on-null.10090/#post-103509
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why count it yourself? Just save the start freeze time with time(), and if time() - $savedStartTime < $timeout, cancel event.

Share This Page

Advertisement