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

$particle->setInvisible(); doesnt work.Why please ?

Discussion in 'Facepalm' started by SkySeven, Feb 8, 2017.

  1. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    setInvisible() is doesn't work in my plugin, why ?

    thank you in advance :)
    PHP:
    <?php
    namespace text;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Server;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\level\particle\FloatingTextParticle;
    use 
    pocketmine\level\particle\Particle;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat as TF;

    class 
    Main extends PluginBase implements Listener{
       
        public 
    $Main;
        public 
    $text;
       
        public function 
    onEnable(){
           
            
    $this->saveDefaultConfig();
            
    $this->getResource("config.yml");
            
    $this->getLogger()->info(TF::GREEN."Text loaded by SkySeven!");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->spawnText();
        }
       
        public function 
    onDisable(){
           
        }

        public function 
    onJoin(PlayerJoinEvent $event){
            
    $particle $this->text;
            
    $this->respawnText($particle);
        }
       
        public function 
    onQuit(PlayerQuitEvent $event){
            
    $particle $this->text;
            
    $this->respawnText($particle);
        }
       
        public function 
    spawnText(){
           
            
    $online count(Server::getInstance()->getOnlinePlayers());
            
    $r TF::RESET."\n";
       
            
    $x $this->getConfig()->get("SpawnX");
            
    $y $this->getConfig()->get("SpawnY");
            
    $z $this->getConfig()->get("SpawnZ");
            
    $level $this->getServer()->getLevelByName($this->getConfig()->get("Level"));
           
            
    $line1 $this->getConfig()->get("Line1");
            
    $line2 $this->getConfig()->get("Line2");
            
    $line3 $this->getConfig()->get("Line3");
            
    $line4 $this->getConfig()->get("Line4");
            
    $line5 $this->getConfig()->get("Line5");
            
    $line6 $this->getConfig()->get("Line6");
       
            
    $lines $line1 $r $line2 $r $line3 $r$line4 $r $line5 $r $line6;
            
    $lines str_replace("{ONLINE}"$online$lines);
            
    $this->text = new FloatingTextParticle(new Vector3($x$y$z), $lines);

            
    $level->addParticle($this->text);
        }
        public function 
    respawnText($particle){
            
    $particle->setInvisible(true);
            
    $this->spawnText();
        }
    }
     
    Last edited: Feb 8, 2017
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    there a [php][/php] BTW
    even tho it is not necessary i just wish to point it out

    but i am guessing you need to actually respawn to all to make it invisible and visible
     
  3. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    oh ok sorry :/
    Yes it's that but the floatingtext is only spawn, it does not despawn...
     
  4. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
  5. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    What is this
    PHP:
    $online count(Server::getInstance()->getOnlinePlayers());
    You may use that
    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $online) {}
    And use
    PHP:
    $level->addParticle($this->text$online);
     
  6. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    $online is for count the number of players
    You think that with that my code will work?
     
  7. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    If not thank you for your answer
     
  8. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Your config did not optimize...
     
  9. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    it's true but i think it's not for that reason
     
  10. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Use getNested() good method ... the probleme its
    Is that you disable the particle you put it in '$particle->setInvisible(true);' = your particle its not visible :/
     
  11. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Everytime you make changes to a particle you need to add it again
    so it should be
    PHP:
    public function respawnText($particle){
            
    $particle->setInvisible(true);
            
    $this->getServer()->getLevelByName($this->getConfig()->get("Level"))->addParticle($particle);
        }
    also you should not be creating a new particle everytime, just create it once in onEnable will do
     
  12. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    oh ok !Thank you for your answer !
     
  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.