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

Removing items will names

Discussion in 'Development' started by Teamblocket, May 14, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    hey , how can i remove an item with a custom name? heres my code i was using but it deletes the entire stack of items , i only want one to get removed from the entire stack.
    PHP:
                             foreach($player->getInventory()->getContents() as $item) {
                      if(
    $item->getId() === 340 and $item->getCustomName() === "CrateKey") {
                      
    $item->setCount(1);
                      
    $player->getInventory()->removeItem($item);
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    if($item->getId() === 340 and $item->getCustomName() === "CrateKey"$item->setCount($item->getCount() - 1);
     
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    thx , just to save time , how can i create an array like $names = [1 => "name", 2 => "name"]; then make it were the number is the id(1 for example) and the following is the item names.
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Code:
    $arr[1] = "string"
    :facepalm:
     
  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.