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

SetCustomName() on addItem()

Discussion in 'Development' started by Driesboy, May 24, 2017.

  1. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
    Hello,

    How to add SetCustomName() on addItem()?

    PHP:
    $p->getInventory()->addItem(Item::get(261,0,1));
     
  2. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    PHP:
    $p->getInventory()->addItem(Item::get(261,0,1)->setCustomName("name"));
     
  3. Michael

    Michael Baby Zombie

    Messages:
    113
    GitHub:
    michaelm04
    As SuperMaXAleX said^

    Just for reference in the future since it seems your new to PMMP API PlayerInventory/BaseInventory class functions such as addItem() removeItem(), etc, the parameter is anything that's instanceof Item.
    So you can create a variable then construct an Item as the value using
    PHP:
    $item Item::get({item_id}, {item_damage}, {item_count});
    Then once you have the variable holding the value of that Item instance, you can run any of the functions under Item::class, such as setCustomName(), addEnchantment(), etc.
    Then add the $item under the functions listed above, addItem(), removeItem(), etc.
    PHP:
    $player->getInventory()->addItem($item);
     
    corytortoise and moska like this.
  4. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
     
  5. FairSYS

    FairSYS Spider

    Messages:
    6
    GitHub:
    Nada
    You can use : $item = Item::get(276, 0, 1);
    $item->setCustomName("hauhauahu");
     
  6. DayKoala

    DayKoala Silverfish

    Messages:
    22
    GitHub:
    daykoala
    PHP:
    $item Item::get(1,0,1);
    $item->setCustomName("The\nMagic\nStone");
    $player->getInventory()->addItem($item);
     
    jasonwynn10 likes this.
  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.