Classes:HealthPickup

From ZDoom Wiki
Jump to navigation Jump to search


Note: Wait! Stop! You do not need to copy this actor's code into your project! Here's why:
  1. This actor is already defined in GZDoom, there's no reason to define it again.
  2. In fact, trying to define an actor with the same name will cause an error (because it already exists).
  3. If you want to make your own version of this actor, use inheritance.
  4. Definitions for existing actors are put on the wiki for reference purpose only.
Health pickup
Actor type Internal Game MiniZDoomLogoIcon.png (ZDoom)
DoomEd Number None Class Name HealthPickup


Classes: InventoryHealthPickup
 →ArtiHealth
 →ArtiSuperHealth
 →MedicalKit
 →MedPatch
 →SurgeryKit

HealthPickups are items that are placed in the inventory and give some health when activated. The base class HealthPickup is never used directly. It is always the base class for predefined items (like Heretic's Quartz Flask or for items defined in DECORATE.

The maximum amount of health that can be given with a HealthPickup is the current default maximum health which normally is 100.


Using in ZScript and DECORATE

HealthPickups use the basic Inventory properties to define their behavior as inventory items. The only new information they require is the amount of health they give. For this they use the standard health actor property.

Additional properties

  • HealthPickup.AutoUse value
Determines whether (and how) the item is set to be automatically used when the player's health drops below a certain point.
The following values are accepted:
0 - Item will never be auto-used.
1 - Item will be automatically used when the player would die from damage taken, but only if the currently-selected skill level has the "autousehealth" flag set. (Like the Quartz Flask from Heretic/Hexen)
2 - Item will be automatically used when the player would die from damage taken, but only if the currently-selected skill level has the "autousehealth" flag set or during a deathmatch game. (Like the Mystic Urn from Heretic/Hexen)
3 - Item is auto-used when the player drops below 50% health; if the player has more than 1 such item, they will continue to be consumed until the player is over 50% health. However, if damage takes the player below 0% health, this will not save them from death. (Like Strife's small health items).

Examples

class MedKit : HealthPickup
{
  Default
  {
    Health 25;
    Inventory.MaxAmount 15;
    Inventory.Icon "I_MDKT";
    Inventory.PickupMessage "You picked up the Medkit."; // This is an example. It's recommended to use LANGUAGE for player-facing strings.
    +COUNTITEM
  }
  States
  {
  Spawn:
    MEDK A -1;
    stop;
  }
}
class MedPatch : HealthPickup
{
  Default
  {
    Health 10;
    HealthPickup.Autouse 3;
    Inventory.MaxAmount 20;
    Inventory.Icon "I_STMP";
    Inventory.PickupMessage "You picked up the Med patch."; // This is an example. It's recommended to use LANGUAGE for player-facing strings.
  }
  States
  {
  Spawn:
    STMP 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 HealthPickup : Inventory
{
	int autousemode;

	property AutoUse: autousemode;

	Default
	{
		Inventory.DefMaxAmount;
		+INVENTORY.INVBAR
		+INVENTORY.ISHEALTH
	}
	
	//===========================================================================
	//
	// CreateCopy
	//
	//===========================================================================

	override Inventory CreateCopy (Actor other)
	{
		Inventory copy = Super.CreateCopy (other);
		copy.health = health;
		return copy;
	}

	//===========================================================================
	//
	// CreateTossable
	//
	//===========================================================================

	override Inventory CreateTossable (int amount)
	{
		Inventory copy = Super.CreateTossable (-1);
		if (copy != NULL)
		{
			copy.health = health;
		}
		return copy;
	}

	//===========================================================================
	//
	// HandlePickup
	//
	//===========================================================================

	override bool HandlePickup (Inventory item)
	{
		// HealthPickups that are the same type but have different health amounts
		// do not count as the same item.
		if (item.health == health)
		{
			return Super.HandlePickup (item);
		}
		return false;
	}

	//===========================================================================
	//
	// Use
	//
	//===========================================================================

	override bool Use (bool pickup)
	{
		return Owner.GiveBody (health, 0);
	}

	
}

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 HealthPickup : Inventory native 
{
  Inventory.DefMaxAmount
  +INVENTORY.INVBAR
}