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

Effect on right click

Discussion in 'Development' started by XCodeMCPE, Nov 26, 2017.

  1. XCodeMCPE

    XCodeMCPE Slime

    Messages:
    96
    GitHub:
    xcodemcpe
    I have a plugin that i am working on which involves menus and hotbar items and I have a menu for cosmetics and i want it to give that player an effect, like when you tap down on the book it enables speed and when you click it again it disables it. How would I do that?
     
  2. NickTehUnicorn

    NickTehUnicorn Zombie

    Messages:
    200
    GitHub:
    unickorn
    Use PlayerInteractEvent, get the item player interacts with, if the id is what you want give player effect. If player already has effect, remove the effect.

    See these;
    For effects:
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Effect.php#L36

    For adding effects:
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Living.php#L237

    For PlayerInteractEvent and getting the item:
    https://github.com/pmmp/PocketMine-...mine/event/player/PlayerInteractEvent.php#L89

    TIP: Always try checking the source code to find out how you can do stuff. (or use an IDE)
     
    QuiverlyRivalry likes this.
  3. XCodeMCPE

    XCodeMCPE Slime

    Messages:
    96
    GitHub:
    xcodemcpe
    Am I missing something?

    }elseif($item->getId() === Item::BOOK and stripos($item->getName(), "speed") !== false) {
    $event->getPlayer()->addEffect(Effect $effect){
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Effect $effect..?
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Forwarding a reply from a duplicated thread:
     
    NickTehUnicorn likes this.
  6. XCodeMCPE

    XCodeMCPE Slime

    Messages:
    96
    GitHub:
    xcodemcpe
    Thanks
     
  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.