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

Solved Correct format in game countdown

Discussion in 'Development' started by rektpixel, Feb 19, 2018.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    Hello pmmp,
    I'm making a minigame plugin and I have this:
    PHP:
        public function onRun($tick){
            
    $config = new Config($this->plugin->getDataFolder() . "/config.yml"Config::YAML);
            
    $slots = new Config($this->plugin->getDataFolder() . "/slots.yml"Config::YAML);
            
    $arenas $config->get("arenas");
            if(!empty(
    $arenas)){
                foreach(
    $arenas as $arena){
                    
    $time $config->get($arena "PlayTime");
                    
    $timeToStart $config->get($arena "StartTime");
                    
    $levelArena $this->plugin->getServer()->getLevelByName($arena);
                    
    $level $this->plugin->getServer()->getLevelByName($arena);
                    
    $this->levela $levelArena;
                    if(
    $levelArena instanceof Level)
                    {
                        
    $playersArena $levelArena->getPlayers();
                        if(
    count($playersArena)==0)
                        {
                            
    $config->set($arena "PlayTime"780);
                            
    $config->set($arena "StartTime"21);
                        }
                        else
                        {
                            if(
    count($playersArena)>=1)
                            {
                                if(
    $timeToStart>0)
                                {
                                    
    $timeToStart--;
                                    foreach(
    $playersArena as $pl){
                                        
    $levelArena->addSound(new PopSound($pl));
                                        
    $pl->sendPopup(TextFormat::YELLOW "Starting in " TextFormat::AQUA $timeToStart "");
                                        if(
    $timeToStart === 5){
                                            
    $pl->addTitle("§c§l5"""0200);
                                            if(
    $timeToStart === 4){
                                                
    $pl->addTitle("§6§l4"""0200);
                                                if(
    $timeToStart === 3){
                                                    
    $pl->addTitle("§6§l3"""0200);
                                                    if(
    $timeToStart === 2){
                                                        
    $pl->addTitle("§e§l2"""0200);
                                                        if(
    $timeToStart === 1){
                                                            
    $pl->addTitle("§a§l"""0200);
                                                            if(
    $timeToStart<=0){
                                                                
    $levelArena->addSound(new GhastShootSound($pl));
                                                                
    $pl->sendMessage("§b§l»§r§e The match has §a§lSTARTED!");
                                                                
    $pl->sendPopup(TextFormat::YELLOW "Good luck!");
                                                                
    $pl->addTitle(""""0300);
                                                                
    $this->refillChests($levelArena);
                                                                
    $config->set($arena "StartTime"$timeToStart);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if(
    $timeToStart === 5){
                                            foreach(
    $playersArena as $pla)
                                            {
                                                if(
    $slots->get("slot1".$arena)==$pla->getName())
                                            {
                                                
    $thespawn $config->get($arena "Spawn1");
                                            }
                                            elseif(
    $slots->get("slot2".$arena)==$pla->getName())
                                            {
                                                
    $thespawn $config->get($arena "Spawn2");
                                            }
                                            
    $spawn = new Position($thespawn[0]+0.5,$thespawn[1],$thespawn[2]+0.5,$levelArena);
                                            
    $pla->teleport($spawn,0,0);
                                            }
                                        }
                                    }
                                }      
                                else
                                {
    So I'm able to join the game and yes $slots is all sorted further up the code when a player joins the match.
    I am trying to send each player to their $slots position when the countdown reaches 5. at the moment it just repeats a popping sound and continuously gives the popup: 'starting in 20' I am fairly sure the code is correct but I think it's in the wrong format/order..
    Could someone help, thanks :)
     
  2. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    use switch() or elseif() for countdown
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Don't use config to store arena data, it's totally useless
     
  4. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Anyway, to fix your problem you must close if() after sending every title or just use switch().
     
  5. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    How do I close an if()
     
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Paste } under
     
  7. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    Your code is very awful. In first place, avoid as many else 's as you can.
     
  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.