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

Inventory Slots

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

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys...How i can add items in different slots? So in different places i the inventory?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    Inventory::setItem($index$item);
    Last edited: Jan 23, 2016
    PEMapModder and CrazedMiner like this.
  3. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Yeah...You understand bro;P
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    addItem() accepts variadic Items.
    You meant setItem.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Woops, changed
  6. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    What I must write in "$index"? In which slot the Item should be?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $index is a slot in player inventory, usually 0-35. $item is the Item object that represents the item to set to.
    CraftYourBukkit likes this.
  8. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    yeah, okay thanks a lot!
  9. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    $event->getPlayer()->Inventory::setItem(4, 369);$event->getPlayer()->Inventory::setItem(1, 388);
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    It won't work....
  11. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Ok....I have it, but look there is an ERROR
    Code:
    Code:
    $event->getPlayer()->getInventory()->setItem(1, 388);
           $event->getPlayer()->getInventory()->setItem(4, 369);
    ERROR:
    Code:
    [20:09:04] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'McKaff_Settings v0.1.0': Argument 2 passed to pocketmine\inventory\PlayerInventory::setItem() must be an instance of pocketmine\item\Item, integer given, called in C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\plugins\McKaff_Settings\src\McKaff_Settings\Main.php on line 656 and defined on McKaff_Settings\Main
    [20:09:04] [Server thread/NOTICE]: InvalidArgumentException: "Argument 2 passed to pocketmine\inventory\PlayerInventory::setItem() must be an instance of pocketmine\item\Item, integer given, called in C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\plugins\McKaff_Settings\src\McKaff_Settings\Main.php on line 656 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/inventory/PlayerInventory" at line 209
    
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $event->getPlayer()->getInventory()->setItem(Item::get(10388));
           
    $event->getPlayer()->getInventory()->setItem(Item::get(40369));
  13. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Sorry.....
    Code:
    [21:25:45] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'McKaff_Settings v0.1.0': Argument 2 passed to pocketmine\inventory\PlayerInventory::setItem() must be an instance of pocketmine\item\Item, none given, called in C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\plugins\McKaff_Settings\src\McKaff_Settings\Main.php on line 656 and defined on McKaff_Settings\Main
    [21:25:45] [Server thread/NOTICE]: InvalidArgumentException: "Argument 2 passed to pocketmine\inventory\PlayerInventory::setItem() must be an instance of pocketmine\item\Item, none given, called in C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\plugins\McKaff_Settings\src\McKaff_Settings\Main.php on line 656 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/inventory/PlayerInventory" at line 209
    
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  15. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I recommend you to analyze the error message yourself. That way, you can ask with more information.
    PEMapModder likes this.

Share This Page

Advertisement