DamageMobj
Jump to navigation
Jump to search
virtual int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags = 0, double angle = 0)
Usage
A virtual function called by the actor whenever it takes damage. Returns the amount of damage the caller actually took from the attack.
Can be both overridden on a specific actor in order to add something to the moment they take damage, and also called on an actor directly to deal damage to them.
There are a few important things to keep in mind when overriding DamageMobj:
- If
super.DamageMobj(...)
isn't called, no damage will be dealt. Justreturn
'ing a positive value doesn't deal the damage by itself. - This function can be called multiple times per the same tic., because an actor can be damaged multiple times at once. This concerns not only attacks from different sources that hit at the same time, but also attacks from the same source, such as a shotgun blast (each pellet is a separate hitscan and thus a separate instance of damage).
- The base function call (handled in C++, not ZScript) also includes a TakeSpecialDamage call, which will modify the value that DamageMobj returns.
Parameters
- 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 source
- 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 to deal.
- Name mod
- The damage type applied to the attack. Regular attacks use 'Normal', hitscan attacks use 'Hitscan'.
- int flags
- The damage flags to use in 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 angle
- The absolute angle for thrusting enemies from the damage if DMG_USEANGLE is set.
Return value
- int - meant to inform the code about how much damage was dealt. This is purefly informative and will not deal any damage, unless
super.DamageMobj(...)
is called.
Examples
This version of the Zombieman will take no damage from projectiles:
class ZombiemanNoProjectiles : Zombieman
{
override int DamageMobj (Actor inflictor, Actor source, int damage, Name mod, int flags, double angle)
{
if (inflictor && inflictor.bMISSILE)
{
return 0;
}
return super.DamageMobj(inflictor, source, damage, mod, flags, angle);
}
}
Note, similar behavior can be achieved with the NONSHOOTABLE flag, but that will completely disable collision with projectiles, while this override disables damage.