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

81 lines
1.7 KiB
Plaintext

import { Tabs, Tab } from 'nextra-theme-docs';
# Client
Caches data related to the player.
An interval runs every 100ms to update data that cannot be checked via handlers.
## Cache States
- ped: `number`
- player entity id
- playerId: `number`
- player id
- serverId: `number`
- player server id
- weapon: `number` or `false`
- current weapon hash
- vehicle: `number` or `false`
- vehicle entity id
- seat: `number` or `false`
- vehicle seat index
- coords: `vector3`
- current player coords
- only populated if using `zones` or `points`
- cannot be listened for with `lib.onCache`
- resource: `string`
- invoking resource name
- mount: `number` or `false` (RedM only)
- mount entity id
## lib.onCache
Register an event handler that is triggered when the cached value is updated.
<Tabs items={["Lua", "JS"]}>
<Tab>
```lua
lib.onCache(key, function(value) end)
```
- key: `string`
- `ped`
- `vehicle`
- `seat`
- `weapon`
- `mount` (RedM only)
- value: `any`
```lua
lib.onCache('vehicle', function(value)
print('old vehicle:', cache.vehicle)
print('new vehicle:', value)
end)
```
</Tab>
<Tab>
```ts
import { onCache } from '@overextended/ox_lib/client';
onCache(key, (value) => {});
```
- key: `string`
- `ped`
- `vehicle`
- `seat`
- `weapon`
- `mount` (RedM only)
- value: `any`
```ts
import { cache, onCache } from '@overextended/ox_lib/client';
lib.onCache('vehicle', (value) => {
console.log('old vehicle:', cache.vehicle);
console.log('new vehicle:', value);
});
```
</Tab>
</Tabs>