FiveM Docs
es_extended

PlayerData

What ESX Legacy stores about a character and where to read it. Every field of ESX.PlayerData on the client and the xPlayer object on the server, with types.

PlayerData is the information ESX keeps about the loaded character: identity, accounts, inventory, loadout, job, group and metadata. On the server it lives on the xPlayer object. On the client a copy is stored in ESX.PlayerData and kept up to date by ESX events. Read it on the client for UI and checks, but make every decision that matters (money, items, permissions) on the server.

Overview

FactValue
ServerESX.GetPlayerFromId(source) returns the xPlayer
ClientESX.PlayerData (needs @es_extended/imports.lua) or ESX.GetPlayerData()
Ready flagESX.PlayerLoaded (client)
Sent to clientIn esx:playerLoaded, then updated by events like esx:setJob and esx:setAccountMoney
Saved columnsaccounts, job, job_grade, group, position, inventory, loadout, metadata in users

Getting PlayerData

fxmanifest.lua
shared_script "@es_extended/imports.lua"
client/main.lua
CreateThread(function()
    while not ESX.PlayerLoaded do
        Wait(250)
    end

    print("Job: " .. ESX.PlayerData.job.label)
end)

RegisterNetEvent("esx:setJob", function(job, lastJob)
    print(("Job changed from %s to %s"):format(lastJob.name, job.name))
end)

With the imports file, ESX.PlayerData is refreshed automatically in your resource. Without it, call ESX.GetPlayerData() each time you need fresh data, because the ESX object you got from the export is a copy.

Field reference

"Client" means ESX.PlayerData.<field>, "Server" means the xPlayer object.

FieldTypeClientServerDescription
identifierstringYesgetIdentifier()Character identifier, char1:... with multicharacter.
ssnstringYesgetSSN()Social security number XXX-XX-XXXX.
namestringYesgetName()Character name, or the FiveM name without an identity.
firstNamestringYesget("firstName")Default "John" until an identity exists.
lastNamestringYesget("lastName")Default "Doe".
dateofbirthstringYesget("dateofbirth")As stored by esx_identity, default "01/01/2000".
sexstringYesget("sex")"m" or "f". Only set when the character has an identity.
heightnumberYesget("height")Height in cm, default 120.
groupstringYesgetGroup()Permission group.
jobtableYesgetJob()See job.
accountstable[]YesgetAccounts()See accounts.
moneynumberYes (snapshot)getMoney()Cash at load time. Not updated on the client afterwards.
inventorytable[]YesgetInventory()See inventory.
weightnumberYes (load time)getWeight()Carried weight.
maxWeightnumberYesgetMaxWeight()Weight limit.
loadouttable[]YesgetLoadout()See loadout.
metadatatableYesgetMeta()Persistent custom data.
variablestableYesget(key)Non-persistent custom data set with xPlayer.set.
coordsvector3Yes (live)getCoords()On the client this reads the ped's current position.
skintableYesnoSaved skinchanger data.
deadbooleanYesnoUpdated on death and respawn.
pednumberYesnoCurrent ped handle.
weaponnumberYesnoHash of the weapon in hand.
vehiclenumberYesnoCurrent vehicle handle, if any.
seatnumberYesnoCurrent seat index, if in a vehicle.
source / playerIdnumbernoYesServer ID. Use GetPlayerServerId(PlayerId()) on the client.
licensestringnoYesIdentifier with type prefix.
adminbooleannoYesAdmin state at load.

Details

job

{
    name = "police",
    label = "LSPD",
    type = "leo",
    onDuty = true,
    grade = 2,
    grade_name = "sergeant",
    grade_label = "Sergeant",
    grade_salary = 900,
    skin_male = {},
    skin_female = {},
}

grade and grade_salary are numbers. onDuty comes from metadata.jobDuty. The field list is described in xPlayer.getJob.

accounts

An array, not a map:

{
    { name = "bank", money = 50000, label = "Bank", round = true, index = 1 },
    { name = "money", money = 500, label = "Cash", round = true, index = 2 },
    { name = "black_money", money = 0, label = "Dirty Money", round = true, index = 3 },
}

The order follows Config.Accounts and is not guaranteed. Look accounts up by name:

local bank = ESX.GetAccount("bank")
print("Bank: $" .. (bank and bank.money or 0))

inventory

With the default inventory: an array of the items the player owns (count above 0), sorted by label.

{
    { name = "bread", label = "Bread", count = 3, weight = 1, usable = true, rare = false, canRemove = true },
    { name = "water", label = "Water", count = 1, weight = 1, usable = true, rare = false, canRemove = true },
}
client/main.lua
local breadCount = ESX.SearchInventory("bread", true) -- 0 when the player has none

With ox_inventory, use ox_inventory's own exports to read items.

loadout

{
    { name = "WEAPON_PISTOL", label = "Pistol", ammo = 48, components = { "clip_default", "flashlight" }, tintIndex = 0 },
}

Empty with ox_inventory.

metadata

A free-form table that is saved to the database. ESX itself uses health, armor, lastPlaytime and jobDuty. Write it on the server with xPlayer.setMeta; the client copy updates automatically.

-- client
local stress = ESX.PlayerData.metadata.stress or 0

Reacting to changes on the client

EventUpdates
esx:playerLoadedWhole ESX.PlayerData.
esx:setJobjob
esx:setAccountMoneyOne entry in accounts
esx:addInventoryItem, esx:removeInventoryItem, esx:setInventoryinventory
esx:setMaxWeightmaxWeight
esx:setGroupgroup
esx:updatePlayerDatametadata or variables
esx:onPlayerLogoutClears ESX.PlayerData and sets ESX.PlayerLoaded = false

With @es_extended/imports.lua you can also define a global OnPlayerData function. It is called with key, value, lastValue whenever es_extended changes a field:

client/main.lua
function OnPlayerData(key, value)
    if key == "job" then
        updateJobBlips(value.name)
    end
end

See client events for the full list.

Common issues

  • attempt to index a nil value (field 'job'): you read ESX.PlayerData before esx:playerLoaded. Wait for ESX.PlayerLoaded.
  • Stale data in a resource without imports: the exported ESX object is a snapshot. Use ESX.GetPlayerData() or switch to @es_extended/imports.lua.
  • xPlayer.firstName is nil: on the server, identity fields are variables. Use xPlayer.get("firstName").
  • Inventory indexed by name returns nil: inventory is an array. Use ESX.SearchInventory or xPlayer.getInventoryItem.

Frequently asked questions

Independent documentation

esx-fivem.com is a community project and is not affiliated with the ESX Framework team. Facts on this page were checked against the upstream source. Official resources: docs.esx-framework.org and github.com/esx-framework.
Edit on GitHub

Last updated on

On this page