Player Data
Learn how to access and modify a player's data
Introductionโ
The Player Data object in qb-core stores all information related to a player's character, such as personal details, job, gang affiliation, metadata, and more. These values are initialized using default values defined in the config.lua file of qb-core. This guide will provide an overview of the structure, default values, and how you can access or modify player data
QBCore
โโโ Players
โ โโโ [source]
โ โโโ PlayerData
โ โโโ citizenid: string (Unique identifier)
โ โโโ cid: number (Character ID)
โ โโโ money: table
โ โ โโโ { cash: number, bank: number }
โ โโโ charinfo: table
โ โ โโโ firstname: string
โ โ โโโ lastname: string
โ โ โโโ ...
โ โโโ job: table
โ โ โโโ name: string
โ โ โโโ label: string
โ โ โโโ payment: number
โ โ โโโ onduty: boolean
โ โ โโโ isboss: boolean
โ โ โโโ grade: table
โ โ โโโ name: string
โ โ โโโ level: number
โ โโโ gang: table
โ โ โโโ name: string
โ โ โโโ label: string
โ โ โโโ isboss: boolean
โ โ โโโ grade: table
โ โ โโโ name: string
โ โ โโโ level: number
โ โโโ metadata: table
โ โ โโโ hunger: number
โ โ โโโ thirst: number
โ โ โโโ stress: number
โ โ โโโ isdead: boolean
โ โ โโโ ...
โ โโโ position: Vector
โ โโโ items: table (inventory items)
Configurationโ
The player data default values can be modified in the config.lua file of qb-core.
These defaults are stored in QBConfig.Player.PlayerDefaults and determine what a player starts with when creating a new character
Identification Tableโ
| Property | Type | Default Value | Description |
|---|---|---|---|
citizenid | string | Generated via CreateCitizenId | A unique identifier for the player. |
cid | number | 1 | Character ID (used for multi-character systems). |
RegisterServerEvent('qb-docs:server:getPlayerInfo', function(source)
local Player = exports['qb-core']:GetPlayer(source)
if not Player then return end
local citizenid = Player.PlayerData.citizenid
print(citizenid)
end)
Money Tableโ
| Property | Type | Default Value | Description |
|---|---|---|---|
money | table | { cash = 0, bank = 0 } | Contains the playerโs cash and bank balances. |
RegisterServerEvent('qb-docs:server:getPlayerInfo', function(source)
local Player = exports['qb-core']:GetPlayer(source)
if not Player then return end
local money = Player.PlayerData.money
local cash = money.cash
local bank = money.bank
print(cash, bank)
end)
Character Information Tableโ
| Property | Type | Default Value | Description |
|---|---|---|---|
charinfo | table | { firstname, lastname, ... } | Basic personal information about the player. |
Subfieldsโ
| Subfield | Type | Default Value | Description |
|---|---|---|---|
firstname | string | "Firstname" | The player's first name. |
lastname | string | "Lastname" | The player's last name. |
birthdate | string | "00-00-0000" | The player's date of birth. |
gender | number | 0 | The player's gender (0 = male, 1 = female). |
nationality | string | "USA" | The player's nationality. |
phone | string | Generated via CreatePhoneNumber | The player's phone number. |
account | string | Generated via CreateAccountNumber | The player's bank account number. |
RegisterServerEvent('qb-docs:server:getPlayerInfo', function(source)
local Player = exports['qb-core']:GetPlayer(source)
if not Player then return end
local charinfo = Player.PlayerData.charinfo
local firstname = Player.PlayerData.firstname
local lastname = Player.PlayerData.lastname
local birthdate = Player.PlayerData.birthdate
local gender = Player.PlayerData.gender
local nationality = Player.PlayerData.nationality
local phone = Player.PlayerData.phone
local account = Player.PlayerData.account
print("Player's name:", firstname, lastname)
end)
Job Tableโ
| Property | Type | Default Value | Description |
|---|---|---|---|
job | table | { name = 'unemployed', ... } | The playerโs current job and related information. |
Subfieldsโ
| Subfield | Type | Default Value | Description |
|---|---|---|---|
name | string | "unemployed" | The job name. |
label | string | "Civilian" | The display label of the job. |
payment | number | 10 | The playerโs salary. |
onduty | boolean | false | Whether the player is on duty. |
isboss | boolean | false | Whether the player is the boss of the job. |
grade | table | { name = 'Freelancer', ... } | The player's job grade. |
RegisterServerEvent('qb-docs:server:getPlayerInfo', function(source)
local Player = exports['qb-core']:GetPlayer(source)
if not Player then return end
local jobInfo = Player.PlayerData.job
local name = jobInfo.name
local label = jobInfo.label
local payment = jobInfo.payment
local onduty = jobInfo.onduty
local isboss = jobInfo.isboss
print("Player's job:", name)
print("Job label:", label)
end)
Gang Tableโ
| Property | Type | Default Value | Description |
|---|---|---|---|
gang | table | { name = 'Unaffiliated', ... } | The playerโs current gang and related information. |
Subfieldsโ
| Subfield | Type | Default Value | Description |
|---|---|---|---|
name | string | "Unaffiliated" | The gang name. |
label | string | "No Gang" | The display label of the gang. |
isboss | boolean | false | Whether the player is the boss of the gang. |
grade | table | { name = 'Unaffiliated', ... } | The player's gang grade. |
RegisterServerEvent('qb-docs:server:getPlayerInfo', function(source)
local Player = exports['qb-core']:GetPlayer(source)
if not Player then return end
local gangInfo = Player.PlayerData.gang
local name = gangInfo.name
local label = gangInfo.label
print("Player's gang:", name)
print("Gang label:", label)
end)
Metadata Tableโ
| Property | Type | Default Value | Description |
|---|---|---|---|
hunger | number | 100 | The playerโs hunger level (0โ100). |
thirst | number | 100 | The playerโs thirst level (0โ100). |
stress | number | 0 | The playerโs stress level (0โ100). |
isdead | boolean | false | Whether the player is dead. |
inhale | boolean | false | Whether the player is handcuffed. |
phone | table | {} | Stores phone-specific data such as installed apps. |
RegisterServerEvent('qb-docs:server:getPlayerInfo', function(source)
local Player = exports['qb-core']:GetPlayer(source)
if not Player then return end
local metadata = Player.PlayerData.metadata
local hunger = metadata.hunger
local thirst = metadata.thirst
print('Hunger Level: ', hunger)
print('Thirst Level: ', thirst)
end)