Classes:Health

From ZDoom Wiki
Jump to navigation Jump to search
Note: Wait! Stop! Before you copy this actor's definition into your mod, remember the following things:
  1. You do NOT need to copy that actor, since it is already defined.
  2. In fact, it's not just useless, it will cause problems.
  3. If you want to modify it, or use a modified version, using inheritance is the way to go.
  4. The actor definitions here are put on the wiki for reference purpose only. Learn from them, don't copy them.
Health
Actor type Internal Game MiniZDoomLogoIcon.png (ZDoom)
DoomEd Number None Class Name Health


Classes: InventoryHealth
 →CrystalVial
 →HealthBonus
 →Medikit
 →MegasphereHealth
 →Soulsphere
 →Stimpack

A Health item adds a certain amount to the player's health points. Items of this type are always effective when picked up. They cannot be placed in the inventory; to have health items in inventory, use HealthPickup. Health is never used directly. This class is only used as a base class for predefined items (like Doom's Stimpack or for items defined in ZScript/DECORATE.


Using in ZScript and DECORATE

Health items support all the basic Inventory properties. However, they use a few of them differently:

  • Inventory.Amount value
Sets the amount of health this item gives when picked up.
  • Inventory.MaxAmount value
Sets the maximum amount of health you can get with this item. If this is greater than 0, the maximum health points gain is added to this to determine the final maximum amount.

In addition they define one new property:

  • Health.LowMessage value, message
When pickupper's health is lower than value, the pickup message is set to message.

Examples

class Whiskey : Health
{
  Default
  {
    Inventory.PickupMessage "You drank some booze.";  // This is an example. It's recommended to use LANGUAGE for player-facing strings.
    Inventory.Amount 5;
    Inventory.MaxAmount 200;
    +COUNTITEM //means that the item counts toward item percentage
  }
  States
  {
  Spawn:
    RWHI A -1;
    Stop;
  }
}


class DogFood : Health 10575
{
  Default
  {
    Inventory.PickupMessage "Ate some dog food. Woof!";  // This is an example. It's recommended to use LANGUAGE for player-facing strings.
    Inventory.PickupSound "dog/sight";
    Inventory.Amount 4;
    Inventory.MaxAmount 200;
    +COUNTITEM //means that the item counts toward item percentage
    +INVENTORY.ALWAYSPICKUP //means the item will be always picked up, even if the actor is already at max health
  }
  States
  {
  Spawn:
    AWI1 A -1;
    Stop;
  }
}

ZScript definition

Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub.
class Health : Inventory
{
	transient int PrevHealth;
	meta int LowHealth;
	meta String LowHealthMessage;
	
	property LowMessage: LowHealth, LowHealthMessage;
	
	Default
	{
		+INVENTORY.ISHEALTH
		Inventory.Amount 1;
		Inventory.MaxAmount 0;
		Inventory.PickupSound "misc/health_pkup";
	}
	
	//===========================================================================
	//
	// AHealth :: PickupMessage
	//
	//===========================================================================
	override String PickupMessage ()
	{
		if (PrevHealth < LowHealth)
		{
			String message = LowHealthMessage;
			if (message.Length() != 0)
			{
				return message;
			}
		}
		return Super.PickupMessage();
	}

	//===========================================================================
	//
	// TryPickup
	//
	//===========================================================================

	override bool TryPickup (in out Actor other)
	{
		PrevHealth = other.player != NULL ? other.player.health : other.health;

		// P_GiveBody adds one new feature, applied only if it is possible to pick up negative health:
		// Negative values are treated as positive percentages, ie Amount -100 means 100% health, ignoring max amount.
		if (other.GiveBody(Amount, MaxAmount))
		{
			GoAwayAndDie();
			return true;
		}
		return false;
	}
}

DECORATE definition

Note: This is legacy code, kept for archival purposes only. DECORATE is deprecated in GZDoom and is completely superseded by ZScript. GZDoom internally uses the ZScript definition above.
ACTOR Health : Inventory native
{
  Inventory.Amount 1
  Inventory.MaxAmount 0
  Inventory.PickupSound "misc/health_pkup"
}