Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Inventory Bar

Comments in 'Plugin Development' started by Marcelo234, Jan 26, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey guys, my last thread was about the Slots in the Inventory....But how to add Items into the Invntory Bar...?
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
    $player->setItem($slotnumber, new Item($id$damage$amount));

    Notice that the slotcount in an inventory starts at 0so when you want to set the first item the $slotnumber needs to be 0.
    Last edited: Jan 26, 2016
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    [​IMG] (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
    Last edited: Jan 27, 2016
    AndrewBit likes this.
  5. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Add to Inventory bar (hotbar),

    PHP:
    $player->setItem(1Item::get(339,0,1)); //paper
    $player->setHotbarSlotIndex(1,1);
  6. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Fatal error: Call to undefined method pocketmine\Player::setHotbarSlotIndex()
  7. KubixQ
    Offline

    KubixQ Active Member

    Joined:
    Sep 13, 2015
    Posts:
    85
    Minecraft User:
    KubixQ
    I don't actually know, if this is good, delete "Index" in ^^ function
  8. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    anybody know how to do this??
  9. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Did you get Inventory?
    PHP:
    $player->getInventory()->setItem(1,Item::get(1,0,1));
    $player->getInventory()->setHotbarSlotIndex(1,1);
  10. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    I once tested this function, and it worked on PocketMine 1.6dev1266 (API : 1.13.1).
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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().
    CrazedMiner and MyNameIsTriXz like this.
  12. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    PHP:
    $player->getInventory()->setItem(1Item::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
    
  13. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Recheck code.

    You wrote : $player->getInventory(setHotbarSlotIndex(1,1));
    Replace : $player->getInventory()->setHotbarSlotIndex(1,1);

    Please replace the codes, and run it.
    PEMapModder and PocketKiller like this.
  14. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    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' :p

    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.
  15. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey again....Have anybody a correctly solution?
    Code is this:
    PHP:
    $player->getInventory()->setItem(0Item::get(388,0,1));
           
    $player->getInventory()->setHotbarSlotIndex(0,388);
          
           
    $player->getInventory()->setItem(6Item::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
  16. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    Player::getInventory()->setItem(/* Inventory Index */0/* Item */Item::get(000);
    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;
        }
    }
    Last edited: Jan 28, 2016

Share This Page

Advertisement