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

Solved setDamage(0) not working

Discussion in 'Development' started by Jose Antonio, May 26, 2017.

  1. Jose Antonio

    Jose Antonio Spider

    Messages:
    13
    Hello,
    This piece of code isn't working:
    PHP:
    $sender->getInventory()->getItemInHand()->setDamage(0);
                
    $sender->sendMessage("Item damage was set to 0 (tool fixed)";
    It doesn't set the sender's hand item damage to 0...
    What am I doing wrong?
     
  2. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    Try this:
    Code:
    $sender->getInventory()->setItemInHand($sender->getInventory()->getItemInHand()->setDamage(0));
    $sender->sendMessage("Item damage was set to 0 (tool fixed)";
     
  3. Jose Antonio

    Jose Antonio Spider

    Messages:
    13
    Argument 1 passed to pocketmine\inventory\PlayerInventory::setItemInHand() must be an instance of pocketmine\item\Item, null given, called in etc/etc.
     
  4. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    PHP:
    $item $sender->getInventory()->getItemInHand();
    $item->setDamage(0);
    $sender->getInventory()->setItemInHand($item);
    $sender->sendMessage("Item damage was set to 0 (tool fixed)";
     
  5. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    When modifying damage values you may need to resend the inventory contents to the player for the changes to become visible. $player->getInventory()->sendContents($player);
     
    Teamblocket and Muqsit like this.
  6. Jose Antonio

    Jose Antonio Spider

    Messages:
    13
    Thank you , it worked
    @ImagicalGamer thanks for the explanation

    In brief words
    @MCPEPIG thank for the code
    @ImagicalGamer thank for the explanation
     
  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.