ModifyDamage

From ZDoom Wiki
Jump to navigation Jump to search

virtual void ModifyDamage (int damage, Name damageType, out int newdamage, bool passive [, Actor inflictor [, Actor source [, int flags]]])

Usage

Allows inventory items to manipulate the damage their owner receives or deals. It is called when the owner of the item is damaged. There are two modes of operations for this function: active and passive:

  • In active the function modifies the damage dealt by the source (the owner of the item) to other actors. The function is not called if damage is zero or less.
  • In passive it modifies the damage received by the owner (with the source being whoever damaged them). It will not be called if damage is zero or less or if the damage is set up to bypass protection powerups.

Note that the function is called before AbsorbDamage, another similar function for damage manipulation.

This function's main usage is with powerups such as PowerProtection and PowerDamage, but could be used with any inventory item.

Parameters

  • damage: the damage before modification. This may not necessarily be the raw damage of the attack.
  • damageType: the damage type of the attack.
  • newdamage: the damage after modification. After the damage is modified, it is to be stored in this variable. Unmodified, this holds the same value as damage.
  • passive: the mode of operation. If it is true, the mode is passive, otherwise it is active.
  • inflictor: a pointer to the actor which caused the damage. Default is null.
  • source: a pointer to the damage source actor if the mode is passive or the damaged actor if the mode is active. Default is null.
  • flags: holds the damage flags that are passed to the function, if any. Default is 0.

Examples

An example of active mode: PowerDamage.

override void ModifyDamage (int damage, Name damageType, out int newdamage, bool passive, Actor inflictor, Actor source, int flags)
{
    if (!passive && damage > 0)
    {
        newdamage = max(1, ApplyDamageFactors(GetClass(), damageType, damage, damage * 4));

        if (Owner != null && newdamage > damage)
        {
            Owner.A_StartSound(ActiveSound, CHAN_AUTO, CHANF_DEFAULT, 1.0, ATTN_NONE);
        }
    }
}


An example of passive mode: PowerProtection.

override void ModifyDamage (int damage, Name damageType, out int newdamage, bool passive, Actor inflictor, Actor source, int flags)
{
    if (passive && damage > 0)
    {
        newdamage = max(0, ApplyDamageFactors(GetClass(), damageType, damage, damage / 4));

        if (Owner != null && newdamage < damage)
        {
            Owner.A_StartSound(ActiveSound, CHAN_AUTO, CHANF_DEFAULT, 1.0, ATTN_NONE);
        }
    }
}

See also