Hook

This overrides garry’s default hook system.  We need this better hook system for any serious development.  We’re implementing hook priorities. hook.Add() now takes an additional parameter of type number between -20 and 20.  0 is default (so we remain backwards compatible).  -20 and 20 are read only (ignores returned values).  Hooks are called in order from -20 on up.

Summary
HookThis overrides garry’s default hook system.
Functions
hook.GetTableThe table filled with all the hooks in a format that is backwards compatible with garry’s.
hook.AddOur new and improved hook.Add function.
hook.Remove
hook.CallNormally, you don’t want to call this directly.
hook.getCurrentHooksReturns the hooks that are currently processing, if any.
hook.isInHookReturns true if the specified hook is currently processing

Functions

hook.GetTable

Returns

The table filled with all the hooks in a format that is backwards compatible with garry’s.

hook.Add

Our new and improved hook.Add function.  Read the file description for more information on how the hook priorities work.

Parameters

event_nameThe name of the event (IE “PlayerInitialSpawn”).
nameThe unique name of your hook.  This is only so that if the file is reloaded, it can be unhooked (or you can unhook it yourself).
funcThe function callback to call
priority(Optional, defaults to 0) Priority from -20 to 20.  Remember that -20 and 20 are read-only.

hook.Remove

Parameters

event_nameThe name of the event (IE “PlayerInitialSpawn”).
nameThe unique name of your hook.  Use the same name you used in hook.Add()

hook.Call

Normally, you don’t want to call this directly.  Use gamemode.Call() instead.

Parameters

nameThe name of the event
gmThe gamemode table
...Any other params to pass

hook.getCurrentHooks

Returns the hooks that are currently processing, if any.

Returns

A table of the current hooks that are processing, starting with the ones that started first.  The table is empty if no hooks are currently executing.

Revisions

v2.40Initial.

hook.isInHook

Returns true if the specified hook is currently processing

Parameters

nameThe name of the hook to check

Returns

true if the hook is executing, false otherwise

Revisions

v2.40Initial.
Close