Effect(PMMP 4.0.0)

Discussion in 'Plugin Help' started by NiLen, Jun 17, 2022.

  1. NiLen

    NiLen Spider

    Messages:
    8
    What is wrong?

    Error: "Call to undefined method pocketmine\entity\effect\Effect::getEffect()" (EXCEPTION) in "plugins/Borrow_plugin/src/Borrow/MainBorrow" at line 34

    <?php

    namespace Borrow;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\entity\EntityDamageByEntityEvent;
    use pocketmine\event\entity\EntityDamageByChildEntityEvent;
    use pocketmine\entity\effect\Effect;
    use pocketmine\entity\Entity;
    use pocketmine\utils\Config;
    use pocketmine\inventory\Inventory;
    use pocketmine\entity\EffectInstance;
    use pocketmine\player\Player;

    class MainBorrow extends PluginBase implements Listener {

    function onEnable() : void {
    $this->config = new Config($this->getDataFolder()."config.yml", Config::YAML);
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->info("lol");
    }

    function onDisable() : void {
    $this->getLogger()->info("lol");
    }

    public function onDamage(EntityDamageEvent $event){
    if($event instanceof EntityDamageByEntityEvent && $event->getDamager() instanceof Player) {
    $player = $event->getEntity();
    $damager = $event->getDamager();
    if($damager->getInventory()->getItemInHand()->getId() == 261){
    $effect = Effect::getEffect(9);
    $effect = new EffectInstance($effect, 20 * 5, 1);
    $entity->addEffect($effect);
    }
    }
    }
    }
     
  2. DavyCraft648

    DavyCraft648 Spider Jockey

    Messages:
    40
    GitHub:
    DavyCraft648
    PHP:
    use pocketmine\entity\Living;
    use 
    pocketmine\entity\effect\{EffectEffectInstanceVanillaEffects};
    use 
    pocketmine\event\entity\{EntityDamageByEntityEventEntityDamageEvent};
    use 
    pocketmine\item\VanillaItems;
    use 
    pocketmine\player\Player;
    PHP:
    public function onDamage(EntityDamageEvent $event): void {
        if (
    $event instanceof EntityDamageByEntityEvent && ($damager $event->getDamager()) instanceof Player) {
            
    $entity $event->getEntity();
            if (
    $entity instanceof Living && $damager->getInventory()->getItemInHand()->equals(VanillaItems::BOW(), falsefalse)) {
                
    $entity->getEffects()->add(new EffectInstance(VanillaEffects::NAUSEA(), 20 51));
            }
        }
    }
     

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.