Merge pull request #1509 from Kenshiin13/fix-player-death

fix(es_extended/client/main): fix player death race condition
This commit is contained in:
Kenshin13
2024-11-27 23:05:58 +01:00
committed by Ilias Rbayti
parent 9c39f38675
commit 292cb6c4f8
3 changed files with 18 additions and 14 deletions
+17 -13
View File
@@ -4,16 +4,6 @@ ESX.SecureNetEvent("esx:requestModel", function(model)
ESX.Streaming.RequestModel(model)
end)
local function ApplyMetadata(metadata)
if metadata.health then
SetEntityHealth(ESX.PlayerData.ped, metadata.health)
end
if metadata.armor and metadata.armor > 0 then
SetPedArmour(ESX.PlayerData.ped, metadata.armor)
end
end
RegisterNetEvent("esx:playerLoaded", function(xPlayer, _, skin)
ESX.PlayerData = xPlayer
@@ -34,8 +24,6 @@ RegisterNetEvent("esx:playerLoaded", function(xPlayer, _, skin)
ESX.PlayerLoaded = true
ApplyMetadata(ESX.PlayerData.metadata)
local timer = GetGameTimer()
while not HaveAllStreamingRequestsCompleted(ESX.PlayerData.ped) and (GetGameTimer() - timer) < 2000 do
Wait(0)
@@ -58,8 +46,10 @@ RegisterNetEvent("esx:playerLoaded", function(xPlayer, _, skin)
StartServerSyncLoops()
end)
local isFirstSpawn = true
ESX.SecureNetEvent("esx:onPlayerLogout", function()
ESX.PlayerLoaded = false
isFirstSpawn = true
end)
ESX.SecureNetEvent("esx:setMaxWeight", function(newMaxWeight)
@@ -72,7 +62,21 @@ local function onPlayerSpawn()
end
AddEventHandler("playerSpawned", onPlayerSpawn)
AddEventHandler("esx:onPlayerSpawn", onPlayerSpawn)
AddEventHandler("esx:onPlayerSpawn", function()
onPlayerSpawn()
if isFirstSpawn then
isFirstSpawn = false
if ESX.PlayerData.metadata.health and (ESX.PlayerData.metadata.health > 0 or Config.SaveDeathStatus) then
SetEntityHealth(ESX.PlayerData.ped, ESX.PlayerData.metadata.health)
end
if ESX.PlayerData.metadata.armor and ESX.PlayerData.metadata.armor > 0 then
SetPedArmour(ESX.PlayerData.ped, ESX.PlayerData.metadata.armor)
end
end
end)
AddEventHandler("esx:onPlayerDeath", function()
ESX.SetPlayerData("ped", PlayerPedId())
@@ -40,6 +40,7 @@ Config.LogPaycheck = false -- Logs paychecks to a nominated Discord channel via
Config.EnableSocietyPayouts = false -- pay from the society account that the player is employed at? Requirement: esx_society
Config.MaxWeight = 24 -- the max inventory weight without a backpack
Config.PaycheckInterval = 7 * 60000 -- how often to receive paychecks in milliseconds
Config.SaveDeathStatus = true -- Save the death status of a player
Config.EnableDebug = false -- Use Debug options?
Config.DefaultJobDuty = true -- A players default duty status when changing jobs
@@ -272,7 +272,6 @@ function Multicharacter:PlayerLoaded(playerData, isNew, skin)
TriggerServerEvent("esx:onPlayerSpawn")
TriggerEvent("esx:onPlayerSpawn")
TriggerEvent("playerSpawned")
TriggerEvent("esx:restoreLoadout")
self:Reset()