Search docs
Search guides, modules and symbols
Modules

Docs / API / Modules / sdkhooks

SDKHooks

Players & world

@s2script/sdk/sdkhooks

Per-entity SDKHook / SDKUnhook (SourceMod-shaped). OnTakeDamage / OnTakeDamagePost; SetTransmit AND-merges with Transmit.setVisibleTo; lifecycle virtuals (Spawn, Think, Use, …); Weapon* / Reload.

Import

import { UseTypeValue } from "@s2script/sdk/sdkhooks";

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.

type
UseTypeValue

CBaseEntity::Use use-type (USE_OFF / USE_ON / USE_SET / USE_TOGGLE).

const
UseType

CBaseEntity::Use use-type constants (wiki USE_*).

readonly Off: 0
— USE_OFF — turn off.
readonly On: 1
— USE_ON — turn on.
readonly Set: 2
— USE_SET — set to value.
readonly Toggle: 3
— USE_TOGGLE — toggle.
const
SDKHookType

Shipped SDKHook types. Wiki names without the SDKHook_ prefix. A wiki name whose engine backing failed or is absent returns false from SDKHook (does not throw). A string that is not a member here throws.

readonly OnTakeDamage: "OnTakeDamage"
— Pre-apply damage, provided by the selected game package (CS2: CBaseEntity::TakeDamageOld). Mutate DamageInfo.damage in place. SDKHook returns false when no game package provides damage hooks.
readonly SetTransmit: "SetTransmit"
— CheckTransmit mux (wiki SDKHook_SetTransmit). Handled / Stop hide this entity from this viewer. AND-merge with Transmit.setVisibleTo: either API can hide; SetTransmit cannot un-hide a native mask clear. There is no SetTransmitPost.
readonly StartTouch: "StartTouch"
— CBaseEntity::StartTouch pre. Handled / Stop skip the original virtual.
readonly Touch: "Touch"
— CBaseEntity::Touch pre. Handled / Stop skip the original virtual.
readonly EndTouch: "EndTouch"
— CBaseEntity::EndTouch pre. Handled / Stop skip the original virtual.
readonly Blocked: "Blocked"
— CBaseEntity::Blocked pre. Handled / Stop skip the original virtual.
readonly StartTouchPost: "StartTouchPost"
— StartTouch post. Return is ignored.
readonly TouchPost: "TouchPost"
— Touch post. Return is ignored.
readonly EndTouchPost: "EndTouchPost"
— EndTouch post. Return is ignored.
readonly BlockedPost: "BlockedPost"
— Blocked post. Return is ignored.
readonly Spawn: "Spawn"
— CBaseEntity::Spawn pre. Handled / Stop skip the original virtual.
readonly SpawnPost: "SpawnPost"
— Spawn post. Return is ignored.
readonly Think: "Think"
— CBaseEntity::Think pre. Handled / Stop skip the original virtual.
readonly ThinkPost: "ThinkPost"
— Think post. Return is ignored.
readonly PreThink: "PreThink"
— Player PreThink. Return is ignored.
readonly PreThinkPost: "PreThinkPost"
— PreThink post. Return is ignored.
readonly PostThink: "PostThink"
— Player PostThink. Return is ignored.
readonly PostThinkPost: "PostThinkPost"
— PostThink post. Return is ignored.
readonly Use: "Use"
— CBaseEntity::Use pre. Handled / Stop skip the original virtual.
readonly UsePost: "UsePost"
— Use post. Return is ignored.
readonly GetMaxHealth: "GetMaxHealth"
— GetMaxHealth. Mutate info.maxHealth. Handled / Stop SUPERCEDE the original.
readonly ShouldCollide: "ShouldCollide"
— ShouldCollide. Return a boolean (not HookResultValue); last defined wins.
readonly VPhysicsUpdate: "VPhysicsUpdate"
— VPhysicsUpdate. Return is ignored.
readonly VPhysicsUpdatePost: "VPhysicsUpdatePost"
— VPhysicsUpdate post. Return is ignored.
readonly GroundEntChangedPost: "GroundEntChangedPost"
— GroundEntChanged post. Return is ignored.
readonly CanBeAutobalanced: "CanBeAutobalanced"
— CanBeAutobalanced. Return a boolean (not HookResultValue); last defined wins.
readonly OnTakeDamagePost: "OnTakeDamagePost"
— Post-apply damage (after the original ran), provided by the selected game package. DamageInfo is read-only for effect; damage assignment is ignored. Return is ignored.
readonly OnTakeDamageAlive: "OnTakeDamageAlive"
— OnTakeDamageAlive pre. CS2 has no distinct function yet — SDKHook returns false.
readonly OnTakeDamageAlivePost: "OnTakeDamageAlivePost"
— OnTakeDamageAlive post. CS2 has no distinct function yet — SDKHook returns false.
readonly TraceAttack: "TraceAttack"
— TraceAttack pre (TraceAttackInfo). No distinct CS2 virtual yet — SDKHook returns false (use OnTakeDamage).
readonly TraceAttackPost: "TraceAttackPost"
— TraceAttack post. No distinct CS2 virtual yet — SDKHook returns false.
readonly FireBulletsPost: "FireBulletsPost"
— FireBulletsPost. Wiki already documents this as often absent. SDKHook returns false until a live path is found.
readonly Reload: "Reload"
— Weapon reload pre. Handled / Stop skip the original virtual. Missing VP → false.
readonly ReloadPost: "ReloadPost"
— Weapon reload post. (weapon, successful). No bool-return thunk yet — SDKHook returns false.
readonly WeaponCanUse: "WeaponCanUse"
— WeaponCanUse pre. Callback is (entity, weapon). Missing ItemServices VP → false.
readonly WeaponCanUsePost: "WeaponCanUsePost"
— WeaponCanUse post. Return is ignored. Missing VP → false.
readonly WeaponCanSwitchTo: "WeaponCanSwitchTo"
— WeaponCanSwitchTo pre. Callback is (entity, weapon). Missing VP → false.
readonly WeaponCanSwitchToPost: "WeaponCanSwitchToPost"
— WeaponCanSwitchTo post. Return is ignored. Missing VP → false.
readonly WeaponDrop: "WeaponDrop"
— WeaponDrop pre. Callback is (entity, weapon). Missing VP → false.
readonly WeaponDropPost: "WeaponDropPost"
— WeaponDrop post. Return is ignored. Missing VP → false.
readonly WeaponEquip: "WeaponEquip"
— WeaponEquip pre. Callback is (entity, weapon). Missing VP → false.
readonly WeaponEquipPost: "WeaponEquipPost"
— WeaponEquip post. Return is ignored. Missing VP → false.
readonly WeaponSwitch: "WeaponSwitch"
— WeaponSwitch pre. Callback is (entity, weapon). Missing VP → false.
readonly WeaponSwitchPost: "WeaponSwitchPost"
— WeaponSwitch post. Return is ignored. Missing VP → false.
interface
TraceAttackInfo

