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

Effects on join

Discussion in 'Development' started by Skylark, Oct 17, 2020.

  1. Skylark

    Skylark Creeper

    Messages:
    4
    GitHub:
    skylark
    Can someone help me with this?
    PHP:
    <?php

    namespace Effectsplugin;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;

    use 
    pocketmine\entity\Effect;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;   

    class 
    main extends PluginBase implements Listener {

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->getLogger()->info("Plugin Enabled");
        }

        public function 
    onPlayerJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            
    $effect Effect::getEffect(Effect::NIGHT_VISION);
            
    $effect->setDuration(99999);
            
    $effect->setAmplifier(1);
            
    $effect->setVisible(false);
            
    $player->addEffect($effect);
        }
    }
     
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    $player->addEffect(new EffectInstance($effect));
     
    Skylark likes this.
  3. Skylark

    Skylark Creeper

    Messages:
    4
    GitHub:
    skylark
    nothing happens :(
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    import EffectInstance?
     
  5. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    Use this:
    PHP:
    use pocketmine\Server;
    use 
    pocketmine\Player;

    use 
    pocketmine\entity\{EffectEffectInstance};

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;   

    class 
    main extends PluginBase implements Listener {

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->getLogger()->info("Plugin Enabled");
        }

        public function 
    onPlayerJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            
    $player->addEffect(new EffectInstance(Effect::getEffect(Effect::NIGHT_VISION), (99999*20), (1), (false)));
        }
    }
     
    Skylark likes this.
  6. Skylark

    Skylark Creeper

    Messages:
    4
    GitHub:
    skylark
    i try this and it works but whnever a player respawn he doesnt get the effect
    PHP:
    <?php

    namespace Effectsplugin;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;

    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\EffectInstance;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\ConsoleCommandSender;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;   

    class 
    main extends PluginBase implements Listener {

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->getLogger()->info("Plugin Enabled");
        }

        public function 
    onPlayerJoin(PlayerJoinEvent $event){
            
    $player $event->getPlayer();
            
    $effect Effect::getEffect((int) 16);
            
    $duration 9999999;
            
    $amplification 2;
            
    $visible false;
            
    $instance = new EffectInstance($effect$duration$amplification$visible);
            
    $player->addEffect($instance);
        }

        public function 
    onPlayerRespawn(PlayerRespawnEvent $event){
            
    $player $event->getPlayer();
            
    $effect Effect::getEffect((int) 16);
            
    $duration 9999999;
            
    $amplification 2;
            
    $visible false;
            
    $instance = new EffectInstance($effect$duration$amplification$visible);
            
    $player->addEffect($instance);
        }
    }
     
  7. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    try adding a few ticks of delay to it
     
  8. Skylark

    Skylark Creeper

    Messages:
    4
    GitHub:
    skylark
    im still new in coding sorry but can you make it or just a pattern i can follow cause i really cant make it
     
  9. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
            $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function (?int $currentTick) use($player$instance): void{
               
    $player->addEffect($instance);
            }), 
    5);
     
  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.