Hello people of PocketMine, Just a quick one, I'm trying to add an item to all the players inventories in a certain world. I have this so far but its giving me problems. PHP: foreach($this->getServer()->getLevelByName($world)->getPlayers() as $p){ $p->getInventory()->addItem($datavalue, $ammount);} The variable $world is declared and works as I tried sending a message to everyone and that worked. Maybe my syntax is messed up or I'm using the wrong functions. Any feedback is appreciated! -Calrizer
Inventory::addItem parameter is a Item Array. Try using this code. PHP: $items = [ Item::get($id, $data, $amount), Item::get($id, $data, $amount)];foreach($this->getServer()->getLevelByName($world)->getPlayers() as $p){ $p->getInventory()->addItem($items);} For further problem like this you should check out the docs
I've implemented it now but I'm getting some Class not found errors. I've used: PHP: use pocketmine\Player;use pocketmine\inventory\Inventory;use pocketmine\Server; Do I need any others?