mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 22:22:46 +00:00
ox_lib: c->s and s->c callbacks
This commit is contained in:
1 parent
a98ce1eba3
commit
cd16955a4f
2 files changed
+81
-10
No files matched your search
@@ -1,14 +1,17 @@
|
|||||||
Triggers a registered server callback and registers an event handler for the response.
|
## Client -> Server callback
|
||||||
|
|
||||||
### lib.callback
|
### lib.callback
|
||||||
|
|
||||||
The response is handled in a separate coroutine.
|
The response is handled in a separate coroutine.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.callback(name, delay, cb, ...)
|
lib.callback(name, delay, cb, ...)
|
||||||
```
|
```
|
||||||
* name: `string`
|
|
||||||
* delay: `number` or `false`
|
- name: `string`
|
||||||
* cb: `function`
|
- delay: `number` or `false`
|
||||||
* ...: `any`
|
- cb: `function`
|
||||||
|
- ...: `any`
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.callback('ox_inventory:getItemCount', false, function(count)
|
lib.callback('ox_inventory:getItemCount', false, function(count)
|
||||||
@@ -17,15 +20,36 @@ end, 'water', {type = 'fresh'})
|
|||||||
```
|
```
|
||||||
|
|
||||||
### lib.callback.await
|
### lib.callback.await
|
||||||
|
|
||||||
The current coroutine is yielded until a response is received.
|
The current coroutine is yielded until a response is received.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.callback.await(name, delay, ...)
|
lib.callback.await(name, delay, ...)
|
||||||
```
|
```
|
||||||
* name: `string`
|
|
||||||
* delay: `number` or `false`
|
- name: `string`
|
||||||
* ...: `any`
|
- delay: `number` or `false`
|
||||||
|
- ...: `any`
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local count = lib.callback.await('ox_inventory:getItemCount', false, 'water', {type = 'fresh'})
|
local count = lib.callback.await('ox_inventory:getItemCount', false, 'water', {type = 'fresh'})
|
||||||
print(count)
|
print(count)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Server -> Client callback
|
||||||
|
|
||||||
|
### lib.callback.register
|
||||||
|
|
||||||
|
```lua
|
||||||
|
lib.callback.register(name, cb)
|
||||||
|
```
|
||||||
|
|
||||||
|
- name: `string`
|
||||||
|
- cb: `function`
|
||||||
|
|
||||||
|
```lua
|
||||||
|
lib.callback.register('ox:getNearbyVehicles', function(radius)
|
||||||
|
local nearbyVehicles = lib.getNearbyVehicles(GetEntityCoords(cache.ped), radius, true)
|
||||||
|
return nearbyVehicles
|
||||||
|
end
|
||||||
|
```
|
||||||
@@ -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
|
### lib.callback.register
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.callback.register(name, cb)
|
lib.callback.register(name, cb)
|
||||||
```
|
```
|
||||||
* name: `string`
|
|
||||||
* cb: `function`
|
- name: `string`
|
||||||
|
- cb: `function`
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.callback.register('ox_inventory:getItemCount', function(source, item, metadata, target)
|
lib.callback.register('ox_inventory:getItemCount', function(source, item, metadata, target)
|
||||||
|
|||||||
Reference in new issue
Block a user