update ox_core player methods

This commit is contained in:
Linden committed 2022-11-27 04:04:57 +11:00
1 parent e2486a4800
commit d4bfd2623d
1 file changed
+31 -159
+31 -159
View File
@@ -11,242 +11,114 @@ These functions are inherited by instances of [CPlayer](../Server/).
Update the player's metadata, optionally syncing it with the client. Update the player's metadata, optionally syncing it with the client.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local key, value = 'iq', 300 player.set(key, value, replicated)
player.set(key, value)
``` ```
</TabItem> - key: `string`
<TabItem value='js/ts' label='JS/TS'> - value: `any`
- replicated?: `boolean`
```ts
const [key, value] = ['iq', 300];
player.set(key, value);
```
</TabItem>
</Tabs>
## player.setdb ## player.setdb
Update the player's metadata and store in the DB, optionally syncing it with the client. Update the player's metadata and store in the DB, optionally syncing it with the client.
Note: These values are not synced to the client on login; you will need to use `player.set`.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local key, value = 'iq', 300 player.setdb(key, value, replicated)
player.setdb(key, value)
``` ```
</TabItem> - key: `string`
<TabItem value='js/ts' label='JS/TS'> - value: `string | number | table | boolean`
- replicated?: `boolean`
```ts
const [key, value] = ['iq', 300];
player.setdb(key, value);
```
</TabItem>
</Tabs>
## player.get ## player.get
Return the player's metadata. Sending an argument will retrieve a specific metadata key. Get a value from the player's metadata, or omit the argument to get all metadata.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local data = player.get() player.get(key)
local iq = player.get('iq')
``` ```
</TabItem> - key?: `string`
<TabItem value='js/ts' label='JS/TS'>
```ts ## player.getState
const data = player.get();
const iq = player.get('iq'); Return the player's statebag.
```lua
player.getState()
``` ```
</TabItem>
</Tabs>
## player.getCoords ## player.getCoords
Return the player's world position. Return the player's position.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local coords = player.getCoords() player.getCoords()
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const coords = player.getCoords();
```
</TabItem>
</Tabs>
## player.setGroup ## player.setGroup
Updates the player's grade for the given group. Any value below 1 will remove the group from the player. Updates the player's grade for the given group. Any value below 1 will remove the group from the player.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local group, grade = 'police', 3
player.setGroup(group, grade) player.setGroup(group, grade)
``` ```
</TabItem> - group: `string`
<TabItem value='js/ts' label='JS/TS'> - grade?: `number`
```ts
const [group, grade] = ['police', 3];
player.setGroup(group, grade);
```
</TabItem>
</Tabs>
## player.getGroup ## player.getGroup
Returns the player's current grade for a given group. Returns the player's current grade for a given group.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local grade = player.getGroup() player.getGroup()
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const grade = player.getGroup();
```
</TabItem>
</Tabs>
## player.getGroup ## player.getGroup
Returns an object of all groups the player is in, with the current grade as the value. Returns an object of all groups the player is in, with the current grade as the value.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local groups = player.getGroups() player.getGroups()
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const groups = player.getGroups();
```
</TabItem>
</Tabs>
## player.hasGroup ## player.hasGroup
Check if the player is a member of a given group, and returns the matching group name and grade. Check if the player is a member of a given group, and returns the matching group name and grade.
The filter can be a string, array, or object where key is the group, and value is the minimum grade. The filter can be a string, array, or object where key is the group, and value is the minimum grade.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local filter = { police = 0, sheriff = 0 } player.hasGroup(filter)
local group, grade = player.hasGroup(filter)
``` ```
</TabItem> - filter: `string | string[] | { [string]: number }`
<TabItem value='js/ts' label='JS/TS'>
```ts
const filter = { police: 0, sheriff: 0 };
const [group, grade] = player.hasGroup(filter);
```
</TabItem>
</Tabs>
## player.getPlayersInScope ## player.getPlayersInScope
Return an array of all player id's inside the player's scope. Return an array of all player id's inside the player's scope.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local inScope = player.getPlayersInScope() player.getPlayersInScope()
``` ```
</TabItem>
<TabItem value='js/ts' label='JS/TS'>
```ts
const inScope = player.getPlayersInScope();
```
</TabItem>
</Tabs>
## player.isPlayerInScope ## player.isPlayerInScope
Check if the given source is inside the player's scope. Check if the given source is inside the player's scope.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
local target = 2 player.isPlayerInScope(target)
local inScope = player.isPlayerInScope(target)
``` ```
</TabItem> - target: `number`
<TabItem value='js/ts' label='JS/TS'>
```ts
const target = 2;
const inScope = player.isPlayerInScope(target);
```
</TabItem>
</Tabs>
## player.triggerScopedEvent ## player.triggerScopedEvent
Trigger a client event for all players in the player's scope.
<Tabs>
<TabItem value='lua' label='Lua'>
```lua ```lua
player.triggerScopedEvent(eventName, ...) player.triggerScopedEvent(eventName, ...)
``` ```
</TabItem> - eventName: `string`
<TabItem value='js/ts' label='JS/TS'> - ...?: `any[]`
```ts
player.triggerScopedEvent(eventName, ...)
```
</TabItem>
</Tabs>