Block-scoped view of a TraceAttack callback. Mutate TraceAttackInfo.damage on the pre-hook. Valid only during the handler.

damage: number
— Incoming damage. Mutate in place on the pre-hook.
readonly damageType: number
— Damage type bits.
readonly ammoType: number
— Ammo type index.
readonly hitbox: number
— Hitbox index.
readonly hitgroup: number
— Hitgroup index.
readonly attacker: EntityRef | null
— Attacking entity, books-gated.
readonly inflictor: EntityRef | null
— Inflicting entity, books-gated.
readonly victim: EntityRef | null
— Victim entity, books-gated.
fn
SDKHook(entity: EntityRef | null, type: "OnTakeDamage", callback: (info: DamageInfo) => HookResultValue | void): boolean

Hook entity for type. Auto-unhooked on entity destroy and plugin unload. Not load-window-only — call from OnEntityCreated, OnPluginStart (ents already live), or any time you hold a live EntityRef. OnTakeDamage: mutate info.damage in place. No return needed. Return HookResult.Handled to zero the hit; HookResult.Stop to also skip later hooks.

Returns — true if the hook was recorded. false on null/stale entity (does not throw).

import { SDKHook, SDKHookType, Entity } from "@s2script/sdk";
import type { EntityRef, DamageInfo } from "@s2script/sdk";

export function OnPluginStart(): void {
  for (const pawn of Entity.findByClass("player")) {
    SDKHook(pawn, SDKHookType.OnTakeDamage, onTakeDamage);
  }
}
export function OnEntityCreated(entity: EntityRef | null, className: string): void {
  if (!entity || className !== "player") return;
  SDKHook(entity, SDKHookType.OnTakeDamage, onTakeDamage);
}
function onTakeDamage(info: DamageInfo) {
  info.damage /= 2;
}
fn
SDKHook(entity: EntityRef | null, type: "OnTakeDamagePost", callback: (info: DamageInfo) => void): boolean

Post-apply damage. DamageInfo reads the info after the original ran; it is valid only during the synchronous callback. Return is ignored; Handled does not zero the hit (that is the pre-hook).

fn
SDKHook(entity: EntityRef | null, type: "OnTakeDamageAlive", callback: (info: DamageInfo) => HookResultValue | void): boolean

