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

Give Item API?

Comments in 'Plugin Development' started by deot, Oct 28, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hi,
    what's the code to give item by item IDs?

    $p->???(???)
  2. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    PHP:
    $p->getInventory()->addItem(new Item($id$damage$amount);
    So, basically you will add the item to the player's inventory
    So in your case, you will be able to do:
    PHP:
    $p->getInventory()->addItem(new Item(276,1);
    Sorry I understood it wrong
    Last edited: Oct 28, 2015
    deot likes this.
  3. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hmmmm.... I don't really understand that code...
    I want to give item to players by item IDs (example I want to give player a stone sword (ITEM IDs: 272))
    How can I do that?

    But the code u given to me is like a code to do: "if the item is equal to x item"
    It doesnt match my needs LOL :p
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How many times I have told you to use Item::get() instead of the Item constructor? It may have some issues with special items like buckets, and other plugins may get the item name wrongly!
    Primus and CraftYourBukkit like this.
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    so
    PHP:
    $player->getInventory()->addItem(Item::get($id$damage$count));
    //getInventory() returns PlayerInventory/Inventory object
  6. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    How about enchantment? How can I add enchantment to the given item?
  7. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    PHP:
    $item Item::get(Item::STONE_SWORD01);
    $item->addEnchantment(Enchantment::get(Enchantment::SHARPNESS));
    $pl->getInventory()->addItem($item);
    deot likes this.
  8. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Thanks! :) One last thing... xD
    Add items to hotbar? I mean the items I given will be shown in hotbar instead in inventory xD
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    pocketmine\inventory\PlayerInventory::setItem ( $index, Item $item, $source = null)
    PocketMine has nice API documentation, why you're not using it?
    PEMapModder likes this.

Share This Page

Advertisement