How can I make the particles repeat

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

  1. Minetron26

    Minetron26 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    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:
    616
    GitHub:
    xXNiceYT
    Make task
     
  3. Minetron26

    Minetron26 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    Yes, but how do I make the task repeat this
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

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

    Minetron26 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    well, thanks for the help
     
    xXNiceAssassinlo YT likes this.
  6. Minetron26

    Minetron26 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    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:
    616
    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 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    gives an error that says the player variable is not defined
     
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

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

    Minetron26 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    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 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    One more thing, how can I cancel the task?
     
  12. RumDaDuMCPE

    RumDaDuMCPE Slime

    Messages:
    77
    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 Wither Skeleton Verified

    Messages:
    1,241
    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 Spider Jockey

    Messages:
    25
    GitHub:
    minetron-26
    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 Wither Skeleton

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

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    476
    $mainClass->getScheduler()->cancelTask($this->getTaskId());
     

Share This Page

  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.