OnTakeDamageAlive pre. No CS2 backing yet — always returns false.

fn
SDKHook(entity: EntityRef | null, type: "OnTakeDamageAlivePost", callback: (info: DamageInfo) => void): boolean

OnTakeDamageAlive post. No CS2 backing yet — always returns false.

fn
SDKHook(entity: EntityRef | null, type: "TraceAttack", callback: (info: TraceAttackInfo) => HookResultValue | void): boolean

TraceAttack pre. No distinct CS2 virtual yet — always returns false.

fn
SDKHook(entity: EntityRef | null, type: "TraceAttackPost", callback: (info: TraceAttackInfo) => void): boolean

TraceAttack post. No distinct CS2 virtual yet — always returns false.

fn
SDKHook(entity: EntityRef | null, type: "FireBulletsPost", callback: FireBulletsPostCallback): boolean

FireBulletsPost. No CS2 backing yet — always returns false.

fn
SDKHook(entity: EntityRef | null, type: "StartTouch" | "Touch" | "EndTouch" | "Blocked", callback: TouchCallback): boolean

Touch-family pre-hook. Callback is (entity, other). Omit return = Continue. Handled / Stop SUPERCEDE the original virtual (Stop also skips later callbacks).

fn
SDKHook(entity: EntityRef | null, type: "StartTouchPost" | "TouchPost" | "EndTouchPost" | "BlockedPost", callback: TouchPostCallback): boolean

Touch-family post-hook. Return is ignored; the original virtual already ran.

fn
SDKHook(entity: EntityRef | null, type: "Spawn" | "Think" | "Reload", callback: ThisCallback): boolean

Spawn / Think pre-hook. Callback is (entity). Omit return = Continue. Handled / Stop SUPERCEDE the original virtual (Stop also skips later callbacks).

fn
SDKHook(entity: EntityRef | null, type:
    | "SpawnPost"
    | "ThinkPost"
    | "PreThink"
    | "PreThinkPost"
    | "PostThink"
    | "PostThinkPost"
    | "VPhysicsUpdate"
    | "VPhysicsUpdatePost"
    | "GroundEntChangedPost", callback: ThisVoidCallback): boolean

Void this-only hooks (Posts, PreThink/PostThink, VPhysicsUpdate, GroundEntChangedPost). Return is ignored.

fn
SDKHook(entity: EntityRef | null, type: "Use", callback: UseCallback): boolean

Use pre-hook. Handled / Stop SUPERCEDE the original virtual.

fn
SDKHook(entity: EntityRef | null, type: "UsePost", callback: UsePostCallback): boolean

Use post-hook. Return is ignored.

fn
SDKHook(entity: EntityRef | null, type: "GetMaxHealth", callback: (info: { maxHealth: number }) => HookResultValue | void): boolean

GetMaxHealth. Mutate info.maxHealth in place. Handled / Stop SUPERCEDE with the new value.

fn
SDKHook(entity: EntityRef | null, type: "ShouldCollide", callback: (
    entity: EntityRef,
    collisionGroup: number,
    contentsMask: number,
    originalResult: boolean,
  ) => boolean): boolean

ShouldCollide. Return a boolean (not HookResult); last defined return wins, default original.

fn
SDKHook(entity: EntityRef | null, type: "CanBeAutobalanced", callback: (client: Client, origRet: boolean) => boolean): boolean

CanBeAutobalanced. Return a boolean (not HookResult); last defined return wins, default original. Callback is skipped when the hooked entity has no Client — never a raw slot 0.

fn
SDKHook(entity: EntityRef | null, type: "SetTransmit", callback: (entity: EntityRef, client: Client) => HookResultValue | void): boolean

SetTransmit. Callback is (entity, client). Omit return = Continue. Handled / Stop hide this entity from this viewer (AND-merge with Transmit.setVisibleTo; cannot un-hide a native mask clear). Stop also skips later SetTransmit callbacks on that pair.

fn
SDKHook(entity: EntityRef | null, type: "WeaponCanUse" | "WeaponCanSwitchTo" | "WeaponDrop" | "WeaponEquip" | "WeaponSwitch", callback: WeaponCallback): boolean

Weapon-family pre-hook. Callback is (entity, weapon). Omit return = Continue. Handled / Stop SUPERCEDE the original virtual. Missing ItemServices VP → false.

fn
SDKHook(entity: EntityRef | null, type:
    | "WeaponCanUsePost"
    | "WeaponCanSwitchToPost"
    | "WeaponDropPost"
    | "WeaponEquipPost"
    | "WeaponSwitchPost", callback: WeaponPostCallback): boolean

