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

Solved How can I make the particles repeat

Discussion in 'Development' started by Minetron26, Sep 12, 2018.

  1. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    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
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Make task
     
  3. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Yes, but how do I make the task repeat this
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    schduleRepeatingTask
     
    Minetron26 likes this.
  5. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    well, thanks for the help
     
    xXNiceAssassinlo YT likes this.
  6. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    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
     
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    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();
    }
     
    InspectorGadget and Minetron26 like this.
  8. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    gives an error that says the player variable is not defined
     
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Send code
     
    Minetron26 likes this.
  10. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    oh, many but thank you very much, I have already managed to solve it, thank you very much for the help
     
    xXNiceAssassinlo YT likes this.
  11. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    One more thing, how can I cancel the task?
     
  12. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    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());
        }
    }
     
    Minetron26 likes this.
  13. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    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
     
  14. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    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?
     
  15. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Entity is the player variable
     
    RumDaDuMCPE likes this.
  16. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    $mainClass->getScheduler()->cancelTask($this->getTaskId());
     
  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.