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

Adding an event after a countdown

Discussion in 'Development' started by XxCodeRedxX, Aug 18, 2017.

  1. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    image.png image.png image.png image.png
    Is there anyway to add an event to where you do /UHC start and countdowns from 3 and then on the 4th tick it breaks all bedrock with a 50 by 50 radius near spawn?

    Here is what the countdown file looks like.
     
    Last edited by a moderator: Aug 18, 2017
  2. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    PHP:
    <?php

    namespace UHCReload;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\math\vector3;
    use 
    UHCReload\Main;
    use 
    pocketmine\Player;
    use 
    pocketmine\level\sound\GhastSound;
    use 
    pocketmine\level\sound\ClickSound;
    use 
    pocketmine\level\sound\AnvilUseSound;
      
    class 
    Countdown extends PluginTask{
      
        public 
    $countdown 0;
      
        public function 
    time($int) {
                    
    $m floor($int 60);
                    
    $s floor($int 60);
                    return ((
    $m 10 "0" "") . $m ":" . ($s 10 "0" "") . $s);
                }
      
        public function 
    __construct(Main $plugin){
            
    parent::__construct($plugin);
            
    $this->plugin $plugin;
            }
          
            public function 
    onRun($task){
                   
    $this->countdown++;
            
    $online count($this->plugin->getServer()->getOnlinePlayers());
                foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $pl){
               
    $x $pl->getFloorX();
               
    $y $pl->getFloorY();
                
    $z $pl->getFloorZ();
    $pl->sendTip("          §8[§9UHCs§8]\n§9X: §3$x §8/ §9Y: §3$y §8/ §9Z: §3$z\n§9Online: §3$pl§8 / §330");
    }
    foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $player){
                    if(
    $this->countdown == 1){
    $player->sendMessage("§8[§9UHC§8] §3Starting in §93");
         
    $click = new ClickSound($player);
             
    $player->getLevel()->addSound($click);
                    }
                      if(
    $this->countdown == 2){
    $player->sendMessage("§8[§9UHC§8] §3Starting in §92");
         
    $click = new ClickSound($player);
             
    $player->getLevel()->addSound($click);
    }
    if(
    $this->countdown == 3){
    $player->sendMessage("§8[§9UHC§8] §3Starting in §91");
         
    $click = new ClickSound($player);
             
    $player->getLevel()->addSound($click);
    }
    if(
    $this->countdown == 4){
                    
    $player->sendMessage("§8[§9UHC§8] §3Event started!");
    $player->getLevel()->addSound(new AnvilUseSound($pl));
    }
    }
    }

    public static function 
    alignStringCenter(string $stringstring $string2) : string {
            
    $length strlen($string);
            
    $half $length 4;
            
    $string $string.PHP_EOL.str_repeat(' '$half).$string2;
            return 
    $string;
    }
    }
     
    Last edited by a moderator: Aug 18, 2017
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Let's assume you meant seconds instead of ticks. You already over complicated things
    PHP:
    <?php

    namespace UHCReload;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\math\vector3;
    use 
    UHCReload\Main;
    use 
    pocketmine\Player;
    use 
    pocketmine\level\sound\GhastSound;
    use 
    pocketmine\level\sound\ClickSound;
    use 
    pocketmine\level\sound\AnvilUseSound;

    class 
    Countdown extends PluginTask {
        private 
    $countdown 0;
        public function 
    __construct(Main $plugin) {
            
    parent::__construct($plugin);
        }
        public function 
    onRun(int $currentTick) {
            if(!isset(
    $this->countdown)) {
                
    $this->countdown $currentTick;
            }
            
    $time $currentTick $this->countdown// in ticks
            
    $online count($this->getOwner()->getServer()->getOnlinePlayers());
            foreach(
    $this->getOwner()->getServer()->getOnlinePlayers() as $pl) {
                
    $x $pl->getFloorX();
                
    $y $pl->getFloorY();
                
    $z $pl->getFloorZ();
                
    $pl->sendTip("          §8[§9UHCs§8]\n§9X: §3$x §8/ §9Y: §3$y §8/ §9Z: §3$z\n§9Online: §3$pl§8 / §330");
            }
            foreach(
    $this->getOwner()->getServer()->getOnlinePlayers() as $player) {
                if(
    $time === 20)  { // every 20 ticks is one second
                    
    $player->sendMessage("§8[§9UHC§8] §3Starting in §93");
                    
    $click = new ClickSound($player);
                    
    $player->getLevel()->addSound($click);
                }
               if(
    $time === 40)  {
                    
    $player->sendMessage("§8[§9UHC§8] §3Starting in §92");
                    
    $click = new ClickSound($player);
                    
    $player->getLevel()->addSound($click);
                }
                if(
    $time === 60) {
                    
    $player->sendMessage("§8[§9UHC§8] §3Starting in §91");
                    
    $click = new ClickSound($player);
                    
    $player->getLevel()->addSound($click);
                }
                if(
    $time === 80) {
                    
    $player->sendMessage("§8[§9UHC§8] §3Event started!");
                    
    $player->getLevel()->addSound(new AnvilUseSound($pl));
                }
            }
            if(
    $time === 80) {
                
    $this->getOwner()->removeBedrock();
                
    $this->getHandler()->remove();
            }
        }
    }
     
    Last edited: Aug 18, 2017
    XCodeMCPE and Muqsit like this.
  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.