FiveM Docs
es_extendedEvents

Server Events

Every esx server event in ESX Legacy 1.16 with parameters, who triggers it and example handlers, plus which client-sent events are untrusted and must be validated.

These are the esx: events you meet on the server. Most of them are local server events that es_extended fires so other resources can react, for example when a player loads, changes job or gets money. A second group are net events sent by clients, which you must treat as untrusted input.

Overview

Resourcees_extended
SideServer
Listen withAddEventHandler (local events), RegisterNetEvent (events sent by clients)
MarkerMeaning
Listen onlyFired by es_extended. Do not trigger it yourself, other scripts would act on fake data.
InternalUsed by ESX for its own flow. Do not trigger or override.
Client-sent (untrusted)Arrives from a client through TriggerServerEvent. Anyone can send any arguments.

Security

Never give money, items or permissions inside a handler for an event that a client can send. The client-sent events below carry whatever the client wants. Always look the player up with ESX.GetPlayerFromId(source) and verify on the server.

Player lifecycle

esx:playerLoaded

Listen only. Fired after a character is loaded and the xPlayer object exists. Also fires for every character switch with multicharacter.

NameTypeDescription
playerIdnumberServer id.
xPlayertableThe xPlayer object.
isNewbooleantrue if the character was just created.
server/main.lua
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer, isNew)
    if isNew then
        xPlayer.addInventoryItem('phone', 1)
        xPlayer.showNotification('Welcome to the city!')
    end
end)

esx:playerDropped

Listen only. Fired when an xPlayer is removed: disconnect, logout or a stale session cleanup. Fired before the final save, so the xPlayer still exists.

NameTypeDescription
playerIdnumberServer id.
reasonstringDrop reason. esx_player_logout for logouts.
AddEventHandler('esx:playerDropped', function(playerId, reason)
    local xPlayer = ESX.GetPlayerFromId(playerId)
    if xPlayer then
        print(('%s left (%s)'):format(xPlayer.getName(), reason))
    end
end)

esx:playerSaved

Listen only. Fired after a player's row was written to the database (autosave every 10 minutes, on drop and manual saves).

NameTypeDescription
playerIdnumberServer id.
xPlayertableThe saved xPlayer.

esx:playerLogout

Server-only trigger. Trigger it from server code to log a player out of the current character. ESX saves and removes the xPlayer, then sends esx:onPlayerLogout to the client. Registered with AddEventHandler, so clients cannot trigger it.

NameTypeDescription
playerIdnumberServer id.
cbfunction?Called when the logout is done.
TriggerEvent('esx:playerLogout', playerId, function()
    print(('Player %s is back at character selection'):format(playerId))
end)

esx:onPlayerJoined

Internal. Starts loading the player.

  • Without multicharacter: client-sent net event with no arguments. ESX ignores it if the player is already loaded or loading.
  • With multicharacter: local server event (playerId, char, data) triggered by the multicharacter resource.

esx:onPlayerDropped

Internal. Local server event (playerId, reason, cb) that runs the ESX drop and save routine. Use esx:playerLogout instead.

esx:onPlayerSpawn

Client-sent (untrusted). Sent by the client after the first spawn. ESX only sets xPlayer.spawned = true.

Jobs and groups

esx:setJob

Listen only. Fired after xPlayer.setJob.

NameTypeDescription
playerIdnumberServer id.
jobtableNew job (name, label, grade, grade_name, grade_label, grade_salary, ...).
lastJobtablePrevious job.
AddEventHandler('esx:setJob', function(playerId, job, lastJob)
    if job.name == 'police' and lastJob.name ~= 'police' then
        exports.my_radio:GiveChannelAccess(playerId, 1)
    end
end)

esx:jobDataRefreshed

Listen only. Fired when a player's job data was rebuilt after the job definition changed (for example after ESX.RefreshJob).

NameTypeDescription
playerIdnumberServer id.
jobtableUpdated job.
lastJobtableJob before the refresh.

esx:setGroup

Listen only. Fired after xPlayer.setGroup.

NameTypeDescription
playerIdnumberServer id.
groupstringNew group.
lastGroupstringPrevious group.

esx:jobsRefreshed

Listen only. No arguments. Fired after all jobs were loaded from the database (ESX.RefreshJobs).

esx:jobRefreshed

Listen only. Fired after one job was reloaded with ESX.RefreshJob.

NameTypeDescription
jobNamestringJob name.
jobtableJob data with grades.

esx:jobRemoved

Listen only. Fired when a refreshed job no longer exists or has no grades. Players with that job are set to unemployed.

NameTypeDescription
jobNamestringRemoved job.
reasonstringmissing job or no job grades found.

esx:jobCreated

