Search docs
Search modules and symbols
Modules

Docs / API / Modules / sdkhooks

SDKHooks

Players & world

@s2script/sdk/sdkhooks

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

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 (DispatchTraceAttack). Mutate DamageInfo.damage in place.
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.
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.

Returnstrue 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: "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", 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
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.

Returnstrue if an entry was removed.

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", 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.

Back to modules All packages

s2script — Source 2 plugin framework

GitHub