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

Solved Get Player Inventory Empty Slot

Discussion in 'Development' started by Bintang Putra, Jun 2, 2017.

  1. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Hi, I Have A Plugin That Add Few Items To Player's Inventory
    But, I Want To Check If The Player Had The Empty Slots Needed

    Example :
    I Want To Give Player 1 Wood and 1 Sword, Then It Will Need 2 Empty Slots

    How To Check It?

    Sorry For My Bad English
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Use PlayerInventory::canAddItem(Item);
    PHP:
    $item Item::get(Item::IRON_SWORD01);
    /** @var Player $player */
    if($player->getInventory()->canAddItem($item)){
        
    //There is space for $item in $player's inventory.
    }
     
    Last edited: Jun 3, 2017
    corytortoise likes this.
  3. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    @Muqsit
    So It Return True If There Is A Space?
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yes
     
  5. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    What Is Item::?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Refer to the source code.
    Item is an object instance of Item (or an Item itself).
     
    corytortoise likes this.
  7. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Oh , I Understand, Thanks :D
     
    Muqsit likes this.
  8. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    But, How If I Use ItemID Instead Of ItemName
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    ::class means class name as string. It's very misleading :(
     
  10. Bintang Putra

    Bintang Putra Witch

    Messages:
    63
    GitHub:
    chaostixzix
    Ok Thank You :D
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And that's not what he means.
     
  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.