Hey guys, my last thread was about the Slots in the Inventory....But how to add Items into the Invntory Bar...?
http://docs.pocketmine.net/dc/d77/c...entory.html#a46103526e5357531d563aabd3c0a932e http://docs.pocketmine.net/dc/d77/c...entory.html#a3ae2ddba44ba8f3cc97d888662a4c301
PHP: $player->setItem($slotnumber, new Item($id, $damage, $amount));Notice that the slotcount in an inventory starts at 0, so when you want to set the first item the $slotnumber needs to be 0.
(facepunch) addItem() just adds an item to the inventory, first argument needs to be an Item object, so how can you use sometimes slot number and sometimes Item? its setItem() also use Item::get() instead
Add to Inventory bar (hotbar), PHP: $player->setItem(1, Item::get(339,0,1)); //paper$player->setHotbarSlotIndex(1,1);
Did you get Inventory? PHP: $player->getInventory()->setItem(1,Item::get(1,0,1));$player->getInventory()->setHotbarSlotIndex(1,1);
Item::get() can return items of different classes. If you, say, pass the value of `new Item()` of a functional item (e.g. buckets, sword, etc.) into certain functions, the item may end up having the same behaviour as an air item (fist). Therefore, always use Item::get() instead of new Item().
PHP: $player->getInventory()->setItem(1, Item::get(1,0,1)); $player->getInventory(setHotbarSlotIndex(1,1)); So why this didn't work? ERROR: Code: Fatal error: Call to undefined function McKaff_Settings\setHotbarSlotIndex() in C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\plugins\McKaff_Settings\src\McKaff_Settings\Main.php on line 494
Recheck code. You wrote : $player->getInventory(setHotbarSlotIndex(1,1)); Replace : $player->getInventory()->setHotbarSlotIndex(1,1); Please replace the codes, and run it.
The documentation is outdated, your better off linking people directly to the line from the PocketMine source on GitHub. I believe it's supposed to be 'facepalm' Please update your incorrect posts instead of leaving them there, if you need to add a comment in the edit say put ** edit ** or something before the comment. PHP: // BB Code is AMAZING, it makes code look pretty and minimises the space used To anyone that is annoyed or frustrated at my comments, one of them was a joke, and let's face the facts, we've all seen the same comments before and some of what I'm saying can be found in the posting Rules and Guidelines.
Hey again....Have anybody a correctly solution? Code is this: PHP: $player->getInventory()->setItem(0, Item::get(388,0,1)); $player->getInventory()->setHotbarSlotIndex(0,388); $player->getInventory()->setItem(6, Item::get(369,0,1)); $player->getInventory()->setHotbarSlotIndex(6,369); But I have the things in my inventory.....It should be in the SlotBar, not in the Inventory.. So if anyone has a correctly Solution...Please write them down..thx
PHP: Player::getInventory()->setItem(/* Inventory Index */0, /* Item */Item::get(0, 0, 0);Player::getInventory()->setHotBarSlotIndex(/* Hotbar Index */0, /* Inventory Index*/0); Here's a little function for filling the hotbar up with items PHP: public function setPlayerInv(Player $player, array $items, $invIndex = 0, $hotbarIndex = 0) { for($i = 0, $inv = $player->getInventory(), $itemCount = count($items); $i < $itemCount; $i++, $invIndex++) { $inv->setItem($invIndex, $items[$i]); if($hotbarIndex < 6) { $inv->setHotBarSlotIndex($hotbarIndex, $invIndex); $hotbarIndex++; } continue; }}