Classes:MaxHealth

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.
Maximum health
Actor type Internal Game MiniZDoomLogoIcon.png (ZDoom)
DoomEd Number None Class Name MaxHealth


Classes: InventoryHealthMaxHealth

A MaxHealth increases the maximum health of an actor by way of adding to its maximum health points gain. Only player-based actors, however, can have their maximum health increased by items of this class. It also retains its parent class's functionality of increasing current health.

MaxHealth is never used directly. This class is only used as a base class for items defined in DECORATE or ZScript.

Usage

Max health items support the same properties as health items. The following properties have extra functionality, in addition to that of the health items:

  • Inventory.Amount value
Sets the amount of maximum health points gain this item gives when picked up.
  • Inventory.MaxAmount value
Sets the maximum amount of maximum health points gain that can be reached by picking up this item. If the current maximum health points gain is at this value or above, picking up this item will have no effect on it, though the item could still be picked up to increase current health.

Examples

In addition to increasing current health, this item increases the player's maximum health by 1 point. The maximum health points gain that can be reached with this item is 200.

class VitalityBonus : MaxHealth
{
    Default
    {
        Inventory.Amount 1;
        Inventory.MaxAmount 200;
        Inventory.PickupMessage "Picked up a vitality bonus.";

        +COUNTITEM
        +INVENTORY.ALWAYSPICKUP
    }

    States
    {
    Spawn:
        BON1 ABCDCB 6;
        Loop;
    }
}

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 MaxHealth : Health
{
	//===========================================================================
	//
	// TryPickup
	//
	//===========================================================================

	override bool TryPickup (in out Actor other)
	{
		bool success = false;
		let player = PlayerPawn(other);
		if (player)
		{
			if (player.BonusHealth < MaxAmount)
			{
				player.BonusHealth = min(player.BonusHealth + Amount, MaxAmount);
				success = true;
			}
		}
		success |= Super.TryPickup(other);
		if (success) GoAwayAndDie();
		return success;
	}
}