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

add item in slots

Comments in 'Plugin Development' started by imJayL, Dec 30, 2015.

  1. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    What is the code for that
  2. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    PHP:
    $event->getPlayer()->getInventory()->addItem(Item::get(id));
  3. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    $player->getInventory()->addItem(Item::get(ITEM::IRON_SWORD));

    It add item in inventory, how to add item in slots ??
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    It can crash clients game, so it is a very dangerous function... Kidding use this \pocketmine\inventory\PlayerInventory::setItem ($index, Item $item, $source=null)
  5. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    Ahmm. Aa i dont get it?
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    $player->getInventory()->setItem(1Item::get(Item::IRON_SWORD), $player->getInventory());
  7. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    private function giveKit(Player $player){
    // Clear inventory
    $player->getInventory()->clearAll();

    // Give sword and armor
    $player->getInventory()->addItem(Item::get(ITEM::IRON_SWORD));
    $player->getInventory()->addItem(Item::get(ITEM::BOW));
    $player->getInventory()->addItem(Item::get(ITEM::ARROW, 0, 64));
    $player->getInventory()->setItemInHand(Item::get(ITEM::IRON_SWORD), $player);


    I need to put item in slots
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $source is not an inventory.
  9. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    Noooo. Its not working :(
  10. imJayL
    Offline

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    How to put it in slot index ??
  11. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    If you mean setting items in first 9 slots in the inventory to the hotbar...
    PHP:
    for($i 0$i <= 8$i++){
            
    $inventory->setHotbarSlotIndex($i$i);
    }
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Isn't, okay what is it?
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

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

    imJayL Active Member

    Joined:
    Aug 5, 2015
    Posts:
    52
    Minecraft User:
    PHC_imJayL
    Yes thats it. But can you give an example
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    How don't you take his code as an example?
  16. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    I dont quite understand what you want... Isn't that code an example?

Share This Page

Advertisement