1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Adding Item to player inventory using id's only.

Discussion in 'Development' started by Karanpatel567, Oct 16, 2017.

  1. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Hello, I want to know how to add a item to a players inventory with id and not letters. It doesn't seem to let me do that. Can you help me please?
     
  2. Mystic30

    Mystic30 Witch

    Messages:
    52
    GitHub:
    Mystic30
    $player->getInventory()->addItem(Item::get(267, 0, 1));
     
    Last edited: Oct 16, 2017
    rektpixel likes this.
  3. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    You can use:
    PHP:
    $player->getInventory()->addItem(Item::get(35131)); // = 1 Cocoa Bean
    The first argument is the ID of the item, the second the meta/damage, the third the amount of that item.
     
    OnTheVerge, rektpixel and jasonwynn10 like this.
  4. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    STOP PUTTING TITLES AS A SIMPLE "HELP"!
    You need to put the title as something like:
    "How to I add item to inventory?"
     
  5. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Ok, but how would i check if the player has this item in his inventory and in his hand.
     
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    You can use
    PHP:
    if($player->getInventory()->getItemInHand()->getId() === 351) { // if player is holding Dye
        // do something
    }
    for that.
     
  7. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Would it matter if it had a custom name in it? Would it still work?
     
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    The item's ID will still be the same, it won't change.
     
  9. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Thanks very much
    Now everything works!
     
  10. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    Its gone. Not even there anymore. So, can't try that one on me anymore. Also, don't be "That Guy"... you're that kinda guy who says the stupid things to get people annoyed at you
     
    OnTheVerge and iiFlamiinBlaze like this.
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    First, sorry...
    Second, who removed it and why?
     
  12. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    It's been removed by a staff member, as it restricts the titles to stuff like "Help"
     
    EdwardHamHam and NickTehUnicorn like this.
  13. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Wow, the staff must have read your message really quickly.
    Please read my profile status.
     
  14. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    One more thing, how would i remove this dye with the custom name?
     
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Use:
    PHP:
    /*
     * @var Player $player
     * @var Item $item
     */
    $player->getInventory()->removeItem($item);
     
  16. Karanpatel567

    Karanpatel567 Baby Zombie

    Messages:
    115
    GitHub:
    Karanpatel567
    Ok
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.