Timer code doesnt work

Discussion in 'Facepalm' started by kaliiks, Dec 29, 2016.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    <?php

    namespace GetDown;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\TextFormat as C;
    use 
    GetDown\Main;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\plugin\Plugin;

    class 
    Timer extends PluginTask
    {
        private 
    $plugin;
        public 
    $tts;

        public function 
    __construct(Main $plugin)
        {
            
    $this->plugin $plugin;
            
    $this->tts 30;
            
    parent::__construct($plugin);
        }

        
    /**
         * @param $currentTick
         */
        
    public function onRun($currentTick)
        {
            foreach (
    $this->plugin->getServer()->getLevelByName("GDHub")->getPlayers() as $pl) {
                if (
    count($pl) >= 1) {
                    
    $this->tts--;
                    
    $pl->setExpLevel($pl->getExpLevel() - 1);
                    
    $pl->sendPopup("");
                    
    //$this->plugin->getServer()->shutdown();
                    /*if ($this->tts == 30) {
                        $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game start in " . $this->tts);
                        if ($this->tts == 15) {
                            $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game start in " . $this->tts);
                            if ($this->tts == 10) {
                                $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game start in " . $this->tts);
                                if ($this->tts == 5) {
                                    $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game start in " . $this->tts);
                                    if ($this->tts == 4) {
                                        $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game start in " . $this->tts);
                                        if ($this->tts == 3) {
                                            $pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game start in " . $this->tts);
                                            if ($this->tts == 2) {*/
                    //$pl->sendMessage($this->plugin->gameprefix . C::GREEN . "Game start in " . $this->tts);
                    
    if ($this->tts == 1) {
                        
    $pl->sendMessage($this->plugin->gameprefix C::GREEN "Game start in " $this->tts);
                        if (
    $this->tts == 0) {
                            
    $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId());
                            
    $pl->sendMessage($this->plugin->gameprefix C::GREEN "Game started!");
                            
    $this->plugin->changePhase(2);
                            
    $pl->teleport(new Vector3(111"GD1"));
                        }
                    }
                }
            }
                                            }

    }
    It work but it use
    PHP:
    if ($this->tts == 1) {
                        
    $pl->sendMessage($this->plugin->gameprefix C::GREEN "Game start in " $this->tts);
    and not use
    PHP:
      if ($this->tts == 0) {
                            
    $pl->sendMessage($this->plugin->gameprefix C::GREEN "Game started!");
                            
    $this->plugin->changePhase(2);
                            
    $pl->teleport(new Vector3(111"GD1"));
    $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId());
    when i use first
    PHP:
     
    if ($this->tts == 1) {
        
    $pl->sendMessage($this->plugin->gameprefix C::GREEN "Game start in " $this->tts);
                         
    it not use
    PHP:
      if ($this->tts == 0) {
                            
    $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId());
                            
    $pl->sendMessage($this->plugin->gameprefix C::GREEN "Game started!");
                            
    $this->plugin->changePhase(2);
                            
    $pl->teleport(new Vector3(111"GD1"));
    :facepalm:
     
    Last edited: Dec 29, 2016

Share This Page

  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.