Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions pages/ox_doorlock/Server/functions/Hooks.mdx
Original file line number Diff line number Diff line change
@@ -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`