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

Need help with PlayerInteractEvent

Discussion in 'Plugin Help' started by Exconic, Apr 19, 2020.

  1. Exconic

    Exconic Spider

    Messages:
    14
    GitHub:
    poyq
    How do u make pots disappear like after you use em for an example would I use the PlayerInteractEvent
     
  2. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    What is pots
     
  3. Exconic

    Exconic Spider

    Messages:
    14
    GitHub:
    poyq
    speed pot and fire pot
     
  4. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    I don't know what is it
     
  5. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
  6. Exconic

    Exconic Spider

    Messages:
    14
    GitHub:
    poyq
  7. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    U mean effect?
     
  8. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
    Remove some or remove all
     
  9. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Doesn't it automatically remove the potion from your inventory when you drink it?
     
  10. Exconic

    Exconic Spider

    Messages:
    14
    GitHub:
    poyq
    No but that's what I want
     
  11. anirudh246

    anirudh246 Spider Jockey

    Messages:
    29
  12. Exconic

    Exconic Spider

    Messages:
    14
    GitHub:
    poyq
    Ik, I just want to know how I would go around to do this
     
  13. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    PHP:
    public function onInteract(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        
    $item $event->getItem();
        if(
    $item->getId == 373){
            
    $effect = new EffectInstance(Effect::getEffect(1), 201); //add speed for 1 second you know
            
    $effect->setVisible(false);
            
    $player->addEffect($effect);
            
    $player->getInventory()->removeItem($player->getInventory()->getItemInHand());
        }
    }
    list of id items: https://gamepedia.cursecdn.com/mine....png?version=b4c261e3c01eca5dedcce349917039d7
     
  14. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    pots means potions haha
     
  15. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    (click on the image to play the video)


    So you want to drink the potion normally, but instead of an empty bottle remaining nothing should remain?

    By PlayerInteractEvent, do you mean that you want a potion to be instantly consumed when clicking it on the floor?

    Don't. Hardcode. IDs. Ever.
     
  16. HiToLaKhanh

    HiToLaKhanh Spider Jockey

    Messages:
    25
    GitHub:
    HiToLaKhanh
    he wants to clear the bottle after drinks potions dude
     
  17. lunix

    lunix Spider

    Messages:
    8
    PlayerInteractEvent is not the way to go here as this fires right when you click something, not after drinking the potion (which is what the author wants). And, please use the constants from src/pocketmine/item/ItemIds.php instead of hardcoding the ID.

    Try using the PlayerItemConsumeEvent instead.
     
    Last edited: Apr 21, 2020
    GamakCZ likes this.
  18. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    In that case you sent the wrong code, dude
    (see @lunix's reply as to why)
     
  19. NTT

    NTT Zombie

    Messages:
    311
    GitHub:
    NTT1906
  20. Exconic

    Exconic Spider

    Messages:
    14
    GitHub:
    poyq
    Thanks for the help this is now solved
     
  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.