FiveM Docs
es_extendedClient

Client Functions

Reference for ESX Legacy client functions such as ESX.IsPlayerLoaded, ESX.GetPlayerData, ESX.SearchInventory and ESX.SecureNetEvent, with examples.

These are the general-purpose functions that es_extended adds to the ESX object on the client. Use them to check whether the character is loaded, read and update the cached player data, search the built-in inventory, register secure net events and key bindings.

Overview

Resourcees_extended
SideClient
Sourceclient/modules/player/*.lua, client/modules/core/events.lua, client/compat.lua, client/modules/game/*.lua
AccessESX = exports['es_extended']:getSharedObject() or shared_script '@es_extended/imports.lua'

UI helpers (notifications, menus, context, progress bar) are on Client UI. Entity helpers are on ESX.Game.

Client fields

These values are set when es_extended starts on the client.

FieldTypeDescription
ESX.PlayerDatatableCached data of the local character. See Client PlayerData.
ESX.PlayerLoadedbooleantrue after esx:playerLoaded has been handled, false after logout.
ESX.playerIdnumberLocal player index (PlayerId()).
ESX.serverIdnumberServer id of the local player (GetPlayerServerId(PlayerId())).

Player data

ESX.IsPlayerLoaded

ESX.IsPlayerLoaded()

Returns whether the local character is fully loaded. Check this before you read ESX.PlayerData.

Returns: boolean

client/main.lua
CreateThread(function()
    while not ESX.IsPlayerLoaded() do
        Wait(250)
    end

    print(('Loaded as %s'):format(ESX.PlayerData.job.label))
end)

ESX.GetPlayerData

ESX.GetPlayerData()

Returns the ESX.PlayerData table. It is the same table reference, so reading ESX.PlayerData directly is equivalent.

Returns: table

local data = ESX.GetPlayerData()
print(data.identifier, data.job.name, data.job.grade_label)

ESX.SetPlayerData

ESX.SetPlayerData(key, val)

Writes a value into the local ESX.PlayerData and fires the local esx:setPlayerData event so other scripts (and OnPlayerData from the imports file) can react. The event is not fired for the loadout key, or when a non-table value did not change.

NameTypeDescription
keystringKey in ESX.PlayerData to set.
valanyNew value.

Returns: nothing

This only changes the client cache. It does not save anything on the server and the server will overwrite the key the next time it sends an update. Change real data (job, money, items) on the server through the xPlayer object.

ESX.SetPlayerData('isCuffed', true)

ESX.GetAccount

ESX.GetAccount(account)

Returns one entry from ESX.PlayerData.accounts.

NameTypeDescription
accountstringAccount name, for example money, bank or black_money.

Returns: table|nil with name, money, label, round and index, or nil if the account does not exist.

local bank = ESX.GetAccount('bank')

if bank then
    print(('Bank balance: $%s'):format(ESX.Math.GroupDigits(bank.money)))
end

ESX.SearchInventory

ESX.SearchInventory(items, count)

Searches ESX.PlayerData.inventory (built-in ESX inventory only).

NameTypeDescription
itemsstring | string[]One item name, or an array of item names.
countboolean?When true, return counts instead of item tables. Missing items return 0.

Returns:

  • with a single item name: the item table (name, count, label, weight, usable, rare, canRemove), its count, or nil.
  • with an array: a table keyed by item name.
local counts = ESX.SearchInventory({ 'bread', 'water' }, true)
print(('bread: %d, water: %d'):format(counts.bread, counts.water))

local bread = ESX.SearchInventory('bread')
if bread then
    print(bread.label, bread.count)
end

ESX.ShowInventory

ESX.ShowInventory()

Opens the default inventory UI through exports.esx_inventory:ShowInventory(). Does nothing unless Config.EnableDefaultInventory is enabled.

Returns: nothing

Events and spawning

ESX.SecureNetEvent

ESX.SecureNetEvent(name, func)

Registers a client net event that only runs when the server triggered it. Calls from a local TriggerEvent (where source is an empty string) are ignored. Handlers are removed automatically when the registering resource stops. Errors inside the handler are re-thrown with the original message.

NameTypeDescription
namestringEvent name.
funcfunctionHandler, receives the event arguments.

Returns: nothing

client/main.lua
ESX.SecureNetEvent('myjob:setDuty', function(onDuty)
    ESX.ShowNotification(onDuty and 'You are on duty' or 'You are off duty')
end)
server/main.lua
TriggerClientEvent('myjob:setDuty', source, true)

Use it for every client event that changes state or grants something. A plain RegisterNetEvent handler can also be fired locally by any client script.

ESX.DisableSpawnManager

ESX.DisableSpawnManager()

Turns off auto-spawn of the default spawnmanager resource if it is started. ESX calls this itself before it spawns the player.

Returns: nothing

ESX.SpawnPlayer

ESX.SpawnPlayer(skin, coords, cb)

Loads a skin through skinchanger:loadSkin, freezes the player, moves the ped to coords, waits up to 5 seconds for collision, resurrects the ped and fires the playerSpawned event. Used by ESX on first spawn and by multicharacter resources.

NameTypeDescription
skintableSkin table for skinchanger.
coordstableTable with x, y, z and heading (not w).
cbfunctionCalled when the spawn is done.

Returns: nothing

ESX.SpawnPlayer leaves the player frozen. ESX unfreezes it in its own esx:playerLoaded handler. If you call it yourself later, unfreeze the ped in cb (for example with FreezeEntityPosition(PlayerPedId(), false)).

Input and keys

ESX.RegisterInput

ESX.RegisterInput(command_name, label, input_group, key, on_press, on_release)

Registers a remappable key binding. It wraps xLib.addKeybind, which creates the commands +command_name and -command_name and a key mapping the player can change in the GTA settings. The callbacks do not fire while the pause menu is open.

NameTypeDescription
command_namestringUnique name. ESX prefixes it with + / -.
labelstringText shown in the key bindings settings.
input_groupstringInput mapper, usually keyboard. See input mapper ids.
keystringDefault key, for example f6.
on_pressfunction?Called on key down.
on_releasefunction?Called on key up.

Returns: a keybind object with currentKey, isPressed, disable(self, toggle), remove(self) and getCurrentKey(self).

client/main.lua
local menuKey = ESX.RegisterInput('myjob_menu', 'Open job menu', 'keyboard', 'f6', function()
    if ESX.PlayerData.job.name == 'police' then
        OpenPoliceMenu()
    end
end)

print('Menu key is', menuKey.currentKey)

ESX.HashString

ESX.HashString(str)

Despite the name, this builds a ~INPUT_...~ text token for a command mapping, so GTA can render the bound key inside help text.

NameTypeDescription
strstringThe mapped command name. For keys made with ESX.RegisterInput, the mapped command is + plus your name.

Returns: string

ESX.ShowHelpNotification(('Press %s to open the menu'):format(ESX.HashString('+myjob_menu')))

If the token does not render for your binding, use the currentKey field of the object returned by ESX.RegisterInput instead.

Vehicles

ESX.GetVehicleTypeClient

ESX.GetVehicleTypeClient(model)

Returns the vehicle type string FiveM expects for CreateVehicleServerSetter, based on the vehicle class plus a list of known exceptions. ESX.GetVehicleType is an alias on the client.

NameTypeDescription
modelstring | numberModel name or hash.

Returns: string|false: one of automobile, bike, boat, heli, plane, submarine, trailer, train, or false when the model does not exist or is not a vehicle.

print(ESX.GetVehicleTypeClient('policeb')) -- bike
print(ESX.GetVehicleTypeClient('kosatka')) -- submarine

The server version is documented in Server functions.

Common issues

  • ESX.PlayerData.job is nil. You read it before the player loaded. Wait for ESX.IsPlayerLoaded() or the esx:playerLoaded event.
  • Changes from ESX.SetPlayerData disappear. The server owns the real data and pushes it again on the next update.
  • Inventory helpers return nothing. ESX.SearchInventory and ESX.ShowInventory only work with the built-in inventory, not with Config.CustomInventory.

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