Files
overextended.github.io/pages/ox_lib/Modules/Callback/Lua/Server.mdx
T
Jag 74227cc262 chore: oxmysql and ox_lib clean-up (#134)
* oxmysql and some lib interface fixes

- Various fixes throughout oxmysql
- started ox_lib audit

* chore: More clean up

- Reword some confusing descriptions
- Add some descriptions
- Type fixes
- Spelling and grammar fixes
- Swapping in `-` where `*` used to be for 
bullet point consistency

ox_lib
- Interface, ACL through GetClosestVehicle audited

* chore: Finishing up ox_lib
2023-07-03 13:13:56 +10:00

63 lines
1.1 KiB
Plaintext

## Trigger Client Callback
### lib.callback
The response is handled in a separate coroutine.
```lua
lib.callback(name, playerId, cb, ...)
```
- name: `string`
- playerId: `number`
- cb: `function`
- ...: `any`
```lua
lib.callback('ox:getNearbyVehicles', source, function(vehicles)
for i = 1, #vehicles do
DeleteEntity(entity)
end
end, args.radius)
```
### lib.callback.await
The current coroutine is yielded until a response is received.
```lua
lib.callback.await(name, playerId, ...)
```
- name: `string`
- playerId: `number`
- ...: `any`
```lua
local vehicles = lib.callback.await('ox:getNearbyVehicles', source, args.radius)
for i = 1, #vehicles do
DeleteEntity(entity)
end
```
## Register Server Callback
### lib.callback.register
Register an event handler for responding to client requests.
```lua
lib.callback.register(name, cb)
```
- name: `string`
- cb: `function`
```lua
lib.callback.register('ox_inventory:getItemCount', function(source, item, metadata, target)
local inventory = target and Inventory(target) or Inventory(source)
return (inventory and Inventory.GetItem(inventory, item, metadata, true)) or 0
end)
```