Skip to main content

Damage

Namespace: DeadworksManaged.Api

Intercept, modify, and apply damage to entities.

OnTakeDamage Hook

Override in your plugin to intercept all damage on the server:

public override HookResult OnTakeDamage(TakeDamageEvent ev)
{
// ev.Entity — the entity taking damage
// ev.DamageInfo — full damage descriptor

// Block damage to the Patrons
if (ev.Entity.DesignerName == "npc_boss_tier3")
return HookResult.Stop;

return HookResult.Continue;
}

TakeDamageEvent

PropertyTypeDescription
EntityCBaseEntityThe entity taking damage
InfoCTakeDamageInfoFull damage descriptor (attacker, inflictor, amount, flags)

Applying Damage

Simple: Hurt()

Convenience wrapper for applying damage. All parameters except damage are optional:

// Minimal — damage is self-inflicted with no attacker credit
pawn.Hurt(50f);

// Attacker credited — shows in the kill feed
target.Hurt(100f, attacker: shooter);

// Full control
entity.Hurt(
100f, // damage amount
attacker, // attacking entity (defaults to the victim if omitted)
inflictor, // entity that caused damage (weapon, projectile)
ability, // ability entity
damageType: 0 // DamageTypes_t bits (int)
);

If attacker is null, the framework treats it as self-damage (attacker = victim).

Advanced: CTakeDamageInfo

For full control, create a CTakeDamageInfo:

using var damageInfo = new CTakeDamageInfo(
damage: 200f,
attacker: attackerEntity,
inflictor: inflictorEntity,
ability: abilityEntity,
damageType: 0
);

targetEntity.TakeDamage(damageInfo);
// damageInfo is disposed automatically via using

CTakeDamageInfo

Method/ConstructorDescription
new CTakeDamageInfo(float damage, CBaseEntity? attacker, CBaseEntity? inflictor, CBaseEntity? ability, int damageType)Create new (must dispose)
FromExisting(nint)Wrap existing pointer (non-owning, e.g. from hook) — internal

Important: When creating via constructor, always use using or call Dispose().

Properties (Verified)

PropertyTypeDescription
DamagefloatDamage amount (get/set)
TotalledDamagefloatTotalled damage (mirrors Damage on creation)
DamageFlagsTakeDamageFlagsDamage flags (get/set)
DamageTypeintDamage type bits (get/set)
AttackerCBaseEntity?The attacking entity
InflictorCBaseEntity?The inflictor entity
AbilityCBaseEntity?The ability entity
OriginatorCBaseEntity?The originator (usually null on creation)

TakeDamageFlags_t

Bit flags that modify how damage is applied (uint64):

FlagValueDescription
DFLAG_NONE0No flags
DFLAG_SUPPRESS_HEALTH_CHANGES1Don't change health
DFLAG_SUPPRESS_PHYSICS_FORCE2No knockback
DFLAG_SUPPRESS_EFFECTS4No visual effects
DFLAG_PREVENT_DEATH8Cannot kill (clamp to 1HP)
DFLAG_FORCE_DEATH16Guarantee kill
DFLAG_ALWAYS_GIB32Always gib on death
DFLAG_NEVER_GIB64Never gib on death
DFLAG_SUPPRESS_DAMAGE_MODIFICATION256Ignore armor/resist
DFLAG_RADIUS_DMG1024Area/splash damage
DFLAG_ALLOW_SUICIDE262144Allow self-kill
DFLAG_SUPPRESS_KILL_CREDIT4194304No kill credit
DFLAG_SUPPRESS_DEATH_CREDIT8388608No death credit
DFLAG_HEAVY_MELEE8589934592Heavy melee hit
DFLAG_LIGHT_MELEE17179869184Light melee hit
tip

Combine DFLAG_FORCE_DEATH | DFLAG_ALLOW_SUICIDE (16 + 262144 = 262160) for guaranteed kills.

DamageTypes_t

Bit flags for damage type classification:

FlagValueDescription
DMG_GENERIC0Generic damage
DMG_BULLET2Bullet damage
DMG_SLASH4Slash/melee
DMG_BURN8Fire/burn
DMG_FALL32Fall damage
DMG_BLAST64Explosion
DMG_SHOCK256Shock/electric
DMG_HEADSHOT524288Headshot
DMG_CRIT1048576Critical hit
DMG_DOT4194304Damage over time
DMG_LETHAL16777216Lethal flag

See Also