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

how to give items with : e.g. 159:5 in code

Comments in 'Plugin Development' started by Kabluinc, Jun 24, 2016.

  1. Kabluinc
    Offline

    Kabluinc New Member

    Joined:
    Mar 2, 2016
    Posts:
    29
    Minecraft User:
    Kabluinc
    what would be the code to add an item in someone's inventory and the items would be an item with a ':' e.g. 159:5 and 159:14

    and how would it be possible to set these two items in the hotbar?

    for the adding, I tried

    $pl->getInventory()->addItem(new Item(159:5, 0 ,1)); but when server starts it shows unexpected ':'
  2. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    The second parameter stands for it damage value on Item::get, so the code is $player->getInventory()->addItem(Item::get(159, 5, 1));
    Last edited: Jun 24, 2016
    PaulchenHD likes this.
  3. eDroid
    Offline

    eDroid New Member

    Joined:
    Jun 26, 2016
    Posts:
    1
    Minecraft User:
    eDroidMC
    This justifys @MyNameIsTriXz answer but with what the parameters mean.

    $player->getInventory()->addItem(Item::get(ID, DAMAGE, AMOUNT));
  4. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    PHP:
    $player->getInventory()->addItem(Item::get((159),5,1);
    ((ID),DAMAGE,AMOUNT);
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    BTW, if you are thinking of getting values out of a string "123:1:1", you can use
    PHP:
    $data explode(':'"113:1:1");
    $item Item::get($data[0], $data[1], $data[2]);
    More info on the PHP manual.
    MikkiMCPE likes this.
  6. MikkiMCPE
    Offline

    MikkiMCPE Active Member

    Joined:
    May 16, 2015
    Posts:
    125
    Minecraft User:
    MikkiMC
    Coach ;);) Thx for info

Share This Page

Advertisement