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

Help me please

Discussion in 'Development' started by SergeyIvanov, Jun 27, 2017.

  1. SergeyIvanov

    SergeyIvanov Witch

    Messages:
    59
    GitHub:
    sergeyivanov14
    I have a problem with floatingtext.

    When a player is not in world DuelsMap1 is no should write "No one plays", but somehow the flying text is not present. But when the player comes into the world, flying text is creating and writes that players 1, but when I exit it still says that players 1 although there is no one there. Why?

    My code:
    PHP:
          foreach($this->getServer()->getLevelByName("DuelsMap1")->getPlayers() as $players){
             
    $online count($players);
                if(
    $online == 0){
                  
    $this->particle->setTitle("§cNo one plays");
                  
    $this->particle->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle, [$players]);
                  
    $this->particle1->setTitle("§bDuеls");
                  
    $this->particle1->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle1, [$players]);
                  
    $this->particle2->setTitle("§e§lCLICK TO PLAY");
                  
    $this->particle2->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle2, [$players]);
               }else{
                  
    $this->particle->setTitle("§e{$online} Plаying");
                  
    $this->particle->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle, [$players]);
                  
    $this->particle1->setTitle("§bDuеls");
                  
    $this->particle1->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle1, [$players]);
                  
    $this->particle2->setTitle("§e§lCLICK TO PLAY");
                  
    $this->particle2->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle2, [$players]);
               }
         }
    ;
     
    Last edited: Jun 27, 2017
  2. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Fix your code block.
     
  3. SergeyIvanov

    SergeyIvanov Witch

    Messages:
    59
    GitHub:
    sergeyivanov14
    Fixed
     
  4. Enes5519

    Enes5519 Spider Jockey

    Messages:
    28
    GitHub:
    Enes5519
    PHP:
    foreach($this->getServer()->getLevelByName("DuelsMap1")->getPlayers() as $players){
             
    $online count($this->getServer()->getLevelByName("DuelsMap1")->getPlayers());
                if(
    $online == 0){
                  
    $this->particle->setTitle("§cNo one plays");
                  
    $this->particle->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle, [$players]);
                  
    $this->particle1->setTitle("§bDuеls");
                  
    $this->particle1->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle1, [$players]);
                  
    $this->particle2->setTitle("§e§lCLICK TO PLAY");
                  
    $this->particle2->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle2, [$players]);
               }else{
                  
    $this->particle->setTitle("§e{$online} Plаying");
                  
    $this->particle->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle, [$players]);
                  
    $this->particle1->setTitle("§bDuеls");
                  
    $this->particle1->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle1, [$players]);
                  
    $this->particle2->setTitle("§e§lCLICK TO PLAY");
                  
    $this->particle2->setText("");
                  
    $this->getServer()->getDefaultLevel()->addParticle($this->particle2, [$players]);
               }
         }
    $online fix
     
  5. Keith

    Keith Spider Jockey

    Messages:
    42
    GitHub:
    k3ithos
    Way more efficient code. There is no need to run the count() and adding each particle to all the players in that foreach loop.
    PHP:
    $players $this->getServer()->getLevelByName("DuelsMap1")->getPlayers();
    $online count($players);
    $lobby $this->getServer()->getDefaultLevel();
    if (
    $online == 0) {
        
    $this->particle->setTitle("§cNo one plays");
        
    $this->particle->setText("");
        
    $this->particle1->setTitle("§bDuеls");
        
    $this->particle1->setText("");
        
    $this->particle2->setTitle("§e§lCLICK TO PLAY");
        
    $this->particle2->setText("");
    } else {
        
    $this->particle->setTitle("§e" $online " Plаying");
        
    $this->particle->setText("");
        
    $this->particle1->setTitle("§bDuеls");
        
    $this->particle1->setText("");
        
    $this->particle2->setTitle("§e§lCLICK TO PLAY");
        
    $this->particle2->setText("");
    }
    $lobby->addParticle($this->particle, [$players]);
    $lobby->addParticle($this->particle1, [$players]);
    $lobby->addParticle($this->particle2, [$players]);
     
  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.