pocketmine\Player::setHealth PHP Method

setHealth() public method

public setHealth ( $amount )
    public function setHealth($amount)
    {
        parent::setHealth($amount);
        if ($this->spawned === true) {
            $this->foodTick = 0;
            $this->getAttributeMap()->getAttribute(Attribute::HEALTH)->setMaxValue($this->getMaxHealth())->setValue($amount, true);
        }
    }

Usage Example

Example #1
0
 public static function giveExplosiveKit(Player $p)
 {
     if (!empty($p) && !empty($p->getInventory())) {
         $p->setHealth(20);
         if (!$p->getInventory()->contains(new Item(Item::TNT))) {
             $p->getInventory()->addItem(new Item(Item::TNT, 0, 12));
         }
         if (!$p->getInventory()->contains(new Item(Item::FLINT_AND_STEEL))) {
             $p->getInventory()->addItem(new Item(Item::FLINT_AND_STEEL, 0, 2));
         }
         $p->getInventory()->setItemInHand(new Item(Item::FLINT_AND_STEEL, 0, 1));
         $p->getInventory()->sendContents($p);
         $p->getInventory()->sendContents($p->getViewers());
     }
 }
All Usage Examples Of pocketmine\Player::setHealth
Player