1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Help, my task is not working correctly!

Discussion in 'Development' started by Enrico Angelon, Mar 28, 2018.

  1. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    Hello everyine, today i tryed to make tnt tag minigame, i tryed to get inventory itmem with a task but won't work!!!
    Code:
    <?php
    
    namespace Core\Games\TnTTag\Task;
    
    use pocketmine\scheduler\Task;
    use pocketmine\Server;
    
    class TnTTagTnTGrabTask extends Task
    {
    
        public $time = 30;
    
        public function onRun(int $currentTick)
        {
    
            foreach (Server::getInstance()->getLevelByName('TNT-TAG-MAP-1')->getPlayers() as $player)
            {
                if ($player->getInventory()->getItemInHand()->getId() === 46)
                {
                    if($this->time <= 30 && $this->time > 29){
                        $player->sendMessage("3000");
                    }elseif($this->time <= 29 && $this->time > 15){
                        $player->sendMessage("u noooo test ob");
                    }elseif($this->time < 15 && $this->time >= 0){
                        $player->setGamemode(3);
                    }
                }
    
            }
    
            $this->time --;
        }
    }

    and to start task



    Code:
           if ($player->getInventory()->getItemInHand()->getId() === 46)
            {
                Server::getInstance()->getScheduler()->scheduleRepeatingTask(new TnTTagTnTGrabTask(), 20);
            }
    i tryed with switch tooo but nothing!
     
  2. korado531m7

    korado531m7 Slime

    Messages:
    77
    GitHub:
    korado531m7
    Rewrite task to plugintask
     
    OnTheVerge likes this.
  3. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    PluginTask not plugintask -_-
     
    OnTheVerge likes this.
  4. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    use this:
    PHP:
    use pocketmine\scheduler\PluginTask;
     
  5. Khaled

    Khaled Slime

    Messages:
    81
    GitHub:
    xXKHaLeD098Xx
    write PluginTask instead of Task
     
  6. Enrico Angelon

    Enrico Angelon Spider Jockey

    Messages:
    37
    GitHub:
    herryyt
    Now is working thx to all!!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.