diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index b989857fd..a4d1daa93 100644 --- a/[core]/es_extended/client/main.lua +++ b/[core]/es_extended/client/main.lua @@ -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()) diff --git a/[core]/es_extended/shared/config/main.lua b/[core]/es_extended/shared/config/main.lua index 2c3756053..7db1e472b 100644 --- a/[core]/es_extended/shared/config/main.lua +++ b/[core]/es_extended/shared/config/main.lua @@ -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 diff --git a/[core]/esx_multicharacter/client/modules/multicharacter.lua b/[core]/esx_multicharacter/client/modules/multicharacter.lua index 9ea9b9749..ef099f58e 100644 --- a/[core]/esx_multicharacter/client/modules/multicharacter.lua +++ b/[core]/esx_multicharacter/client/modules/multicharacter.lua @@ -272,7 +272,6 @@ function Multicharacter:PlayerLoaded(playerData, isNew, skin) TriggerServerEvent("esx:onPlayerSpawn") TriggerEvent("esx:onPlayerSpawn") - TriggerEvent("playerSpawned") TriggerEvent("esx:restoreLoadout") self:Reset()