ModifyDamage
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 or deals damage to another actor. 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 (a projectile or a puff). Not to be confused with source. May be null.
- source: a pointer to the actor responsible for the damage (the actor that fired the attack). In passive mode it's the actor that dealt the damage to the owner, while in active mode it's the same as owner. May be null (for example, if the damage was dealt directly from an ACS script).
- flags: holds the damage flags that are passed to the function, if any (the flags are the same as the ones used by DamageMobj). 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
This article is issued from Zdoom. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.