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

FloatingTextParticle problem

Discussion in 'Development' started by VentroxStudio, Dec 29, 2016.

  1. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Hi,
    I tried to add some FloatingTextParticles to a world (PlayerJoinEvent). My code works. But they're getting more and more (Every time a player joins).

    My code:
    PHP:
    $level->addparticle(new FloatingTextParticle(new Vector3($x1$y1$z1), "My Text"));
    I hope someone could help me :)
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    Code:
    $particle = new FloatingTextParticle(new Vector3($x1, $y1, $z1), "My Text");
    
    send:
    $level->addParticle($particle);
    update:
    $particle->setText("My Text 2");
    $particle->setInvisible(false);
    remove:
    $particle->setInvisible();
    goto send:
    
    After setting particle invisible remember to actually remove it from level by sending again
     
  3. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Mh. I found something out it's only if I use player->getName in the Text
     
  4. kaliiks

    kaliiks Zombie

    Messages:
    250
    add floating text in function onEnable
     
  5. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    I can't get a player's name onEnable....
     
  6. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    public function addParticle(Player $p) {
    $level = ...
    $level->addparticle(new FloatingTextParticle(new Vector3($x1$y1$z1), "My Text"));
    }

    public function 
    onEnable(){
    $this->addParticle(Player $p) {
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    Doesn't make sense. Where is he going to get Player object from?

    Mind using https://github.com/Falkirks/Holograms ?
     
    Hariz likes this.
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    What are you trying to display on the text? What variables do you need? Perhaps try spawning the text to each person separately, if each player needs their own FTP. Please give a few more details if you want a good solution. :D
     
  9. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    The core implementation of FTP is bad, very hacky. I intend to re-implement it at some stage.
     
  10. kaliiks

    kaliiks Zombie

    Messages:
    250
    you can remove it on quit and spawn on join
     
  11. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    That still doesn't solve OP's issue. If any more than 1 person is online, more than one FTP will exist at a time.
     
  12. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    I think you may want to look at the second parameter of addParticle() here.
    Use it to prevent sending it to other players

    Short example if you use it on PlayerJoinEvent:
    PHP:
     $event->getPlayer()->getLevel()->addParticle($particle, [$event->getPlayer()]);
     
    Last edited: Dec 30, 2016
    Sandertv and corytortoise like this.
  13. imYannic

    imYannic Baby Zombie

    Messages:
    113
    You need datapackets:
    PHP:
    public function addFTP($player){

    $text "§aHello §b".$player->getName();

    $pk = new AddPlayerPacket();
                
    $pk->eid 80000;
                
    $pk->uuid UUID::fromRandom();
                
    $pk->128;
                
    $pk->4;
                
    $pk->128;
                
    $pk->speedX 0;
                
    $pk->speedY 0;
                
    $pk->speedZ 0;
                
    $pk->yaw 0;
                
    $pk->pitch 0;
                
    $pk->item Item::get(0);
        
    $flags 0;
                
    $flags |= << Entity::DATA_FLAG_INVISIBLE;
                
    $flags |= << Entity::DATA_FLAG_CAN_SHOW_NAMETAG;
                
    $flags |= << Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG;
                
    $flags |= << Entity::DATA_FLAG_IMMOBILE;
                
    $pk->metadata = [
                    
    Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG$flags],
                    
    Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING$text], Entity::DATA_SCALE => [Entity::DATA_TYPE_FLOAT0],
                    
    Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1],
                ];

    $player->dataPacket($pk);

    }
    These are only sent to the special player and you can obviously use their name and properties in the text too.


    And don't forget the uses:
    PHP:
    use pocketmine\network\protocol\AddPlayerPacket;
    use 
    pocketmine\utils\UUID;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\entity\Entity;
     
    VentroxStudio likes this.
  14. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you could use individual FTPs
    so
    $holder = [] // $playername => FTP "instance"
    and when spawning, spawn to player individually if that's what you asking
     
  15. VentroxStudio

    VentroxStudio Witch

    Messages:
    71
    Thanks that helped!
     
  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.