📊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: vector3
│           └── 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

Player Data Object Structure

When accessing the player object on the server using QBCore.Functions.GetPlayer pass the source (player net id) — shown in examples

When accessing the player object on the client, you don't have to pass anything and can just call QBCore.Functions.GetPlayerData

If you prefer to access the player data directly instead of calling the functions, you can do so with this format QBCore.Players[source].PlayerData but it's not recommended

Below is a breakdown of the player data structure, its properties, default values and how to access them when retrieving the player object

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).

Money Table

Property
Type
Default Value
Description

money

table

{ cash = 0, bank = 0 }

Contains the player’s cash and bank balances.

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 for male, 1 for 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.

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.

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 job.

grade

table

{ name = 'Unaffiliated', ... }

The player's job grade.

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.

Player Object Functions

Every player that is created on the server has certain functions that are attached to them. These functions can be called on them directly!

UpdatePlayerData

Update the players data on the client & server

This function triggers the event QBCore:Player:SetPlayerData

SetJob

Set a player's job and grade

  • job: string

  • grade: number

  • returns: boolean - true for successful, false for unsuccessful

SetGang

Set a players gang and grade

  • gang: string

  • grade: number

  • returns: boolean - true for successful, false for unsuccessful

Notify

Shows the player a notification

  • text: string

  • type: string — error, success, primary, warning

  • length (optional): number

HasItem

Preferred to use inventory export for checking if has item! This function just routes to that

  • item: string | table

  • amount: number

  • returns: boolean

GetName

Get's the players full character name

  • returns: string

SetJobDuty

Sets the player on/off duty

This function triggers the events QBCore:Server:OnJobUpdate and QBCore:Client:OnJobUpdate It also triggers the function UpdatePlayerData

  • duty: boolean

SetPlayerData

Set the player data value of a player specifically by it's name

This function also triggers the function UpdatePlayerData

  • key: string

  • value: string | table

SetMetaData

Set the metadata value of a player specifically by it's name

This function also triggers the function UpdatePlayerData

  • key: string

  • value: string | table | number

GetMetaData

Gets the value of a player metadata specifically by it's name

  • value: string

  • returns: string | table | number

AddRep

Adds rep to value to a rep specifically by it's name

This function also triggers the function UpdatePlayerData

Add different kinds of rep in qb-core/config.lua

  • rep: string

  • amount: number

RemoveRep

Decreases value to a rep specifically by it's name

This function also triggers the function UpdatePlayerData

Add different kinds of rep in qb-core/config.lua

  • rep: string

  • amount: number

GetRep

Gets the current value of rep specifically by it's name

  • rep: string

  • returns: number

AddMoney

Adds to the value of a specific money type by it's name

This function also triggers the function UpdatePlayerData

  • money: string

  • returns: boolean

RemoveMoney

Decreases the value of a specific money type by it's name

This function also triggers the function UpdatePlayerData

  • money: string

  • returns: boolean

SetMoney

Sets the value of a specific money type by it's name

This function also triggers the function UpdatePlayerData

  • money: string

  • returns: boolean

GetMoney

Returns the value of the money type supplied

  • money: string

  • returns: number

Save

Triggers a save of the player

Logout

Forces the player to logout back to the multicharacter screen

AddMethod

The AddMethod function allows you to dynamically add custom methods (functions) to the player object. This is particularly useful for extending player functionality in a modular and reusable way

  • method: string

  • handler: function

AddField

The AddField function allows you to dynamically add custom fields (variables or data) to the player object. This is useful for storing additional player-specific data that isn’t part of the default PlayerData structure

  • field: string

  • data: any

Last updated

Was this helpful?