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

Update floating text particle by task

Discussion in 'Development' started by kaliiks, Jan 20, 2017.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    <?php

    namespace Core;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\level\particle\FloatingTextParticle;
    use 
    pocketmine\math\Vector3;

    class 
    ParticleTask2 extends PluginTask
    {

        public function 
    __construct(Core $plugin)
        {
            
    $this->plugin $plugin;
            
    parent::__construct($plugin);
        }

        public function 
    onRun($currentTick)
        {
            
    $text = new FloatingTextParticle(new Vector3(1406140), "§eSWAG");
            
    $text->setInvisible(true);
            
    $level $this->plugin->getServer()->getLevelByName("Lobby-1");
            
    $level->addParticle($text);
        }
    }
    Dont work :/
    It remove particle and dont add
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    What are you trying to do? Your code just sets the new particle to be invisible and add it, which despawns it from the player, so the particle is never spawned to the player
     
  3. kaliiks

    kaliiks Zombie

    Messages:
    250
    I want add particle and respawn it to update particle text
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You want to change the text?
     
  5. kaliiks

    kaliiks Zombie

    Messages:
    250
    I add to text how many players is online and by replacing floating text updaten count of online players !
     
  6. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Then you can just do smth like this
    PHP:
    public function __construct(Core $plugin)
        {
            
    $this->plugin $plugin;
            
    parent::__construct($plugin);
    $this->text = new FloatingTextParticle(new Vector3(1406140),"""§eSWAG");
        }

        public function 
    onRun($currentTick)
        {
            
    $this->text->setText("Online: ".count($this->plugin->getServer()->getOnlinePlayers()));
            
    $level $this->plugin->getServer()->getLevelByName("Lobby-1");
            if(
    $level$level->addParticle($this->text);
        }
     
    RyanShaw, Skullex and kaliiks like this.
  7. kaliiks

    kaliiks Zombie

    Messages:
    250
    Thx i used this
    <?php

    namespace Core;
    use pocketmine\math\Vector3;
    use pocketmine\level\particle\FloatingTextParticle;
    use pocketmine\scheduler\PluginTask;

    class ParticleTask extends PluginTask
    {

    public function __construct(Core $plugin)
    {
    $this->plugin = $plugin;
    parent::__construct($plugin);
    $this->text = new FloatingTextParticle(new Vector3(140, 6, 140), "", "§e");
    }

    public function onRun($currentTick)
    {
    $this->text->setText("Online: " . count($this->plugin->getServer()->getOnlinePlayers()));
    $level = $this->plugin->getServer()->getLevelByName("Lobby-1");
    if ($level) $level->addParticle($this->text);
    }
    }
     
  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.