ox_lib: c->s and s->c callbacks

This commit is contained in:
Linden committed 2022-09-18 16:44:04 +10:00
1 parent a98ce1eba3
commit cd16955a4f
2 files changed
+81 -10

No files matched your search

+49 -2
View File
@@ -1,9 +1,56 @@
## Server -> Client callback
### lib.callback
The response is handled in a separate coroutine.
```lua
lib.callback(name, source, cb, ...)
```
- name: `string`
- source: `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, source, ...)
```
- name: `string`
- source: `number`
- ...: `any`
```lua
local vehicles = lib.callback.await('ox:getNearbyVehicles', source, args.radius)
for i = 1, #vehicles do
DeleteEntity(entity)
end
```
## Client -> Server callback
### lib.callback.register
```lua
lib.callback.register(name, cb)
```
* name: `string`
* cb: `function`
- name: `string`
- cb: `function`
```lua
lib.callback.register('ox_inventory:getItemCount', function(source, item, metadata, target)