Code: $items_count = 0; foreach($event->getPlayer()->getInventory()->getContents() as $item){ $items_count = $items_count + $item->getCount(); } $event->getPlayer()->sendMessage("You have $items_count items in your inventory"); Error: Server thread/CRITICAL Error: "Call to a member function getCount() on array" (EXCEPTION) Can't see any error. Thx for help.
There's no need of a loop for that, you can just use this: PHP: $items_count = count($event->getPlayer()->getInventory()->getContents());
That does a different thing from what the OP wants OP wanted to count the total number of items not the number of stacks The code you posted does not seem to be the one causing the error as $item will not be an array