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

How to check if inventory is full?

Discussion in 'Development' started by Noobie, Dec 12, 2016.

  1. Noobie

    Noobie Silverfish

    Messages:
    16
    Is there a way to check if inventory is full? Because i wanna do addItem(), so what if the inventory of the player is full and additem() didn't work?
     
  2. Aviv

    Aviv Baby Zombie

    Messages:
    156
    I think theres a function called Inventory::canAddItem(), if that doesnt exist theres a code
    PHP:
    public function isInventoryFull(Player $player){
        
    $full true;
        for(
    $i 0;$i $player->getInventory()->getSize();$i++){
            if(
    $player->getInventory()->getItem($i)->getId() === 0){
                
    $full false;
            }
        }
        return 
    $full;
    }
     
    Skullex and Noobie like this.
  3. Noobie

    Noobie Silverfish

    Messages:
    16
    Thanks, it worked!
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    PHP:
    $inventory->firstEmpty() === -1
     
  5. Noobie

    Noobie Silverfish

    Messages:
    16
    is there a way to remove only one of a specified item from the hand of player and not all?
     
  6. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    $item $player->getInventory()->getItemInHand();
    $item->setCount($item->getCount() - 1);
    $player->getInventory()->setItemInHand($item);
    next time open a new thread :p
     
    Noobie likes this.
  7. Noobie

    Noobie Silverfish

    Messages:
    16
    Damn, thanks dude! @Aviv
     
  8. Aviv

    Aviv Baby Zombie

    Messages:
    156
  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.