mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 14:38:50 +00:00
ox_core: Player tweaks, and docs for accounts
This commit is contained in:
1 parent
7f99ef97e1
commit
d21e19e9a3
4 files changed
+133
-28
No files matched your search
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: Server
|
||||||
|
sidebar_position: 1
|
||||||
|
---
|
||||||
|
|
||||||
|
## Ox.GetAccounts
|
||||||
|
|
||||||
|
Return an instance of CAccount for the given charid or group.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local accounts = Ox.GetAccounts(owner)
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use [player.getAccounts](../../Player/Server/methods.md#playergetaccounts) to to simplify access to an player accounts, however the standard function works for offline players.
|
||||||
|
|
||||||
|
|
||||||
|
You can refer to [vl_banking](https://github.com/Volumed/vl_banking) for a simple implementation of banking using ox_core accounts.
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
title: Methods
|
||||||
|
---
|
||||||
|
|
||||||
|
These functions are inherited by instances of CVehicle.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local accounts = Ox.GetAccounts(owner)
|
||||||
|
```
|
||||||
|
|
||||||
|
## accounts.get
|
||||||
|
|
||||||
|
Gets the current balance for an account.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local account = 'fleeca'
|
||||||
|
local balance = accounts.get(account)
|
||||||
|
```
|
||||||
|
|
||||||
|
## accounts.set
|
||||||
|
|
||||||
|
Sets the balance of an account to the given amount.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local account, newBalance = 'fleeca', 200
|
||||||
|
accounts.set(account, newBalance)
|
||||||
|
```
|
||||||
|
|
||||||
|
## accounts.add
|
||||||
|
|
||||||
|
Increases the balance of an account by the given amount.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local account, amount = 'fleeca', 100
|
||||||
|
accounts.add(account, amount)
|
||||||
|
```
|
||||||
|
|
||||||
|
## accounts.remove
|
||||||
|
|
||||||
|
Decreases the balance of an account by the given amount.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local account, amount = 'fleeca', 100
|
||||||
|
accounts.remove(account, amount)
|
||||||
|
```
|
||||||
@@ -16,45 +16,55 @@ Return an instance of CPlayer for the given player source.
|
|||||||
local player = Ox.GetPlayer(source)
|
local player = Ox.GetPlayer(source)
|
||||||
print(json.encode(player, { indent = true }))
|
print(json.encode(player, { indent = true }))
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { GetPlayer } from '@overextended/ox_core/server'
|
import { GetPlayer } from '@overextended/ox_core/server';
|
||||||
|
|
||||||
const player = GetPlayer(source)
|
const player = GetPlayer(source);
|
||||||
console.log(JSON.stringify(player, null, 2))
|
console.log(JSON.stringify(player));
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
|
||||||
## Ox.GetPlayers
|
## Ox.GetPlayers
|
||||||
|
|
||||||
Returns an array containing all players. Methods will not be applied if the first argument is false.
|
Returns an array containing all players. Methods will not be applied if the first argument is false.
|
||||||
|
Players can be filtered to only return players that match the given properties, or groups.
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value='lua' label='Lua'>
|
<TabItem value='lua' label='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local players = Ox.GetPlayers(usemetatable)
|
-- Get an array containing all players in the police or sheriff groups, with grade 3 or higher.
|
||||||
|
local filter = { groups = {['sheriff'] = 3, ['police'] = 3} })
|
||||||
|
|
||||||
|
local players = Ox.GetPlayers(usemetatable, filter)
|
||||||
|
|
||||||
for i = 1, #players do
|
for i = 1, #players do
|
||||||
local player = players[i]
|
local player = players[i]
|
||||||
print(json.encode(player, { indent = true }))
|
print(json.encode(player, { indent = true }))
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { GetPlayers } from '@overextended/ox_core/server'
|
import { GetPlayers } from '@overextended/ox_core/server';
|
||||||
|
|
||||||
const players = GetPlayers()
|
// Get an array containing all players in the police or sheriff groups, with grade 3 or higher.
|
||||||
|
const filter = { groups: { sheriff: 3, police: 3 } })
|
||||||
|
|
||||||
|
const players = GetPlayers(useclass, filter);
|
||||||
for (let i = 0; i < players.length; i++) {
|
for (let i = 0; i < players.length; i++) {
|
||||||
const player = players[i]
|
const player = players[i];
|
||||||
console.log(JSON.stringify(player, null, 2))
|
console.log(JSON.stringify(player));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
@@ -7,21 +7,22 @@ import TabItem from '@theme/TabItem';
|
|||||||
|
|
||||||
These functions are inherited by instances of CPlayer.
|
These functions are inherited by instances of CPlayer.
|
||||||
|
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value='lua' label='Lua'>
|
<TabItem value='lua' label='Lua'>
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
local player = Ox.GetPlayer(source)
|
local player = Ox.GetPlayer(source)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { GetPlayer } from '@overextended/ox_core/server'
|
import { GetPlayer } from '@overextended/ox_core/server';
|
||||||
|
|
||||||
const player = GetPlayer(source)
|
const player = GetPlayer(source);
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
@@ -29,7 +30,6 @@ const player = GetPlayer(source)
|
|||||||
|
|
||||||
Sets the player's metadata for key to the given value.
|
Sets the player's metadata for key to the given value.
|
||||||
|
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value='lua' label='Lua'>
|
<TabItem value='lua' label='Lua'>
|
||||||
|
|
||||||
@@ -37,17 +37,18 @@ Sets the player's metadata for key to the given value.
|
|||||||
local key, value = 'iq', 300
|
local key, value = 'iq', 300
|
||||||
player.set(key, value)
|
player.set(key, value)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const [key, value] = ['iq', 300]
|
const [key, value] = ['iq', 300];
|
||||||
player.set(key, value)
|
player.set(key, value);
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
|
||||||
## player.get
|
## player.get
|
||||||
|
|
||||||
Return the player's metadata. Sending an argument will retrieve a specific metadata key.
|
Return the player's metadata. Sending an argument will retrieve a specific metadata key.
|
||||||
@@ -59,13 +60,36 @@ Return the player's metadata. Sending an argument will retrieve a specific metad
|
|||||||
local data = player.get()
|
local data = player.get()
|
||||||
local iq = player.get('iq')
|
local iq = player.get('iq')
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const data = player.get()
|
const data = player.get();
|
||||||
const iq = player.get('iq')
|
const iq = player.get('iq');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
## player.getAccounts
|
||||||
|
|
||||||
|
Returns an instance of [CAccount](../../Accounts) for the player.
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value='lua' label='Lua'>
|
||||||
|
|
||||||
|
```lua
|
||||||
|
player.getAccounts()
|
||||||
|
```
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
|
```ts
|
||||||
|
player.getAccounts()
|
||||||
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
@@ -79,18 +103,20 @@ Return the player's world position. The value will be cached for future calls, s
|
|||||||
```lua
|
```lua
|
||||||
local coords = player.getCoords(update)
|
local coords = player.getCoords(update)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const coords = player.getCoords(update)
|
const coords = player.getCoords(update);
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
## player.setGroup
|
## player.setGroup
|
||||||
|
|
||||||
Updates the player's grade for the given group. A value of 0 will remove the player
|
Updates the player's grade for the given group. Any value below 1 will remove the group from the player.
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value='lua' label='Lua'>
|
<TabItem value='lua' label='Lua'>
|
||||||
@@ -99,13 +125,15 @@ Updates the player's grade for the given group. A value of 0 will remove the pla
|
|||||||
local group, grade = 'police', 3
|
local group, grade = 'police', 3
|
||||||
player.setGroup(group, grade)
|
player.setGroup(group, grade)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const [group, grade] = ['police', 3]
|
const [group, grade] = ['police', 3];
|
||||||
player.setGroup(group, grade)
|
player.setGroup(group, grade);
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
@@ -121,13 +149,15 @@ The filter can be a string, array, or object where key is the group, and value i
|
|||||||
local filter = { police = 0, sheriff = 0 }
|
local filter = { police = 0, sheriff = 0 }
|
||||||
local group, grade = player.hasGroup(filter)
|
local group, grade = player.hasGroup(filter)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const filter = { police: 0, sheriff: 0 }
|
const filter = { police: 0, sheriff: 0 };
|
||||||
const [group, grade] = player.hasGroup(filter)
|
const [group, grade] = player.hasGroup(filter);
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
@@ -142,13 +172,15 @@ Check if the given source is inside the player's scope.
|
|||||||
local target = 2
|
local target = 2
|
||||||
local inScope = player.isPlayerInScope(target)
|
local inScope = player.isPlayerInScope(target)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const target = 2
|
const target = 2;
|
||||||
const inScope = player.isPlayerInScope(target)
|
const inScope = player.isPlayerInScope(target);
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
@@ -162,12 +194,13 @@ Trigger a client event for all players in the player's scope.
|
|||||||
```lua
|
```lua
|
||||||
player.triggerScopedEvent(eventName, ...)
|
player.triggerScopedEvent(eventName, ...)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value='js/ts' label='JS/TS'>
|
<TabItem value='js/ts' label='JS/TS'>
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
player.triggerScopedEvent(eventName, ...)
|
player.triggerScopedEvent(eventName, ...)
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
Reference in new issue
Block a user