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

Solved How to get the slot of item on interact event?

Discussion in 'Development' started by Yexeed, Jan 22, 2018.

  1. Yexeed

    Yexeed Slime

    Messages:
    76
    How I can get an item slot when PlayerInteractEvent called?
     
  2. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    On the event, run this:
    PHP:
    $inv $event->getPlayer()->getInventory();
    $item $event->getItem();
    foreach(
    $inv->getContents() as $slot => $it){
       if(
    $it->equals($item)){
          
    $event->getPlayer()->sendMessage("The slot is {$slot}");
       }
    }
    Note: Sometimes it may not work, so check if $it damage and I'd matches $item values, then do same as shown in code
     
    Yexeed and xXNiceAssassinlo YT like this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    $slot $event->getPlayer()->getInventory()->getHeldItemIndex();
     
    Yexeed likes this.
  4. Yexeed

    Yexeed Slime

    Messages:
    76
    Thanks alot guys, it really helped!
     
  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.