Search docs
Search guides, modules and symbols
Modules

Docs / API / Modules / damage

Damage

Players & world

@s2script/sdk/damage

Borrowed DamageInfo view of a live damage event (throws "expired borrowed view" after the synchronous callback). Subscribe with SDKHook (OnTakeDamage / OnTakeDamagePost), provided by the selected game package. Post assignment of damage is ignored.

Import

import { DamageInfo } from "@s2script/sdk/damage";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

interface
DamageInfo

A borrowed view of the current damage event, valid only during the synchronous OnTakeDamage or OnTakeDamagePost SDKHook callback: reading or writing it afterwards (including after an await) throws "expired borrowed view". Returning HookResult.Handled/Stop from OnTakeDamage blocks the hit by setting damage to 0 after every handler ran; the engine's damage function still runs.

import type { DamageInfo } from "@s2script/sdk";
function onTakeDamage(info: DamageInfo) { info.damage = info.damage / 2; }
damage: number
— The damage amount (m_flDamage). On the pre-hook, assigning MODIFIES the damage the engine applies (later handlers see it); set to 0 to block. A non-finite value is refused (the damage keeps its prior value). On OnTakeDamagePost, assignment is ignored (the original already ran).
readonly damageType: number
— The damage-type bit flags (m_bitsDamageType).
readonly attacker: EntityRef | null
— The attacking entity (m_hAttacker), or null if none/stale.
readonly inflictor: EntityRef | null
— The inflicting entity (m_hInflictor), or null if none/stale.
readonly victim: EntityRef | null
— The victim — the entity taking damage (the hooked this), or null if stale.
Back to modules All packages