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

Solved error when giving some effect

Discussion in 'Plugin Help' started by Igor Da silva, Jan 10, 2021.

  1. Igor Da silva

    Igor Da silva Creeper

    Messages:
    3
    hello, I tried to make the player receive effects when interacting with a certain item, but there was an error that I couldn't solve.

    error:
    [21:35:26] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\entity\Effect::setAmplifier()" (EXCEPTION) in "plugins/CustomPot/src/ZanoKing/CustomPot/Main" at line 42

    part of the most relevant code:

    PHP:
    use pocketmine\entity\Effect;

    //function onInteract
           
          
    $pot Effect::getEffect(1);
    (
    42)  $pot->setAmplifier(2);
          
    $pot->setVisible(true);
          
    $pot->setDuration(273);
          
    $player->addEffect($pot);
    and sorry for the english of the google translator
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    For Player->addEffect() you have to use EffectInstance instead of Effect
     
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Your code is outdated.

    PHP:
    use pocketmine\entity\EffectInstance;
    use 
    pocketmine\entity\Effect;

    $effect Effect::getEffect(9); // Declaring effect (Confusion)
    $duration 20 4// Duration. 20 = 1 second
    $amplification 0// Lv1 is 0
    $visible false// Particle
    $instance = new EffectInstance($effect$duration$amplification$visible); //Effect Instance
    $player->addEffect($instance); // Adds Effect
     
    Igor Da silva likes this.
  4. Igor Da silva

    Igor Da silva Creeper

    Messages:
    3
    thanks bro, i'll see better about the EffectInstance class
     
    minijaham likes this.
  5. Igor Da silva

    Igor Da silva Creeper

    Messages:
    3
    thanks bro, really I had seen it in a 2018 forum and also in an older plugin
     
  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.