SDKHooks

From AlliedModders Wiki
Revision as of 06:59, 7 September 2025 by Luki1412 (talk | contribs) (Added other hooks)
Jump to: navigation, search

Introduction

SDKHooks was previously an external extension to Sourcemod. It was rolled in Sourcemod 1.5 and it does not need to be manually installed anymore.

Hooks

Some information on various hooks below:

SDKHook_Blocked

SDKHook_BlockedPost

SDKHook_CanBeAutobalanced

SDKHook_EndTouch

SDKHook_EndTouchPost

SDKHook_FireBulletsPost

SDKHook_GetMaxHealth

 (ep2v and later)

SDKHook_GroundEntChangedPost

SDKHook_OnTakeDamage

inflictor (3rd argument) is the entity that inflicts the damage. If a player directly damages another, inflictor should be equal to the attacking player id. An example of an indirect damage would be a grenade.

SDKHook_OnTakeDamagePost

SDKHook_OnTakeDamageAlive

This hook works in a similar way to SDKHook_OnTakeDamage but it gives the actual, calculated damage amount done to the player. The pre-hook will fire after an OnTakeDamage pre-hook, and the post-hook will fire before an OnTakeDamage post-hook. The health is subtracted in between pre and post unless the hook is blocked. PR 149

OnTakeDamageAlive is also only called for players.

SDKHook_OnTakeDamageAlivePost

SDKHook_PreThink

SDKHook_PreThinkPost

SDKHook_PostThink

SDKHook_PostThinkPost

SDKHook_Reload

SDKHook_ReloadPost

SDKHook_SetTransmit

SDKHook_ShouldCollide

SDKHook_Spawn

SDKHook_SpawnPost

SDKHook_StartTouch

SDKHook_StartTouchPost

SDKHook_Think

SDKHook_ThinkPost

SDKHook_Touch

SDKHook_TouchPost

SDKHook_TraceAttack

SDKHook_TraceAttackPost

SDKHook_Use

SDKHook_UsePost

SDKHook_VPhysicsUpdate

SDKHook_VPhysicsUpdatePost

SDKHook_WeaponCanSwitchTo

SDKHook_WeaponCanSwitchToPost

SDKHook_WeaponCanUse

SDKHook_WeaponCanUsePost

SDKHook_WeaponDrop

SDKHook_WeaponDropPost

SDKHook_WeaponEquip

SDKHook_WeaponEquipPost

SDKHook_WeaponSwitch

SDKHook_WeaponSwitchPost

Under CSS

Non-regular cases for SDKHook_OnTakeDamage

In the scenario where a player throw a grenade to another player then quickly disconnect, the attacker (2nd argument) will become the inflictor (3rd argument).

In the scenario where a player fall; the attacker, which is also the inflictor, will be 0 (the world).

In the scenario where a terrorist plants the bomb, when the bomb explodes, the attacker (2nd argument) will be the same as the inflictor (3rd argument) which will have the Classname "planted_c4".

Some damage types

A normal HEGrenade and the C4 inflict damage of type DMG_BLAST.

A fall inflicts damage of type DMG_FALL.

A grenade impact (for instance a flash hitting a teammate) will inflict damage of type DMG_CLUB.

A normal gun bullet and the knife will inflict damage of type (DMG_BULLET | DMG_NEVERGIB) (non-headshot) or (DMG_BULLET | DMG_NEVERGIB | (1 << 30) ) (headshot).

A single attack can trigger many SDKHook_OnTakeDamage; when a gun throws pullets for instance (shotgun and glock in burst-mode notably).


(Regarding SM/Admin damaged; maybe place this is another section if someone can be sure that this would occur on all mods)

sm_slap does not trigger SDKHook_OnTakeDamage.

sm_burn will trigger two different callback : an entity with the classname "entityflame" will deal once 0 damage of type DMG_BURN and once 1 damage of type (DMG_BURN | DMG_DIRECT) every tick.

Regarding SDKHook_OnTakeDamage and SDKHook_OnTakeDamageAlive

SDKHook_OnTakeDamage/Post is triggered when hitting a teammate with mp_friendlyfire 0 (except in TF2), but not SDKHook_OnTakeDamageAlive.

Under TF2

Under TF2, the SDKHook_OnTakeDamage hook isn't 100% accurate, it's damage parameter is the weapon's base damage. the DMG_CRIT flag is for both crits and minicrits. Weapon spread and minicrit/crit damage is calculated after this call (in SDKHook_OnTakeDamageAlive/Post).

Some damage types

Shotgun = DMG_BUCKSHOT | DMG_SLOWBURN

Rocket Launcher = DMG_SLOWBURN | DMG_RADIATION | DMG_BLAST

If a crit, |= DMG_CRIT