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

How i add a Effect code?

Discussion in 'Development' started by Baducai, Mar 1, 2018.

  1. Baducai

    Baducai Spider Jockey

    Messages:
    30
    GitHub:
    Baducai
    How i added a effect to interact with a Item
     
  2. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    Any previous attempts?
     
  3. Baducai

    Baducai Spider Jockey

    Messages:
    30
    GitHub:
    Baducai
    No
     
  4. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    You have to try it yourself first, and then ask for help here. Show us what you tried, and what doesn't work.
     
  5. What exactly do you mean, the description is too vague.
     
  6. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:

    Use:

    use 
    pocketmine\entity\Effect;

    Code:

    $player->addEffect(Effect::getEffect(Effect::SPEED));
     
  7. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    He wants help lmao that why he asked us
     
  8. CortexPE

    CortexPE Witch

    Messages:
    61
    GitHub:
    cortexpe
  9. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    some bullshit we got here, u couldve given a better code if you gonna feed the op
     
    OnTheVerge likes this.
  10. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    Hello there @Baducai I hope this helps you:)

    Libraries:
    PHP:
    use pocketmine\plugin\PluginBase as PB;
    use 
    pocketmine\event\Listener as L;
    use 
    pocketmine\Player;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    Code for adding effects when you Interact with an Item:

    PHP:
    public function onInteract(PlayerInteractEvent $ev){
     
    $player $ev->getPlayer();
     
    $item $ev->getItem();

    #Effects
    $haste Effect::getEffect(3); //Effect Id for haste
    $haste->setDuration(6273); //the Duration for the effect
    $haste->setAmplifier(2); //Amplifier for effect
    $haste->setVisible(true);
    ---
    $speed Effect::getEffect(1); //Effect Id for Speed
    $speed->setDuration(6273); //the Duration for the effect
    $speed->setAmplifier(2); //Amplifier for effect
    $speed->setVisible(true);
    ---

         switch(
    $item->getId()){

       case 
    388//First Item which is a emerald btw
      
    $player->sendMessage(TF::GREEN "Your wish has been granted");
      
    $player->addEffect($haste); //adds haste effect

    break;

       case 
    426//Second Item which is a ender crystal :)
       
    $player->sendMessage(TF::DARK_AQUA "Your wish has been granted");
       
    $player->addEffect($speed); //adds speed effect

    break;
      }
    }
    I hope this reply helped you to fully understand how to add effects, goodluck with your plugin mate:)
     
  11. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Better than not giving code
     
    Levi likes this.
  12. Phqzing

    Phqzing Spider

    Messages:
    8
    GitHub:
    phqzing
    It says " Call for undefined method pocketmine\entity\Effect::setDuration() "
     
  13. IvanCraft623

    IvanCraft623 Baby Zombie

    Messages:
    105
    GitHub:
    IvanCraft623
    hummm...

    This thread is from 3 years ago, with the passage of time the API changes, well here is an example of how to do it in PM3 (currently), although in a few months after PM4 this method will be obsolete.

    Libraries:
    PHP:
    use pocketmine\Player;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\EffectInstance;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    Code:
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
        
    $player $event->getPlayer();
        
    $item $event->getItem();
        
    $id $item->getId();
        
    $name $item->getCustomName();
        if (
    $id == 388 and $name === "Especial Emerald") { //Here you must specify the id of the item with which it will interact and the name of the item.
            
    $player->addEffect(new EffectInstance(Effect::getEffect(Effect::HASTE), 20*601true));
        }
    }
     
  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.