HookPipeline
Creates a hook pipeline for a specific event, which manages a collection of registered hooks and controls execution flow through filtering, rejection, and dispatching.
lib.hook:new(event, filter)
import { HookPipeline } from "@overextended/ox_lib/hooks";
new HookPipeline(event, filter)
- event:
string - filter?:
function(hook, payload): boolean- Used to filter out registered hooks based on if they pass a predicate function.
Returns: HookPipeline
Methods > registerHook
Registers a new event handler into the hook pipeline.
pipeline:registerHook(handler, options)
pipeline.registerHook(handler, options)
- handler:
function(payload: unknown): boolean - options?:
table- Optional metadata to attach to the hook.
Methods > remove
Removes hooks from the pipeline.
pipeline:remove(hookId)
pipeline.remove(hookId)
- hookId?:
string- If defined, only the specified hook is removed - otherwise all hooks for the invoking resource are removed.
Methods > dispatch
Executes each registered hook in order of registration, checking the payload against a provided filter using the hook options and executing the hook callback.
A hook may block execution by returning false from a registered handler.
If any hook rejects the execution, dispatch is cancelled and result.ok is set to false.
The returned object acts as a finalisation handle and emits results to registered handlers once closed.
local hook <close> = pipeline:dispatch(payload)
using hook = pipeline.dispatch(payload)
- payload:
unknown
EventHook
Allows resources to call pipeline.registerHook using exports.
lib.registerHook(eventName, handler, options)
import { registerHook } from "@overextended/ox_lib/hooks";
registerHook(eventName, handler, options)
- eventName:
string - handler?:
function(payload: unknown): boolean - options?: Optional metadata to attach to the hook.
Methods > on
Attaches a post-execution event handler for this hook.
hook:on(handler)
hook.on(handler)
- handler:
function(ok: boolean, payload: unknown)
Methods > off
Detatches the currently registered post-hook event handler, if one exists.
hook:off()
hook.off()
Methods > remove
Fully removes this hook from both the local event system and the external hook pipeline provided from the originating resource.
hook:remove()
hook.remove()
Registered Hooks
These hook pipelines are registered and managed by ox_lib for other resources to interact with.
See EventHook for more information.
ox_lib:setPlayerState
When using sv_stateBagStrictMode players cannot arbitrarily modify their own states, and changes will be rejected by default.
lib.registerHook('ox_lib:setPlayerState', predicate, { key: state })
import { registerHook } from "@overextended/ox_lib/hooks";
registerHook('ox_lib:setPlayerState', predicate, { key: state })
ox_lib:setEntityState
When using sv_stateBagStrictMode players cannot arbitrarily modify entity states, and changes will be rejected by default.
lib.registerHook('ox_lib:setEntityState', predicate, { key: state })
import { registerHook } from "@overextended/ox_lib/hooks";
registerHook('ox_lib:setEntityState', predicate, { key: state })