Classes:HealthPickup

From ZDoom Wiki
(Redirected from HealthPickup)
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 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
}