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.
| Param | Type | Notes |
| event | string | Event name, e.g. "OverlayElement". |
| name | string | Unique identifier for this callback. |
| fn | function | Called with the event's arguments. |
functionhook.Remove(event, name) → nil
Unregisters the callback previously added under this event + name.
| Param | Type | Notes |
| event | string | The event name. |
| name | string | The 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.
| Param | Type | Notes |
| event | string | The event name to fire. |
| ... | any | Any 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.
| Param | Type | Notes |
| event | string | The event name to fire. |
| ... | any | Any number of arguments, passed through to each callback. |