mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 06:28:54 +00:00
add docs for js/ts callbacks
This commit is contained in:
1 parent
4e93442110
commit
05d6333992
4 files changed
+96
No files matched your search
@@ -0,0 +1,62 @@
|
||||
## Trigger 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
|
||||
```
|
||||
|
||||
## 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)
|
||||
```
|
||||
Reference in new issue
Block a user