How to install your script on your ESX framework!
To get started, locate the ESX_STATUS file in the 'resources' folder on your server. When you open it, you will find a subfolder called SERVER.
Inside this folder, you will see a file called main.lua, where different snippets of code are stored.
If, by chance, you find a function called setPlayerStatus in your server files (ESX_STATUS), follow these instructions to configure it:
Replace the existing setPlayerStatus function in your code with the following function:
local function setPlayerStatus(xPlayer, data)
data = data and json.decode(data) or {}
for i=1, #data, 1 do
if data[i].name == "hunger" then
TriggerClientEvent("statusHunger",xPlayer.source,data[i].percent)
end
if data[i].name == "thirst" then
TriggerClientEvent("statusThirst",xPlayer.source,data[i].percent)
end
end
xPlayer.set('status', data)
ESX.Players[xPlayer.source] = data
TriggerClientEvent('esx_status:load', xPlayer.source, data)
end
By default, the existing function in your code ESX_STATUS will look like this:
RegisterServerEvent('esx_status:update')
AddEventHandler('esx_status:update', function(status)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
xPlayer.set('status', status) -- save to xPlayer for compatibility
ESX.Players[xPlayer.source] = status -- save locally for performance
end
end)
You will need to replace it with the code below:
RegisterServerEvent('esx_status:update')
AddEventHandler('esx_status:update', function(status)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
for i=1, #status, 1 do
if status[i].name == "hunger" then
TriggerClientEvent("statusHunger",xPlayer.source,status[i].percent)
end
if status[i].name == "thirst" then
TriggerClientEvent("statusThirst",xPlayer.source,status[i].percent)
end
end
xPlayer.set('status', status) -- save to xPlayer for compatibility
ESX.Players[xPlayer.source] = status -- save locally for performance
end
end)
If your ESX_STATUS does not have the setPlayerStatus function, configure it this way:
Override your default esx:playerLoaded event:
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(result)
local data = {}
if result[1].status then
data = json.decode(result[1].status)
end
xPlayer.set('status', data)
ESX.Players[xPlayer.source] = data
TriggerClientEvent('esx_status:load', playerId, data)
end)
end)
Using the code below:
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
MySQL.Async.fetchAll('SELECT status FROM users WHERE identifier = @identifier', {
['@identifier'] = xPlayer.identifier
}, function(result)
local data = {}
if result[1].status then
data = json.decode(result[1].status)
end
for i=1, #data, 1 do
if data[i].name == "hunger" then
TriggerClientEvent("statusHunger",playerId,data[i].percent)
end
if data[i].name == "thirst" then
TriggerClientEvent("statusThirst",playerId,data[i].percent)
end
end
xPlayer.set('status', data)
ESX.Players[xPlayer.source] = data
TriggerClientEvent('esx_status:load', playerId, data)
end)
end)
Once this is done, look for the esx_status:update event in this same file, which by default comes like this:
RegisterServerEvent('esx_status:update')
AddEventHandler('esx_status:update', function(status)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
xPlayer.set('status', status)
ESX.Players[xPlayer.source] = status -- save locally for performance
end
Now, replace it with the file provided below:
RegisterServerEvent('esx_status:update')
AddEventHandler('esx_status:update', function(status)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
for i=1, #status, 1 do
if status[i].name == "hunger" then
TriggerClientEvent("statusHunger",source,status[i].percent)
end
if status[i].name == "thirst" then
TriggerClientEvent("statusThirst",source,status[i].percent)
end
end
xPlayer.set('status', status)
ESX.Players[xPlayer.source] = status -- save locally for performance
end
end)
All ready, your ESX_STATUS is configured! All Hud information is working!
(except for stress, some frameworks do not have them installed by default in the file).
If it doesn't resolve
If it doesn't work, follow the steps in consumables which will work, in some bases the components update are not in the general core