diff --git a/pages/ox_doorlock/Server/functions/Hooks.mdx b/pages/ox_doorlock/Server/functions/Hooks.mdx new file mode 100644 index 000000000..65c1c1a11 --- /dev/null +++ b/pages/ox_doorlock/Server/functions/Hooks.mdx @@ -0,0 +1,56 @@ +# Hooks + +Event hooks allow 3rd party resources to define new behaviour without modifying the doorlock system code directly. + +## registerHook + +```lua +exports.ox_doorlock:registerHook(eventName, function(payload) end, options) +``` + +- eventName: `string` +- payload: `table` +- options?: `table` + - print?: `boolean` + - Print to the console when triggering the event. + - nameFilter?: `string` + - The event will only trigger for specific doors + +Return: + +- hookId: `number` + +### doorAuthorization + +Triggered when opening/closing door. +By returning `false`, you can override door authorization allowing to use your own logic. + +- Payload: `table` + - source: `number` + - door: `DoorData` + - lockpick: boolean + - authorised: boolean + +**Example** + +Allow hotel room's owner open/close door + +```lua +local hookId = exports.ox_doorlock:registerHook('doorAuthorization', function(payload) + local hotel, apartment = payload.door.name:match("HotelDoor_(%w+)_([%d]+)") + return IsAuthorized(payload.source, hotel, apartment) +end, { + nameFilter = "HotelDoor_%w+_[%d]+" +}) +``` + +## removeHooks + +Removes a hook created by the invoking resource with the the specified id. +If no id is specified then all hooks registered by the resource are removed. + +```lua +exports.ox_doorlock:removeHooks(id) +``` + +- id?: `number` \ No newline at end of file