GiveBody

From ZDoom Wiki
Jump to navigation Jump to search

bool GiveBody (int num [, int max])

Usage

Heals the calling actor. This function does nothing if the actor is dead.

Parameters

  • num: the amount by which to heal, which is in the range of -65536 and 65536. If this is a negative value, it acts as a percentage by which the actor's health is set to if its health as a percentage is below that value. If it is positive, the actor's health is increased by that value; in this case, the HealthFactor skill property is taken into account when determining the final amount, but only if the actor to heal is a player. If the final amount results in less than 1, it is set to 1.
  • max: the maximum value the actor's health can reach when healed. This is only relevant if the actor to heal is a player actor and num is positive. If this is 0, the actor is healed up to its maximum health, otherwise if it is positive, it is healed up to the sum of that value and the maximum health gain the actor may have, disregarding its maximum health. Non-player actors are healed up to their spawn health, and as such, this parameter is ignored for them. Default is 0.
    • Important note: if GiveBody is used on the player and their bonushealth property was modified (by an item like MaxHealth), the bonushealth value will be added to the second argument value. So, for example, if player.bonushealth is 50, and you want to increase player's current health to 150, you need to use GiveBody(150,100), not GiveBody(150,150), because 50 will be added to the 2nd argument.

Return value

Returns true if the actor is successfully healed, otherwise it returns false.

Examples

Assuming the player's maximum health is 200, this item sets their health to 50 points (which equals to 25% of their maximum health) upon pickup, but only if it is lower than that. If it is equal or higher, healing fails, and thus the item is not picked up.

class HealthPack : Inventory
{
    Default
    {
        Inventory.PickupMessage "Picked up a health pack.";
    }

    override bool TryPickup (in out Actor toucher)
    {
        if (toucher.GiveBody(-25))
        {
            GoAwayAndDie();
            return true;
        }

        return false;
    }

    States
    {
    Spawn:
        STIM A -1;
        Stop;
    }
}