Skip to content

Commit

Permalink
feat: added documentation for clientcallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
DasistOnly committed Jul 15, 2024
1 parent 7df05b3 commit 01e5be1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/legacy/Client/functions/registerclientcallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# RegisterClientCallback

```lua
ESX.RegisterClientCallback(name, handler)
```

This function registers a client callback, which is used for sending Client Data, to the Server.

## Arguments

| Argument | Data Type | Optional | Default Value | Explaination |
| -------- | --------- | -------- | ------------- | ---------------------------------------------------------------------------------------------------------------- |
| name | string | No | - | Client callback name |
| cb | function | No | - | Callback function, which contains an varied size of arguments depending on how many arguments parsed from client |
| ...args | any | No | - | The args provided after the handler on the client TriggerClientCallback |

## Example

```lua
local myVariable = 'hello'

ESX.RegisterClientCallback('esx_example:test', function(cb, myArgument)
print(myArgument)
print('this code is an asynchronous task')
cb(myVariable)
end)

print('this code is running in sync')
```
29 changes: 29 additions & 0 deletions docs/legacy/Server/Functions/triggerclientcallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# TriggerClientCallback

```lua
ESX.TriggerClientCallback(name, source, cb, ...args)
```

This function triggers a client callback. See [ESX.RegisterClientCallback](./../../client/functions/registerclientcallback) on registering client callbacks.

## Arguments

| Argument | Data Type | Optional | Default Value | Explaination |
| -------- | --------- | -------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name | string | No | - | A valid client callback name |
| source | number | No | - | The source of the player to trigger the callback on |
| cb | function | No | - | The returned function when the async task has completed. The invoked function a varied size of arguments depending on how many arguments are parsed from the client |
| args | any | Yes | - | Any arguments to parse to the async function |

## Example

```lua
local myArgument = 'hello'

ESX.TriggerClientCallback('esx_example:test', source, function(isBusy, numKills)
print(isBusy, numKills)
print('this code is an asynchronous task')
end, myArgument)

print('this code is running in sync')
```

0 comments on commit 01e5be1

Please sign in to comment.