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

Solved Remove 1 Item from 1 stack in players hand

Discussion in 'Help' started by NakiFx, Aug 23, 2020.

  1. NakiFx

    NakiFx Silverfish

    Messages:
    17
    GitHub:
    nakifx
    Hello, I want to remove 1 item from 1 stack in players hand
    Code :
    PHP:
    $player->getInventory()->removeItem($player->getInventory()->getItemInHand());
    But this code will remove 1 stack in players hand
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    PHP:
    public function Remove(Player $player) {
        
    $inv $player->getInventory();
        
    $slot $inv->getHeldItemIndex();
        return 
    $inv->setItem($slotItem::get(Item::AIR));
       }
    and use:
    $this->Remove($player);
    to remove item in player's hand
     
  3. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    or use remove instead removeItem in your code, but if you use this for remove glass in your inv, if you have 10000 blocks in your inventory this will remove all of glass blocks but if you want just remove items in hand slot, use this:
     
  4. RicardoMilos384

    RicardoMilos384 Slime

    Messages:
    82
    GitHub:
    ricardomilos384

    PHP:
    $item $player->getInventory()->getItemInHand();
    $item->setCount($item->getCount() - 1);
    $player->getInventory()->setItemInHand($item);
     
    Taco likes this.
  5. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    he can just do
    $inv->removeItem(Item here);
     
    Last edited: Aug 26, 2020
  6. RicardoMilos384

    RicardoMilos384 Slime

    Messages:
    82
    GitHub:
    ricardomilos384
    He want to reduce item not removing item
     
    Taco likes this.
  7. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    ok wait wait wait

    What the hell is going on here?????

    so for start i should say to you upgrade your knowledge in Coding & Pmmp & English bacause i think you didnt see:
    ok and his code is :
    What the hell is going on here?????
    this fucntion :
    PHP:
    $inv->removeItem(Item Id Here);
    will reduce items in player inventory @RicardoMilos384 try it then anwser tyo people and confuse them |:

    so what is it? what do you mean? what's the problem?
    removeItem will reduce item in player inv
    remove will remove all blocks in player inv
    are you kidding me? @NakiFx

    also im gonna suicide for:
    upload_2020-8-26_19-34-2.png
    o_O:facepalm::facepalm::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.