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

getContent() isn't getting all the items

Discussion in 'Facepalm' started by InspectorGadget, Mar 24, 2017.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi! I'm not sure how to make getContents() work. If anyone know who please let me know...

    My Code:

    PHP:
        public function onJoin(\pocketmine\event\player\PlayerJoinEvent $e) {
           
            
    $inv $e->getPlayer()->getInventory()->getContents();
           
                if(
    $inv === \pocketmine\item\Item::get(33801)) {
                    
    $this->getLogger()->info('no'); // helps to tell if the line gets executed
                
    }
           
        }
    Thanks
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    getContents() returns an array of the items in the inventory. If you want to check if a player has a certain item, I recommend using $inventory->contains();
     
    applqpak, corytortoise and Kyd like this.
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    If you trying to check if player has any item in inventory do @Sandertv method
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    or you can just foreach it, either ways it works
     
  5. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
  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.