mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
improvement(esx/client): Send both new and old value of playerdata with event; properly set job/grade display for hud
- Makes the event a viable alternative to esx:setJob as we can compare if the value has changed. - Formatting for job/grade would not update when going to or from unemployed
This commit is contained in:
@@ -41,9 +41,12 @@ ESX.GetPlayerData = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
ESX.SetPlayerData = function(key, val)
|
ESX.SetPlayerData = function(key, val)
|
||||||
|
local current = ESX.PlayerData[key]
|
||||||
ESX.PlayerData[key] = val
|
ESX.PlayerData[key] = val
|
||||||
if key ~= 'inventory' and key ~= 'loadout' then
|
if key ~= 'inventory' and key ~= 'loadout' then
|
||||||
TriggerEvent('esx:setPlayerData', key, val)
|
if type(val) == 'table' or val ~= current then
|
||||||
|
TriggerEvent('esx:setPlayerData', key, val, current)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ Citizen.CreateThread(function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('esx:playerLoaded')
|
RegisterNetEvent('esx:playerLoaded')
|
||||||
AddEventHandler('esx:playerLoaded', function(playerData, isNew, skin)
|
AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
|
||||||
ESX.PlayerLoaded = true
|
ESX.PlayerLoaded = true
|
||||||
ESX.PlayerData = playerData
|
ESX.PlayerData = xPlayer
|
||||||
|
|
||||||
FreezeEntityPosition(PlayerPedId(), true)
|
FreezeEntityPosition(PlayerPedId(), true)
|
||||||
|
|
||||||
@@ -20,10 +20,10 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew, skin)
|
|||||||
Citizen.Wait(3000)
|
Citizen.Wait(3000)
|
||||||
else
|
else
|
||||||
exports.spawnmanager:spawnPlayer({
|
exports.spawnmanager:spawnPlayer({
|
||||||
x = playerData.coords.x,
|
x = ESX.PlayerData.coords.x,
|
||||||
y = playerData.coords.y,
|
y = ESX.PlayerData.coords.y,
|
||||||
z = playerData.coords.z + 0.25,
|
z = ESX.PlayerData.coords.z + 0.25,
|
||||||
heading = playerData.coords.heading,
|
heading = ESX.PlayerData.coords.heading,
|
||||||
model = `mp_m_freemode_01`,
|
model = `mp_m_freemode_01`,
|
||||||
skipFade = false
|
skipFade = false
|
||||||
}, function()
|
}, function()
|
||||||
@@ -53,20 +53,19 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew, skin)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Config.EnableHud then
|
if Config.EnableHud then
|
||||||
for k,v in ipairs(playerData.accounts) do
|
for k,v in ipairs(ESX.PlayerData.accounts) do
|
||||||
local accountTpl = '<div><img src="img/accounts/' .. v.name .. '.png"/> {{money}}</div>'
|
local accountTpl = '<div><img src="img/accounts/' .. v.name .. '.png"/> {{money}}</div>'
|
||||||
ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, {money = ESX.Math.GroupDigits(v.money)})
|
ESX.UI.HUD.RegisterElement('account_' .. v.name, k, 0, accountTpl, {money = ESX.Math.GroupDigits(v.money)})
|
||||||
end
|
end
|
||||||
|
|
||||||
local jobTpl = '<div>{{job_label}} - {{grade_label}}</div>'
|
local jobTpl = '<div>{{job_label}}{{grade_label}}</div>'
|
||||||
|
|
||||||
if playerData.job.grade_label == '' or playerData.job.grade_label == playerData.job.label then
|
local gradeLabel = ESX.PlayerData.job.grade_label ~= ESX.PlayerData.job.label and ESX.PlayerData.job.grade_label or ''
|
||||||
jobTpl = '<div>{{job_label}}</div>'
|
if gradeLabel ~= '' then gradeLabel = ' - '..gradeLabel end
|
||||||
end
|
|
||||||
|
ESX.UI.HUD.RegisterElement('job', #ESX.PlayerData.accounts, 0, jobTpl, {
|
||||||
ESX.UI.HUD.RegisterElement('job', #playerData.accounts, 0, jobTpl, {
|
job_label = ESX.PlayerData.job.label,
|
||||||
job_label = playerData.job.label,
|
grade_label = gradeLabel
|
||||||
grade_label = playerData.job.grade_label
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
StartServerSyncLoops()
|
StartServerSyncLoops()
|
||||||
@@ -97,7 +96,6 @@ AddEventHandler('skinchanger:modelLoaded', function()
|
|||||||
while not ESX.PlayerLoaded do
|
while not ESX.PlayerLoaded do
|
||||||
Citizen.Wait(100)
|
Citizen.Wait(100)
|
||||||
end
|
end
|
||||||
|
|
||||||
TriggerEvent('esx:restoreLoadout')
|
TriggerEvent('esx:restoreLoadout')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -225,9 +223,11 @@ end)
|
|||||||
RegisterNetEvent('esx:setJob')
|
RegisterNetEvent('esx:setJob')
|
||||||
AddEventHandler('esx:setJob', function(Job)
|
AddEventHandler('esx:setJob', function(Job)
|
||||||
if Config.EnableHud then
|
if Config.EnableHud then
|
||||||
|
local gradeLabel = Job.grade_label ~= Job.label and Job.grade_label or ''
|
||||||
|
if gradeLabel ~= '' then gradeLabel = ' - '..gradeLabel end
|
||||||
ESX.UI.HUD.UpdateElement('job', {
|
ESX.UI.HUD.UpdateElement('job', {
|
||||||
job_label = Job.label,
|
job_label = Job.label,
|
||||||
grade_label = Job.grade_label
|
grade_label = gradeLabel
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
ESX.SetPlayerData('job', Job)
|
ESX.SetPlayerData('job', Job)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
ESX = exports['es_extended']:getSharedObject()
|
ESX = exports['es_extended']:getSharedObject()
|
||||||
|
|
||||||
if not IsDuplicityVersion() then -- Only register this event for the client
|
if not IsDuplicityVersion() then -- Only register this event for the client
|
||||||
AddEventHandler('esx:setPlayerData', function(key, val)
|
AddEventHandler('esx:setPlayerData', function(key, val, last)
|
||||||
if GetInvokingResource() == 'es_extended' then
|
if GetInvokingResource() == 'es_extended' then
|
||||||
ESX.PlayerData[key] = val
|
ESX.PlayerData[key] = val
|
||||||
if OnPlayerData ~= nil then OnPlayerData(key, val) end
|
if OnPlayerData ~= nil then OnPlayerData(key, val, last) end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user