Im trying to use floating text for my server, i looked around and found this PHP: // To create the particle$ftext = new FloatingTextParticle(Vector3 $position, int $text, string $title);// To spawn it so players can see it:$level->addParticle($ftext); then i tried doing myself, i made a new function and ran it in onEnable PHP: public function spawnText() { $infoParticle = new FloatingTextParticle(new Position(67, 10, - 963, $this->getServer()->getLevelByName("SkyBlock")), "§l§bINFO", ""); $this->getServer()->getLevelByName("SkyBlock")->addParticle($infoParticle); } i joined the server, there was no error and no text. If anyone could help i would appreciate it
PHP: <?phpdeclare(strict_types=1);namespace Primo;use Primo\Commands\BypassCommand;use Primo\Events\Block\{BlockBreak, BlockPlace};use pocketmine\level\Level;use pocketmine\level\Position;use pocketmine\level\particle\FloatingTextParticle;use pocketmine\plugin\PluginBase;class Loader extends PluginBase { const PREFIX_GREEN = "§l§7(§a!§7)§r§7 "; const PREFIX_GOLD = "§l§7(§6!§7)§r§7 "; const PREFIX_RED = "§l§7(§c!§7)§r§7 "; public function onEnable() { @mkdir($this->getDataFolder()); $this->saveResource("BypassedPlayers.txt"); $this->loadCommands(); $this->loadEvents(); $this->spawnText(); } public function loadCommands() { $this->getServer()->getCommandMap()->registerAll("Primo", [ new BypassCommand("bypass", $this) ]); } public function loadEvents() { $events = [ new BlockBreak($this), new BlockPlace($this) ]; foreach($events as $event) { $this->getServer()->getPluginManager()->registerEvents($event, $this); } } public function spawnText() { $infoParticle = new FloatingTextParticle(new Position(67, 10, - 963, $this->getServer()->getDefaultLevel()), "", "§l§bINFO"); $this->getServer()->getDefaultLevel[()->addParticle($infoParticle); }}
Oh nvm. Your error is on Enable. Should be ran on Join not on Enable. Reason being you must set it when they join not when server loads plugin
That would cause major lag, since the particle would spawn in the same place everytime a player joins.
Incorrect. It doesn’t despawn for everybody else when you leave. By using the current code: - A player joins, floating text particle is added - Another player joins, floating text particle is added to level again ...and so on. The first player will see two floating text particles (because it was added and sent to them twice) while the second player will only see one because the previous particle wasn’t sent to them. This continues and in the end, you’ll have many floating text particles added at the same spot (not sure if the first player would be happy about that!). To avoid this problem, all you need to do is add another argument to the code you’re already using to send the floating text particle to the player: PHP: $this->getServer()->getDefaultLevel()->addParticle($infoParticle, [$player]); ($player is an instance of Player) The 2nd argument to addParticle() (make sure you’re sending an array) allows you to choose which players to send the particle to. If you don’t set the 2nd argument, by default it’ll send the particle to everybody in the server. By using this code, you’re ensuring that you only send the floating text particle to the player who is meant to receive it (the player who has just joined, not everybody else).