Files
JagandLuke 1d2c490b26 refactor: Add h1 headers to all pages missing it (#137)
* refactor: Add h1 headers to all pages missing it

* refactor: missed example h3

* change hooks example heading to bold text

---------

Co-authored-by: Luke <[email protected]>
2023-07-08 11:08:43 +02:00

51 lines
1.1 KiB
Plaintext

# Server
## Trigger Client Callback
### triggerClientCallback
```ts
triggerClientCallback(eventName, playerId, ...args)
```
- eventName: `string`
- playerId: `number`
- ...args: `any`
## Register Server Callback
### onClientCallback
```ts
onClientCallback(eventName, cb)
```
* eventName: `string`
* cb: `function`(playerId: `number`, ...args: `any`)
## Usage Example
For this example to fully make sense take a look at the example on the [client](./Client#usage-example) page for the callbacks.
```ts
import { onClientCallback, triggerClientCallback } from '@overextended/ox_lib/server';
```
```ts
onClientCallback('test:server', (playerId, ...args: [number, null, number, null, null, number]) => {
console.log('onClientCallback', playerId, ...args);
return {
serverValue: 3000,
};
});
```
```ts
setTimeout(async () => {
const response = await triggerClientCallback<{ clientValue: string }>('test:client', 1, [1, null, 3, null, null, 6])
if (!response) return;
console.log(response.clientValue);
console.log('Response from client', response);
}, 100);
```