Weapon-family post-hook. Return is ignored. Missing VP → false.

fn
SDKHook(entity: EntityRef | null, type: "ReloadPost", callback: ReloadPostCallback): boolean

ReloadPost. Callback is (weapon, successful). No CS2 backing yet — always returns false.

fn
SDKUnhook(entity: EntityRef | null, type: "OnTakeDamage", callback: (info: DamageInfo) => HookResultValue | void): boolean

Remove one matching (entity, type, callback) hook. Callback identity is the function reference.

Returns — true if an entry was removed.

fn
SDKUnhook(entity: EntityRef | null, type: "OnTakeDamagePost", callback: (info: DamageInfo) => void): boolean

Remove an OnTakeDamagePost hook.

fn
SDKUnhook(entity: EntityRef | null, type: "OnTakeDamageAlive", callback: (info: DamageInfo) => HookResultValue | void): boolean

Remove an OnTakeDamageAlive hook.

fn
SDKUnhook(entity: EntityRef | null, type: "OnTakeDamageAlivePost", callback: (info: DamageInfo) => void): boolean

Remove an OnTakeDamageAlivePost hook.

fn
SDKUnhook(entity: EntityRef | null, type: "TraceAttack", callback: (info: TraceAttackInfo) => HookResultValue | void): boolean

Remove a TraceAttack hook.

fn
SDKUnhook(entity: EntityRef | null, type: "TraceAttackPost", callback: (info: TraceAttackInfo) => void): boolean

Remove a TraceAttackPost hook.

fn
SDKUnhook(entity: EntityRef | null, type: "FireBulletsPost", callback: FireBulletsPostCallback): boolean

Remove a FireBulletsPost hook.

fn
SDKUnhook(entity: EntityRef | null, type: "StartTouch" | "Touch" | "EndTouch" | "Blocked", callback: TouchCallback): boolean

Remove a Touch-family pre-hook.

fn
SDKUnhook(entity: EntityRef | null, type: "StartTouchPost" | "TouchPost" | "EndTouchPost" | "BlockedPost", callback: TouchPostCallback): boolean

Remove a Touch-family post-hook.

fn
SDKUnhook(entity: EntityRef | null, type: "Spawn" | "Think" | "Reload", callback: ThisCallback): boolean

Remove a Spawn / Think pre-hook.

fn
SDKUnhook(entity: EntityRef | null, type:
    | "SpawnPost"
    | "ThinkPost"
    | "PreThink"
    | "PreThinkPost"
    | "PostThink"
    | "PostThinkPost"
    | "VPhysicsUpdate"
    | "VPhysicsUpdatePost"
    | "GroundEntChangedPost", callback: ThisVoidCallback): boolean

Remove a void this-only hook.

fn
SDKUnhook(entity: EntityRef | null, type: "Use", callback: UseCallback): boolean

Remove a Use pre-hook.

fn
SDKUnhook(entity: EntityRef | null, type: "UsePost", callback: UsePostCallback): boolean

Remove a Use post-hook.

fn
SDKUnhook(entity: EntityRef | null, type: "GetMaxHealth", callback: (info: { maxHealth: number }) => HookResultValue | void): boolean

Remove a GetMaxHealth hook.

fn
SDKUnhook(entity: EntityRef | null, type: "ShouldCollide", callback: (
    entity: EntityRef,
    collisionGroup: number,
    contentsMask: number,
    originalResult: boolean,
  ) => boolean): boolean

Remove a ShouldCollide hook.

fn
SDKUnhook(entity: EntityRef | null, type: "CanBeAutobalanced", callback: (client: Client, origRet: boolean) => boolean): boolean

Remove a CanBeAutobalanced hook.

fn
SDKUnhook(entity: EntityRef | null, type: "SetTransmit", callback: (entity: EntityRef, client: Client) => HookResultValue | void): boolean

Remove a SetTransmit hook.

fn
SDKUnhook(entity: EntityRef | null, type: "WeaponCanUse" | "WeaponCanSwitchTo" | "WeaponDrop" | "WeaponEquip" | "WeaponSwitch", callback: WeaponCallback): boolean

Remove a Weapon-family pre-hook.

fn
SDKUnhook(entity: EntityRef | null, type:
    | "WeaponCanUsePost"
    | "WeaponCanSwitchToPost"
    | "WeaponDropPost"
    | "WeaponEquipPost"
    | "WeaponSwitchPost", callback: WeaponPostCallback): boolean

Remove a Weapon-family post-hook.

fn
SDKUnhook(entity: EntityRef | null, type: "ReloadPost", callback: ReloadPostCallback): boolean

Remove a ReloadPost hook.

Back to modules All packages