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

FloatingTextParticle update

Discussion in 'Development' started by Az928, Apr 19, 2017.

  1. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    Hi, I was wondering how to update a FloatingTextParticle...My code
    PHP:
    public function spawnFloats(Level $levelVector3 $pos, array $texts){
               
    $float implode("\n"$texts);
               
    $float str_replace("{MAX}"$this->getServer()->getMaxPlayers(), $float);
               
    $float str_replace("{ONLINE}"count($this->getServer()->getOnlinePlayers()), $float);
               
    $float str_replace("{TPS}"$this->getServer()->getTicksPerSecond(), $float);
               
    $float str_replace("{MOTD}"$this->getServer()->getMotd(), $float);
              
               
    //$players = $this->getServer()->getOnlinePlayers();
               
    $pp = new FloatingTextParticle($posC::AQUA.$float);
               
    $pp->setText(C::AQUA.$float);
                
    $level->addParticle($pp);
                return 
    true;
            }
    This code works to spawn texts but when updating by using this function it spawns another text instead of editing existing one...Thanks for help

    Problem: I need to update the texts of floating particle
     
    Last edited: Apr 20, 2017
  2. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    you use a task ?
     
  3. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    No event and that's a custom function made by me ...
     
  4. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    PHP:
    public function spawnFloats(Level $levelVector3 $pos, array $texts){
               
    $float implode("\n"$texts);
               
    $float str_replace("{MAX}"$this->getServer()->getMaxPlayers(), $float);
               
    $float str_replace("{ONLINE}"count($this->getServer()->getOnlinePlayers()), $float);
               
    $float str_replace("{TPS}"$this->getServer()->getTicksPerSecond(), $float);
               
    $float str_replace("{MOTD}"$this->getServer()->getMotd(), $float);
              
               
    //$players = $this->getServer()->getOnlinePlayers();
               
    $pp ?? $pp = new FloatingTextParticle($pos"""");
               
    $pp->setText(C::AQUA.$float);
                
    $level->addParticle($pp);
                return 
    true;
            }
     
  5. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    i think it's good
     
  6. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    Lol
    Looks same to me unless add a new $pp variable...
     
  7. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    i have do that and it's work for me
     
  8. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    It will simply add another particle instead of updating it (I think). And android Genisys app doesn't spawn multiple floating particles so if you tested there, it's a bad test
     
  9. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    but it's not work on pocketmine pc :/
     
  10. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    Exactly what I was saying
     
  11. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    By using AddPlayerPacket and spawn him invisible you can do it :)
     
  12. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    Isn't it "AddEntityPacket"? Show some example so I can understand xD
     
  13. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Save the FloatingTextParticle instance, don't create a new one, it will give you one with a new entity id (This is, what you don't want!) and just use $particle->setText() and $particle->setTitle() to edit the text.
     
  14. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    Well my plugin spawn multiple floats at once and I need to update them all at once also
     
  15. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Then save them all. You need them to have the same entity ids when you want to update them. Otherwise you will spawn new entities for the client.
    (Which should be your issue, right? New text spawned inside the already existing text.)
     
  16. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    My question is "HOW" can I save all of them in one variable like array or string or whatever
     
  17. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    You may have already seen something like:
    PHP:
    $this->variable 'example';
    I believe you can also read a bit about this here. Correct me if I'm wrong.
    Also, you should be fine by storing it in an array.
     
  18. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    You are wrong ._. I need to get entity ID Everytime I spawn one ...And I know how to store data...I just want to know how can I get floats entity Id if I use your method
     
  19. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    I suggest you to save the FloatingTextParticle objects, because to get the entityId value you could be forced to create a new class which extends the FloatingTextParticle class and makes you able to get this value. You cannot get this without doing something similar, because it is a protected variable.
     
  20. Orlando092

    Orlando092 Creeper

    Messages:
    5
    GitHub:
    orlando092
    OnEnable:
    PHP:
    $this->particles = [];

    Add particle:

    PHP:
    $particle = new FloatingTextParticle($pos"""");
     
    $particle->setText(C::AQUA.$float);

    $this->particles[$player] = $particle;
    $level->addParticle($particle, [$player]);

    Update it with:
    PHP:
    $this->particles[$player]->setText("blah");

    $level->addParticle($this->particles[$player], [$player]);
    Last time this was working on my server
     
    Last edited: Apr 29, 2017
    Az928 likes 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.