WorldThingDamaged

From ZDoom Wiki
Jump to navigation Jump to search

StaticEventHandler

void WorldThingDamaged (WorldEvent e)

Usage

An event handler virtual function that is called when an actor is damaged. Will not be called if the actor was attacked but didn't receive any damage because of unique protection effects or similar.

Notes:

  • This event is called after the damage has been dealt. As such, it cannot be used to override damage. For that, see DamageMobj (called on the actor itself) and ModifyDamage (called on items in the actor's possession).
  • This event is also called when an actor is killed, alongside WorldThingDied. To check if the actor actually died to this instanceof damage, check e.thing.health <= 0.

Passed values

This event gets a pointer to the WorldEvent struct and can read the following from it by preceding the value with e.:

  • Actor Inflictor
The actor dealing the damage. This is a projectile or a puff if one was used. For monster melee attacks this is the same as the source.
  • Actor DamageSource
The actor responsible for the inflictor. This is the actor who actually performed the attack. Can be null if the damage is dealt without a source, for example by a damaging floor.
  • int Damage
The amount of damage that was dealt (this is the final amount of damage, after all randomization, factors and other special rules have been applied).
  • Name DamageType
The damage type applied to the attack. (By default, regular attacks use 'Normal', and hitscan attacks use 'Hitscan'.)
  • int DamageFlags
The damage flags that were applied to the attack:
  • DMG_NO_ARMOR - The attack doesn't call AbsorbDamage on any of the victim's inventory items.
  • DMG_NO_PAIN - The attack does not cause the victim to enter their Pain state sequence.
  • DMG_INFLICTOR_IS_PUFF - Used by ApplyKickback to determine whether the origin should be the source (if the flag is set) or the inflictor. Automatically set by hitscan attacks.
  • DMG_THRUSTLESS - The attack doesn't call ApplyKickback on the victim.
  • DMG_FORCED - The attack ignores all damage negation flags/properties the victim has, such as NODAMAGE, and doesn't call special damage functions e.g. TakeSpecialDamage. Players with the NODAMAGE flag, god2, or buddha2 cheats are immune due to potential abuse.
  • DMG_NO_FACTOR - The attack doesn't apply the victim's damage factors.
  • DMG_PLAYERATTACK - Set if the attack came from a hitscan weapon fired by a player.
  • DMG_FOILINVUL - The attack ignores the INVULNERABLE flag if the victim has it set.
  • DMG_FOILBUDDHA - The attack ignores the BUDDHA flag if the victim has it set.
  • DMG_NO_PROTECT - The attack doesn't call ModifyDamage or AbsorbDamage on any of the victim's inventory items.
  • DMG_NO_ENHANCE - The attack doesn't call ModifyDamage on any of the source's inventory items.
  • DMG_USEANGLE - The attack uses use the angle parameter when applying kickback instead of having ApplyKickback calculate the angle from the origin of the attack.
  • DMG_EXPLOSION - The attack is marked as splash damage from an explosion. This is set automatically if the damage came from an explosive projectile.
  • double DamageAngle
The absolute angle from which the attack came. Is portal-aware (Verification needed)

Examples

This event handler simply prints a message whenever an actor is damaged, and will append " and died" at the end if it was also killed:

class MyEventHandler : EventHandler
{
  override void WorldThingDamaged(WorldEvent e)
  {
    Console.Printf("%s was damaged by %s for %d damage%s",
      e.thing.GetTag(),
      e.DamageSource? e.DamageSource.GetTag() : "something",
      e.Damage,
      e.thing.health <= 0? " and died" : "");
  }
}

(See Console and GetTag)

See also