hook

GMod-style event system. Register named callbacks for engine events; the name lets you replace or remove your own hook later.

functionhook.Add(event, name, fn)

Registers fn for event under a unique name. Adding again with the same event + name replaces the previous callback.

ParamTypeNotes
eventstringEvent name, e.g. "OverlayElement".
namestringUnique identifier for this callback.
fnfunctionCalled with the event's arguments.
functionhook.Remove(event, name) → nil

Unregisters the callback previously added under this event + name.

ParamTypeNotes
eventstringThe event name.
namestringThe unique identifier used in hook.Add.
functionhook.Run(event, ...) → nil · alias: hook.Call

Fires an event, calling every registered callback with the given arguments. The engine uses this to dispatch events, but you can also define and fire your own custom events between mods.

ParamTypeNotes
eventstringThe event name to fire.
...anyAny number of arguments, passed through to each callback.
functionhook.RunReturn(event, ...) → any | nil

Like Run, but stops at the first callback that returns a non-nil value and hands that value back. This is how a handler consumes an event instead of merely observing it — OnFrameReceived is dispatched with it, so a mod that has fully handled a frame can say so and the rest are not called. Callback order between mods is not defined, so do not build anything that depends on getting there first. Errors are caught and logged per callback, exactly as with Run.

ParamTypeNotes
eventstringThe event name to fire.
...anyAny number of arguments, passed through to each callback.
One page of the MCCP modding reference. Every section is its own document; search covers all of them.