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
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
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) {
Doesn't make sense. Where is he going to get Player object from? Mind using https://github.com/Falkirks/Holograms ?
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.
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.
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()]);
You need datapackets: PHP: public function addFTP($player){$text = "§aHello §b".$player->getName();$pk = new AddPlayerPacket(); $pk->eid = 80000; $pk->uuid = UUID::fromRandom(); $pk->x = 128; $pk->y = 4; $pk->z = 128; $pk->speedX = 0; $pk->speedY = 0; $pk->speedZ = 0; $pk->yaw = 0; $pk->pitch = 0; $pk->item = Item::get(0); $flags = 0; $flags |= 1 << Entity::DATA_FLAG_INVISIBLE; $flags |= 1 << Entity::DATA_FLAG_CAN_SHOW_NAMETAG; $flags |= 1 << Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG; $flags |= 1 << 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_FLOAT, 0], 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;
you could use individual FTPs so $holder = [] // $playername => FTP "instance" and when spawning, spawn to player individually if that's what you asking