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

Solved Add name to give item ?

Discussion in 'Development' started by Matrox, Aug 6, 2018.

  1. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Hello I am a beginner in Pocketmine code and I would like to know how to make a custom name to give the player object ?
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I assume you mean to give a player a custom named item.
    You'd start by creating an item using the ItemFactory::get() method, or by using the older method, Item::get(). After you have your Item object, you can use Item->setCustomName(), then give it to the player. If you don't care about what I just said, or still don't understand, just import ItemFactory and use this:
    PHP:
     /** @Player $player */
     
    $item ItemFactory::get(364 /* Steak ID, I think? *//*Item Damage/meta */1/* Count*/);
     
    $item->setCustomName("Super Steak");
     
    $player->getInventory()->addItem($item);
    There are more parameters you can use for creating the Item object, but this method is a bit more friendly to newer developers.
     
    Muqsit likes this.
  3. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Please make à exemple please :/
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I did give an example, it's the code I posted. If you don't know what to do with it, then there are other things you need to learn about first, such as PHP basics and how to utilize the PMMP API.
     
  5. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Tanks
     

    Attached Files:

  6. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    And add anchant ??
     
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You can find most of this if you search for it, but here's an example from @Muqsit.
     
    Muqsit 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.