Files
overextended.github.io/pages/ox_lib/Modules/Cache/Client.mdx
T
Jag 74227cc262 chore: oxmysql and ox_lib clean-up (#134)
* oxmysql and some lib interface fixes

- Various fixes throughout oxmysql
- started ox_lib audit

* chore: More clean up

- Reword some confusing descriptions
- Add some descriptions
- Type fixes
- Spelling and grammar fixes
- Swapping in `-` where `*` used to be for 
bullet point consistency

ox_lib
- Interface, ACL through GetClosestVehicle audited

* chore: Finishing up ox_lib
2023-07-03 13:13:56 +10:00

78 lines
1.4 KiB
Plaintext

import { Tabs, Tab } from 'nextra-theme-docs';
Caches data related to the player.
An interval runs every 100ms to update data that cannot be checked via handlers.
## 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`
- 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>