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 an actor receives. It is called when an actor is damaged. There are two modes of operations for this function: active and passive. The difference between the two modes is whose item that manipulates the damage. In active, the damage manipulator is the item of the damage source (the actor which is responsible for the damage), while in passive, it is the damaged actor's item. When an actor is damaged, the function is called twice: first in active mode and then in passive mode. The function is not called if the damage is zero or less, and in the case the mode is passive, it is also not called 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, 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