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

Inventory

Discussion in 'Development' started by Alex, Nov 16, 2017.

  1. Alex

    Alex Spider Jockey

    Messages:
    28
    GitHub:
    Bichwha
    Hey, so im coding a plugin and i need help on how to get whst slot the player is holding and removing a item off it
     
  2. Ant

    Ant Spider

    Messages:
    9
    GitHub:
    Dead
    Reference:
    PlayerInventory::getHeldItemIndex(): int
    BaseInventory::clear(int $index, bool $send = true): bool
    Human::getInventory(): PlayerInventory (Return of this method will be instance of PlayerInventory only if entity is instance of Player)

    PHP:
    /** @var Player $player */
    $index $player->getInventory()->getHeldItemIndex();

    // Remove this item from player inventory
    if($player->getInventory()->clear($indextrue)) {
        
    // The item was taken
    } else {
        
    // Somehow, it failed.
    }
     
    jasonwynn10 likes this.
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    $player->getInventory()->setItemInHand(Item::get(Item::AIR)); //deletes all items in the slot
    $item $player->getInventory()->getItemInHand();
    $item->pop(); // deletes a single item off the stack
    $player->getInventory()->setItemInHand($item);
     
    Last edited: Nov 17, 2017
    Ant likes this.
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I think you just want to decrease count by one. He's asking for removing "a(n)" item.
     
    jasonwynn10 likes this.
  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.