Hi, I need to know how I can use a Task to repeat the particle spawneo when interacting with an item, like this: PHP: if($item->getName() == "Particles"){ $player->getLevel()->addParticle(new FlameParticle(new Vector3($player->getX(), $player->getY() + 0.5, $player->getZ())), $players); } But to be repeated constantly, please help me
Well, but you could give me an example of how to do the task, I already read the publication of how to do one in "Resources" but I could not get it to fulfill what I need
Interact: PHP: public function onInteract(PlayerInteractEvent $e): void{$player = $e->getPlayer();$item = $e->getItem();if($item->getName() == "Particle") $this->getScheduler()->scheduleRepeatingTask(new Particle($player), 20);} PHP: private $player;public __construct(Player $player){$this->player = $player;}public function onRun(int $tick): void{$this->player->getLevel()->addParticle();}
oh, many but thank you very much, I have already managed to solve it, thank you very much for the help
PHP: public $tasks = [];public function onInteract(PlayerInteractEvent $e): void{$player = $e->getPlayer();$item = $e->getItem();if($item->getName() == "Particle") $this->getScheduler()->scheduleRepeatingTask(new Particle($player, $this), 20);} PHP: private $player, $main;public __construct(Player $player, $main){$this->player = $player;$this->main = $main;$this->main->tasks[$this->getHandler()->getTaskId()] = $this->player->getId();}public function onRun(int $tick): void{$this->player->getLevel()->addParticle();} Now, To cancel your task, you may add this to your Main. PHP: private function cancelTask($id) { $this->getScheduler()->cancelTask($id);} An example; PHP: public function onDamage(EntityDamageEvent $event) { if ($event->getEntity() instanceof \pocketmine\Player) { $this->cancelTask($entity->getId()); }}
Here's a plugin script example to make a particle world border. You can probably use this to see how a repeating task works with particles
Well, thanks, and if I want the task to be canceled for a player, should I put the player variable instead of entity or not?