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

Remove particles

Discussion in 'Plugin Help' started by Willoxey, Apr 11, 2020.

  1. Willoxey

    Willoxey Spider Jockey

    Messages:
    33
    Hi there! i'm trying to make a Particle effects plugin for my server.
    The VIP have some particles when they walk but i want that to desactive it if they want, but i cant figure it out how could i do it with a command. So for example if the player execute the command /particle the plugin give him the particles, but if he execute /particlesno the particles dissapear.
    For now i have this code. Thanks! PD: I can add this in an UI Core that i have. But first i want to know how i could disactive that particles.
    PHP:
             public function particulas(PlayerMoveEvent $event) {
                 
    $player $event->getPlayer();
                 
    $pos $player->getPosition();
                if(
    $event->getPlayer()->hasPermission("tornadus.particulas.lobby") == true) {
                
    $red = new DustParticle($pos->add(02.5), 2521717);
                
    $orange = new DustParticle($pos->add(02.1), 25213517);
                
    $yellow = new DustParticle($pos->add(01.7), 25225217);
                
    $green = new DustParticle($pos->add(01.3), 1725217);
                
    $lblue = new DustParticle($pos->add(00.9), 9494252);
                
    $dblue = new DustParticle($pos->add(00.5), 1717252);

                foreach ([
    $red$orange$yellow$green$lblue$dblue] as $particle) {
                
    $pos->getLevel()->addParticle($particle);
                    }
                 }
             }
     
    Last edited: Apr 11, 2020
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You could either save the player who have it disabled (or enabled) in an array or remove the permission from them when they use the command.
     
    GamakCZ likes this.
  3. Willoxey

    Willoxey Spider Jockey

    Messages:
    33
    How do i make the array? so they can enable or disable it
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Make a class property.
    PHP:
    private $particlesEnabled = [];
    When the player executes the command, the following code will toggle the particles:
    PHP:
    $name $sender->getName();
    if (!isset(
    $this->particlesEnabled[$name]) {
      
    $this->particlesEnabled[$name] = false;
    }
    $this->particlesEnabled[$name] = !$this->particlesEnabled[$name];
    In your particle function:
    PHP:
    if (isset($this->particlesEnabled[$name]) && $this->particlesEnabled[$name]) {
      
    // do particle stuff
    }
     
    Willoxey likes this.
  5. Willoxey

    Willoxey Spider Jockey

    Messages:
    33
    Thank you very much Himber. Very helpful. It worked. :)
     
    HimbeersaftLP likes this.
  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.