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

Change the text of a floating text particle + multiple levels bug

Discussion in 'Development' started by MalakasPlayzMCPE, Aug 12, 2018.

  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Alright, so the owner/developer of the server I am working on gets bug reports from the players for the leaderboard which is in a floating text. It does not refresh when any of the top 10 players get a win. We are both trying to find a method to refresh the leaderboard while the player is in-game, because what we did before was just adding the particle on the join event to the player who joins. We explained them this is not a bug, they have to re-join in order to get the refreshed leaderboard. Is there any way to auto refresh them in a task? Keep in mind that there are spawning to the player every time he joins, so you can't get an actual entity id. Also, the leaderboards are being shown in the other worlds when I only spawned them to the Lobby. Can this be fixed?
     
  2. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Save the floating text object you are spawning to the players. Set the text of the floating text particle, before spawning it again to the player. The previous floating text entity will be despawned and a new one will be spawned with the updated text.
     
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    How to save them? I use addParticle()
    I tried to despawn them but I couldn't
     
  4. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Here's an example:
    PHP:
    private $floatingTextParticle;
    private 
    $spawnedTo = [];

    public function 
    onEnable()
    {
        
    $this->floatingTextParticle = new FloatingTextParticle(new Vector3(01280), "DaPigGuy""Best Pig of the Month");
    }

    public function 
    spawnFloatingTextParticleTo(Player $player)
    {
        
    $player->getLevel()->addParticle($this->floatingTextParticle, [$player]);
        
    $this->spawnedTo[$player->getId()] = $player;
    }


    public function 
    despawnFloatingTextParticleTo(Player $player)
    {
        
    $this->floatingTextParticle->setInvisible();
        
    $player->getLevel()->addParticle($this->floatingTextParticle, [$player]);
        
    $this->floatingTextParticle->setInvisible(false);
        unset(
    $this->spawnedTo[$player->getId()]);
    }

    public function 
    setFloatingTextParticleText(string $text)
    {
        
    $this->floatingTextParticle->setText($text);
        foreach (
    $this->spawnedTo as $player) {
            if(!
    $player->closed){
                
    $player->getLevel()->addParticle($this->floatingTextParticle, [$player]);
            }
        }
    }
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Uhh, sorry for that but I forgot to say that I am spawning 1 entity for each player in the list. I would really like to make that but first, would you tell me how to fix the world bug?
     
  6. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Are you spawning a floating text particle with different text to every player? If not, spawning one for each player is unnecessary. As for your 2nd issue, you can check the level the player is in after a level change. If it's not the correct level, despawn the floating text (shown above).
     
  7. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Okay, too OP for me. Thank you for your time anyway.
     
  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.