Listen only. Fired after ESX.CreateJob created a job.

NameTypeDescription
namestringJob name.
jobtableThe new entry in ESX.Jobs.

Money and inventory

esx:setAccountMoney / esx:addAccountMoney / esx:removeAccountMoney

Listen only. Fired by xPlayer.setAccountMoney, addAccountMoney and removeAccountMoney (also with ox_inventory).

NameTypeDescription
playerIdnumberServer id.
accountNamestringmoney, bank, black_money, ...
moneynumberFor set: the new balance. For add / remove: the amount changed.
reasonstring?Reason passed to the xPlayer method.
AddEventHandler('esx:addAccountMoney', function(playerId, account, amount, reason)
    if account == 'black_money' and amount >= 100000 then
        print(('[audit] %s received %s dirty money (%s)'):format(playerId, amount, reason or 'no reason'))
    end
end)

esx:onAddInventoryItem / esx:onRemoveInventoryItem

Listen only. Built-in inventory only. Fired after xPlayer.addInventoryItem / removeInventoryItem.

NameTypeDescription
playerIdnumberServer id.
itemNamestringItem name.
countnumberThe new total count of the item, not the amount added.

esx:playerInventoryCleared / esx:playerLoadoutCleared

Listen only. Fired by the /clearinventory and /clearloadout admin commands.

NameTypeDescription
xPlayertableThe target xPlayer (not an id).

Vehicles

esx:createdExtendedVehicle / esx:deletedExtendedVehicle

Listen only. Fired when an ExtendedVehicle object is created or deleted.

NameTypeDescription
vehicletableThe ExtendedVehicle object (has plate).

esx:changedExtendedVehiclePlate

Listen only. Fired after an ExtendedVehicle plate change.

NameTypeDescription
newPlatestringNew plate.
oldPlatestringPrevious plate.

Events sent by clients

Handled by es_extended

These net events are handled by the built-in inventory (not registered when Config.CustomInventory is set). ESX validates and rate-limits them. Do not register your own handlers that trust their arguments.

EventArgumentsWhat ESX does
esx:giveInventoryItemtarget, itemType, itemName, itemCountGives an item, money, weapon or ammo to a nearby player.
esx:removeInventoryItemitemType, itemName, itemCountDrops something on the ground as a pickup.
esx:useItemitemNameUses an item via ESX.UseItem if the player has it.
esx:onPickuppickupIdPicks up a pickup within 5 units.
esx:requestPickupsnoneSends nearby pickups to the client.
esx:updateWeaponAmmoweaponName, ammoCountSyncs ammo. Only lowers the stored ammo, never raises it.

Not handled by es_extended

The client sends these so other resources can use them. ESX itself registers no server handler. All arguments are client-controlled.

esx:onPlayerDeath

Field of dataTypeDescription
victimCoordstable{ x, y, z } rounded to 1 decimal.
killedByPlayerbooleanWhether another player caused the death.
deathCausenumberWeapon hash from GetPedCauseOfDeath.
killerCoordstable?Killer position (player kills only).
distancenumber?Distance to the killer (player kills only).
killerServerIdnumber?Killer server id (player kills only).
killerClientIdnumber?Killer client player index (player kills only).
server/main.lua
RegisterNetEvent('esx:onPlayerDeath', function(data)
    local victim = source
    if type(data) ~= 'table' or not data.killedByPlayer then return end

    local killer = tonumber(data.killerServerId)
    if not killer or not ESX.GetPlayerFromId(killer) then return end

    local distance = #(GetEntityCoords(GetPlayerPed(victim)) - GetEntityCoords(GetPlayerPed(killer)))
    if distance > 300.0 then return end -- claim does not match server state

    print(('Player %s was killed by %s'):format(victim, killer))
end)

Vehicle events

EventArguments
esx:enteringVehicleplate, seat, netId
esx:enteringVehicleAbortednone
esx:enteredVehicleplate, seat, displayName, netId
esx:exitedVehicleplate, seat, displayName, netId
RegisterNetEvent('esx:enteredVehicle', function(plate, seat, displayName, netId)
    local vehicle = NetworkGetEntityFromNetworkId(netId)
    if vehicle == 0 or GetVehiclePedIsIn(GetPlayerPed(source), false) ~= vehicle then return end

    print(('%s entered %s (%s) in seat %s'):format(source, displayName, plate, seat))
end)

netId is the local entity handle when the vehicle is not networked, so always check the result of NetworkGetEntityFromNetworkId.

Deprecated and removed

EventStatus
esx:getSharedObjectDeprecated. Still answers for old scripts. Use exports['es_extended']:getSharedObject().
esx:playerJumpingRemoved. Not fired in 1.16.

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