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

Floating text

Discussion in 'Facepalm' started by LucGamesDE, May 31, 2017.

  1. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    How can I create floating texts?
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    PHP:
    // To create the particle
     
    $ftext = new FloatingTextParticle(Vector3 $positionint $textstring $title);
     
    // To spawn it so players can see it:
     
    $level->addParticle($ftext);
    The class path is pocketmine\level\particle\FloatingTextParticle.
    It's pretty self explanatory, but you need an instance of Vector3 for the position of the floating text, and a string to set the text of the particle I'm not sure why, but $text is supposed to be an int according to PMMP's source code, and $title is a string. You can use a player or block object for the position if you want to.

    Fun Fact: Floating Text Particles aren't an actual particle. They are invisible entities with set nametags. :p
     
    Last edited: May 31, 2017
    Sandertv likes this.
  3. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    Ok. And how can I add infos for each player to th text?
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Can you give an example?
     
  5. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    How should I give an example if I don't know how it works?
     
  6. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I was asking if you could give the name of what you want help with. What player info? Players have a lot of data. You were very vague about what you were asking.
     
  7. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    TextParticle for each player
     
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    $level->addParticle has an optional second parameter for what players you want to spawn the floating text particle to. If you leave it null, it is broadcasted as a chunkpacket. You can see the entire method in the source here.

    If you want to send it to a single player, you can do this:
    PHP:
     /** @var Player $player */
     
    $ftext = new FloatingTextParticle($player"Text");
     
    $player->level->addParticle($ftext, [$player]);
     
  9. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    And how can I remove them? And new joined players don't see them
     
  10. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You can set it invisible, but without using packets, you can't, really. You may be interested in using packets directly. You can send it to players when they join. There's some good content in this thread about that.
     
  11. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    What level?
     
  12. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    The level the player is in, or the level you chose
    I recommend getting the level by name
    PHP:
    $level $this->getServer()->getLevelByName("kitpvp");
     
  13. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    But when I use code then error:

    Call a member function addParticle() on null

    How to fix:((
     
  14. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    That probably means the world isn't loaded, or doesn't exist
    What's the name of your world, and can you show the lines of code that give that error?
     
  15. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    I load world but floating text don't work. My code:

    PHP:
    public function add(PlayerJoinEvent $ev) {
         foreach((array) 
    $this->getServer()->getProperty("lobby", []) as $lobby){
              
    $this->getServer()->loadLevel($lobby);
              
    $text "Welcome";
              
    $title "+++++++";
              
    $floating = new FloatingTextParticle(new Vector3(100100100), $text$title);
              
    $level $this->getServer()->getLevelByName("lobby");
              
    $level->addParticle($floating);
    }
    }
     
  16. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    Hi, you delete code?
     
  17. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    Accidentally, I was tired and started doing random things, I'll give it in a few hours (it's 5am rn)
     
  18. WoolChannel3295

    WoolChannel3295 Silverfish

    Messages:
    22
    GitHub:
    KietTran0308
    So can you give me the code again :((?
     
  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.