Functions
This topic includes most functions that are existing in ESX.
IsPlayerLoaded
This function will return a bool
if the player has sucessfully loaded.
This should be checked before manipulating or checking data of the player.
Example
while not ESX.IsPlayerLoaded() do
Wait(250)
end
print('player is loaded')
GetPlayerData
This function simply returns ESX.PlayerData.
Example
local playerData = ESX.GetPlayerData()
print("The client's identifier: " .. playerData.identifier)
SearchInventory
Can be used to check for items in the player’s Inventory
Arguments
- items:
string
or table- A string or table containing the items.
Example
local items = ESX.SearchInventory({'bread', 'water'}, true)
for key, value in pairs(items) do
print(string.format(('You have %sx %s'), value, key))
end
local item = ESX.SearchInventory('bread')
local count = item.count
Output
- usable:
boolean
- If the item is usable or not.
- count:
number
- How many of the item is found.
- canRemove:
number
- This returns 1 when it can be removed otherwise 0
- label:
string
- The item label that is shown in the inventory.
- name:
string
- The name of the item
- rare:
number
- Is the item rare?
SetPlayerData
This function you can set playerdata with.
Arguments
- key:
string
- The key of the playerdata.
- value:
value
- The data to be set.
Example
ESX.SetPlayerData('test', 'a nice test')
print(ESX.PlayerData.test) -- this will print 'a nice test'
Context
ESX has a context system by default as a seperate resource. See more at esx_context
Progressbar
ESX has a progress bar system by default as a seperate resource. See more at esx_progressbar
ShowNotification
ESX has a custom notification system as a seperate resource. See more at esx_notify
TextUI
ESX has a Text UI system by default as a seperate resource. See more at esx_textui
ShowAdvancedNotification
This function will show a default GTA 5 notification
Arguments
- sender:
string
- The notification title.
- subject:
string
- The notification subtitle
- msg:
string
- The notification message
- textureDict:
string
- The texture dictionary for the icon
- iconType:
string
- The icon type, see the list below.
- flash?:
boolean
(Default:false
)- According to the fivem natives, this var never works no matter what.
- saveToBrief?:
boolean
(Default:false
)- Makes the notification appear in the “Pause Menu > Info/Brief > Notifications” section.
- hudColorIndex?:
number
- The background color for the notification.
Icon types
- Chat Box
- Add Friend Request
- Nothing
- Nothing
- Nothing
- Right Jumping Arrow
- RP Icon
- $ Icon
Example
local handle = RegisterPedheadshot(PlayerPedId())
while not IsPedheadshotReady(handle) or not IsPedheadshotValid(handle) do
Wait(0)
end
local txd = GetPedheadshotTxdString(handle)
local title = GetPlayerName(PlayerId())
local subtitle = 'Private Message'
local iconType = 0
ESX.ShowAdvancedNotification(title, subtitle, 'this is the message that we send to you', txd, iconType, false, true, 6)
ShowHelpNotification
This function shows a help notification on the top left of the screen. Either needs to be ran every frame or a duration can be optionally set.
Arguments
- msg:
string
- The message content.
- thisFrame?:
boolean
(Default:false
)- Should it only be displayed this frame.
- beep?:
boolean
(Default:false
)- Should it play a beep sound?
- duration?:
number
(Default:-1
)- The duration of how long this should show.
Example
RegisterCommand('help', function (source, args, raw)
ESX.ShowHelpNotification("We won't give you help, we are truly not sorry.", false, true, 3500)
end)
ShowFloatingHelpNotification
This function shows a floating help notification, this is needs to be ran every millisecond.
Arguments
- msg:
string
- The floating message.
- coords:
vector3
- The coords of where it should be displayed
Example
local coords = vector3(0, 0, 0)
CreateThread(function()
while true do
ESX.ShowFloatingHelpNotification('ESX is so cool', coords)
Wait(0)
end
end)
HashString
This function will turn a string into a (rockstar) hash. Which for example could be used to display a key of a custom keybind.
Arguments
- str:
string
- The string that should be hashed.
Example
RegisterCommand('howtosit', function (source, args, raw)
local inputMapping = string.format("~INPUT_%s~"):format(ESX.HashString("sit"))
ESX.ShowHelpNotification("You can sit down using "..inputMapping , false, true, 3500)
end)
RegisterInput
This functions registers an input.
Arguments
- command_name:
string
- The name of the command that should be executed.
- label:
string
- The label of the keybind.
- input_group:
string
- The input group.
- key:
string
- The key used for the keybind.
- on_press:
function
- The function that will be executed when pressing the key.
- on_release?:
function
- The function that will be executed when releasing the key.
Example
ESX.RegisterInput('testinput', 'Test', 'keyboard', 'f6', function()
print('pressed')
end, function()
print('released')
end)
TriggerServerCallback
This function trigger a previously registered server callback
Arguments
- name:
string
- The server callback’s name.
- cb:
function
- The callback function passed from the server.
- …
- The arguments that should be passed to the server callback.
ESX.TriggerServerCallback('myScript:getMeme', function(cb)
print(cb) --output: "Meme data string"
end)
Game
Functions that modify the client some way or another.
GetPedMugshot
This function takes a mugshot from given ped and returns it as a texture.
Arguments
- ped:
ped
object- The ped you want a mugshot from.
- transparent?:
boolean
(Default:false
)- Should the picture be transparent?
Returns
- mugshot:
string
- The mugshot
- txd:
string
- The mugshot texture as base64 string
Example
local ped = PlayerPedId()
local mugshot, txd = ESX.Game.GetPedMugshot(ped, true)
Teleport
Teleports the given entity to the given coords and triggers the callback once finished.
Arguments
- entity:
entity
handle- The entity to teleport.
- coords:
vector3
|vector4
- The coords the entity should be teleported to.
- cb?:
function
- The callback function that will be triggered after.
Example
local entity = PlayerPedId()
ESX.Game.Teleport(entity, vector3(0,0,0), function()
print('player is teleported')
end)
SpawnObject
This function will spawn an object with given model at given coords. And can be networked.
Arguments
- model:
string
or hash- the model name or hash of the object
- coords:
vector3
- where the object needs to be spawned
- cb?:
function
- the callback function
- networked?:
boolean
(Default:true
)- if the object needs to be networked or not
Example
local coords = GetEntityCoords(PlayerPedId())
ESX.Game.SpawnObject('prop_tool_bluepnt', coords, function()
print('object is spawned')
end, true)
SpawnLocalObject
This function will spawn a local object with given model at given coords.
This function only exits for backwards compatibility. You should use ESX.Game.SpawnObject(model, coords, cb, false)
instead.
Arguments
- model:
string
|number
- The model name or hash of the object.
- coords:
vector3
- Where the object needs to be spawned.
- cb?:
function
- The callback function.
Example
local coords = GetEntityCoords(PlayerPedId())
ESX.Game.SpawnObject('prop_tool_bluepnt', coords, function()
print('object is spawned')
end)
DeleteVehicle
This function will delete given vehicle.
Arguments
- vehicle:
number
(vehicle handle)- The vehicle that should be removed
Example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
ESX.Game.DeleteVehicle(vehicle)
DeleteObject
This function will delete given object.
Arguments
- object:
number
(object handle)- the object that needs to be removed
Example
ESX.Game.DeleteObject(object)
SpawnVehicle
This function will spawn given vehicle with given model at given coords. And can be networked.
Arguments
- vehicleModel:
string
|number
- The model name or hash.
- coords:
vector3
- Where the vehicle needs to be spawned.
- heading:
number
- The heading of the vehicle
- cb:
function
- The callback function
- networked:
boolean
- If the vehicle should to be networked or local
Example
local coords = GetEntityCoords(PlayerPedId())
ESX.Game.SpawnVehicle('blista', coords, 0.0, function(vehicle)
print(vehicle)
end, true)
SpawnLocalVehicle
This function will spawn given vehicle with model at given coords.
This function only exits for backwards compatibility. You should use ESX.Game.SpawnVehicle(model, coords, heading, cb, false)
instead.
Arguments
- vehicleModel:
string
|number
- The model name or hash.
- coords:
vector3
- Where the vehicle needs to be spawned.
- heading:
number
- The heading of the vehicle
- cb:
function
- The callback function.
Example
ESX.Game.SpawnLocalVehicle('blista', coords, 0.0, function(vehicle)
print(vehicle)
end)
IsVehicleEmpty
This function will return a boolean
if the vehicle is empty.
Arguments
- vehicle:
number
(vehicle handle)- The vehicle you want to check
Example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), true)
local isEmpty = ESX.Game.IsVehicleEmpty(vehicle)
if isEmpty then
print('Vehicle is empty!')
end
GetObjects
Returns all objects the client has currently loaded.
This function only exits for backwards compatibility. You could use GetGamePool('CObject')
instead.
Example
local objects = ESX.Game.GetObjects()
for i=1, #objects do
local object = objects[i]
end
GetPeds
Returns all peds the client has currently loaded.
Arguments
- onlyOtherPeds:
boolean
- Should the own ped be filtered out?
Example
local objects = ESX.Game.GetPeds(true)
print('We found ' .. #objects .. ' peds other then you!')
GetVehicles
Returns all vehicles the client has loaded.
This function only exits for backwards compatibility. You could use GetGamePool('CVehicle')
instead.
Example
local vehicles = ESX.Game.GetVehicles()
for i=1, #vehicles do
local vehicle = vehicles[i]
end
GetPlayers
Returns all players the client has currently loaded.
Arguments
- onlyOtherPlayers:
boolean
- Should the own player be filtered out?
- returnPeds?:
boolean
(Default:false
)- Should the value be the ped? Otherwise player id. (Value always ped with
returnKeyValue
true)
- Should the value be the ped? Otherwise player id. (Value always ped with
GetClosestEntity
Returns the closest entity’s handle and distance to the object in the given table.
Arguments
- entities:
table
- The entities to filter through
- isPlayerEntities:
boolean
- Is the table filled with players?
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- filter:
table
- Only look for specific value (model / player id)
Returns
- closestObject:
number
(object handle)- The handle of the closest object.
- closestObjectDistance:
number
- The distance to the object.
Example
local coords = GetEntityCoords(PlayerPedId())
local closestObject, distance = ESX.Game.GetClosestObject(coords, {
["prop_weed_01"] = true,
["prop_weed_02"] = true,
})
GetClosestObject
Returns the closest object’s handle and distance to the object.
Arguments
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- modelFilter:
table
- Only look for specific models
Returns
- closestObject:
number
(object handle)- The handle of the closest object.
- closestObjectDistance:
number
- The distance to the object.
Example
local coords = GetEntityCoords(PlayerPedId())
local closestObject, distance = ESX.Game.GetClosestObject(coords, {
["prop_weed_01"] = true,
["prop_weed_02"] = true,
})
GetClosestPed
Returns the closest ped’s handle and distance to the ped.
Arguments
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- modelFilter:
table
- Only look for specific models
Returns
- closestPed:
number
(ped handle)- The handle of the closest ped.
- closestPedDistance:
number
- The distance to the ped.
Example
local coords = GetEntityCoords(PlayerPedId())
local closestPed, distance = ESX.Game.GetClosestPed(coords, {
["a_f_m_beach_01"] = true,
["a_m_y_hipster_02"] = true,
})
GetClosestPlayer
Returns the closest player’s id and distance to the player.
Arguments
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- modelFilter:
table
- Only look for specific models
Returns
- closestPed:
number
(ped handle)- The player id of the closest player.
- closestPedDistance:
number
- The distance to the player.
Example
local coords = GetEntityCoords(PlayerPedId())
local closestPlayer, distance = ESX.Game.GetClosestPlayer(coords, {
[5] = true,
[9] = true,
})
GetClosestVehicle
Returns the closest vehicle’s handle and distance to the vehicle.
Arguments
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- modelFilter:
table
- Only look for specific models
Returns
- closestVehicle:
number
(ped handle)- The handle of the closest vehicle.
- closestVehicleDistance:
number
- The distance to the vehicle.
Example
local coords = GetEntityCoords(PlayerPedId())
local closestVehicle, distance = ESX.Game.GetClosestVehicle(coords, {
["t20"] = true,
["zentorno"] = true,
})
GetPlayersInArea
Returns all players in specified radius.
Arguments
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- maxDistance:
table
- The radius to search in.
Example
local coords = GetEntityCoords(PlayerPedId())
local playersInArea = ESX.Game.GetPlayersInArea(coords, 20)
print('Found ' .. #playersInArea .. ' player in area')
GetVehiclesInArea
Returns all vehicles in speicified radius.
Arguments
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- maxDistance:
table
- The radius to search in.
Example
local coords = GetEntityCoords(PlayerPedId())
local vehiclesInArea = ESX.Game.GetVehiclesInArea(coords, 20)
print('Found ' .. #vehiclesInArea .. ' vehicles in area')
IsSpawnPointClear
Returns a boolean
saying if the given space is clear of other vehicles.
Arguments
- coords:
vector
(Default: Player coords)- Coordinates to search at.
- maxDistance:
table
- The radius to search in.
Example
RegisterCommand('spawnCoolVehicle', function()
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local heading = GetEntityHeading(ped)
if ESX.Game.IsSpawnPointClear(coords, 10) then
ESX.Game.SpawnVehicle('t20', coords, heading, function(vehicle)
print(vehicle)
end, true)
end
end)
GetVehicleInDirection
Returns vehicle in front of player.
Returns
- vehicle:
number
(vehicle handle)- The handle of the vehicle.
- coords:
number
- The coords of the vehicle.
Example
local vehicle, coords = ESX.Game.GetVehicleInDirection()
if vehicle then
print('Vehicle found!')
print('It has ' .. GetEntityHealth(vehicle) .. ' health!')
end
GetVehicleProperties
Returns different properties about the given vehicle.
Arguments
- vehicle:
number
(vehicle handle)- The handle of the vehicle.
Returns
- model:
string
- The model of the vehicle.
- doorsBroken:
table
- The vehicle doors and if they are broken.
- windowsBroken:
table
- The vehicle windows and if they are broken.
- tyreBurst:
table
- The vehicle tyres and if they are broken.
- tyresCanBurst:
boolean
- Can the tyres burst?
- plate:
string
- The vehicle plate.
- wheels:
number
- The wheel type of the vehicle.
- windowTint:
number
- The window tint of the vehicle.
- neonEnabled:
boolean
- Does the vehicle have neons?
- extras:
table
- The extras of the vehicle
- tyreSmokeColor:
table
- The color of the tyre smoke
-
modSpoilers:
number
-
modFrontBumper:
number
-
modRearBumper:
number
-
modSideSkirt:
number
-
modExhaust:
number
-
modFrame:
number
-
modGrille:
number
-
modHood:
number
-
modFender:
number
-
modRightFender:
number
-
modRoof:
number
-
modRoofLivery:
number
-
modEngine:
number
-
modBrakes:
number
-
modTransmisson:
number
-
modHorns:
number
-
modSuspension:
number
-
modArmor:
number
-
modTurbo:
number
-
modSmokeEnabled:
number
-
modXenon:
number
-
modFrontWheels:
number
-
modCustomFrontWheels:
number
-
modBackWheels:
number
-
modCustomBackWheels:
number
-
modPlateHolder:
number
-
modVanityPlate:
number
-
modTrimA:
number
-
modOrnaments:
number
-
modDashboard:
number
-
modDial:
number
-
modDoorSpeaker:
number
-
modSeats:
number
-
modSteeringWheel:
number
-
modShifterLeavers:
number
-
modAPlate:
number
-
modSpeakers:
number
-
modTrunk:
number
-
modHydrolic:
number
-
modEngineBlock:
number
-
modAirFilter:
number
-
modStruts:
number
-
modArchCover:
number
-
modAerials:
number
-
modTrimB:
number
-
modTank:
number
-
modWindows:
number
-
modLivery:
number
-
modLightbar:
number
Example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local properties = ESX.Game.GetVehicleProperties(vehicle)
print("The vehicle has " .. #properties.doorsBroken .. " doors broken.")
SetVehicleProperties
This function sets properties to the vehicle.
Arguments
- vehicle:
number
(vehicle handle)- The handle of the vehicle.
Example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
ESX.Game.SetVehicleProperties(vehicle, {
["plate"] = "ABCD1234",
["fuelLevel"] = 100.0
})
DrawText3D
This function draws a 3D Text
Arguments
- coords:
vector
- The coords of where it should be displayed.
- text:
string
- Text that should be displayed.
- size?:
string
(Default:1
)- What size the 3D Text should have
- font?:
string
(Default:0
)- The font it should have (ID)
Example
CreateThread(function()
while true do
local coords = GetEntityCoords(PlayerPedId())
ESX.Game.Utils.DrawText3D(coords, "This person is a really cool guy")
Wait(0)
end
end)
GetAccount
Returns the player’s specified account
Arguments
- account:
string
- The account name.
Example
local account = ESX.GetAccount('money')
print("The client has " .. account.money .. ' currently in his purse!')
ShowInventory
Opens the player’s inventory. (Default es_extended inventory)
GetVehicleType
Returns the vehicle type of the given model.
Arguments
Returns
- vehicleType:
string
- The type of the vehicle.
Vehicle Types
- bike
- trailer
- bike
- boat
- heli
- plane
- train