diff --git a/[core]/es_extended/client/functions.lua b/[core]/es_extended/client/functions.lua index 425693815..58252a0f9 100644 --- a/[core]/es_extended/client/functions.lua +++ b/[core]/es_extended/client/functions.lua @@ -1019,7 +1019,7 @@ function ESX.Game.SetVehicleProperties(vehicle, props) for extraId, enabled in pairs(props.extras) do extraId = tonumber(extraId) if extraId then - SetVehicleExtra(vehicle, extraId, enabled) + SetVehicleExtra(vehicle, extraId, not enabled) end end end diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index ea49ba17f..4dd156edc 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]/es_extended/shared/functions.lua b/[core]/es_extended/shared/functions.lua index fc342bce4..1a5d00900 100644 --- a/[core]/es_extended/shared/functions.lua +++ b/[core]/es_extended/shared/functions.lua @@ -164,3 +164,10 @@ function ESX.AssertType(...) return matches end + +---@param val unknown +function ESX.IsFunctionReference(val) + local typeVal = type(val) + + return typeVal == "function" or (typeVal == "table" and type(getmetatable(val)?.__call) == "function") +end \ No newline at end of file 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() diff --git a/[core]/esx_multicharacter/server/modules/multicharacter.lua b/[core]/esx_multicharacter/server/modules/multicharacter.lua index 923dd55e1..c43be5819 100644 --- a/[core]/esx_multicharacter/server/modules/multicharacter.lua +++ b/[core]/esx_multicharacter/server/modules/multicharacter.lua @@ -13,7 +13,7 @@ function Multicharacter:SetupCharacters(source) local identifier = Server:GetIdentifier(source) ESX.Players[identifier] = true - local slots = Database:GetPlayerSlots() + local slots = Database:GetPlayerSlots(identifier) identifier = Server.prefix .. "%:" .. identifier local rawCharacters = Database:GetPlayerInfo(identifier, slots) diff --git a/[core]/esx_skin/client/modules/menu.lua b/[core]/esx_skin/client/modules/menu.lua index e7ddcf1b4..410146d0e 100644 --- a/[core]/esx_skin/client/modules/menu.lua +++ b/[core]/esx_skin/client/modules/menu.lua @@ -46,7 +46,7 @@ function Menu:InsertElements() value = GetPedPropIndex(playerPed, self.components[i].componentId) end - local data = self.components[i] + local data = table.clone(self.components[i]) data.value = value data.type = "slider" data.max = self.maxValues[self.components[i].name] @@ -80,27 +80,39 @@ function Menu:Change(data, menu) Skin.zoomOffset = data.current.zoomOffset Skin.camOffset = data.current.camOffset - if skin[data.current.name] ~= data.current.value then - -- Change skin element - exports["skinchanger"]:Change(data.current.name, data.current.value) - skin[data.current.name] = data.current.value + if skin[data.current.name] == data.current.value then + return + end - local newData = {} + -- Change skin element + exports["skinchanger"]:Change(data.current.name, data.current.value) + skin[data.current.name] = data.current.value - for i = 1, #self.elements, 1 do - local component = self.components[i] + -- Texture variation changed. We don't have to update anything. + if data.current.textureof then + return + end - newData.max = type(component.max) == "function" and component.max(PlayerPedId(), skin) or component.max + -- Texture changed. Update variation max value. + for i = 1, #self.elements, 1 do + local element = self.elements[i] - if self.elements[i].textureof ~= nil and data.current.name == self.elements[i].textureof then - newData.value = 0 + if element.textureof == data.current.name then + local component = self.components[i] + + if ESX.IsFunctionReference(component.max) then + self.elements[i].max = component.max(PlayerPedId(), skin) end + self.elements[i].value = 0 - menu.update({ name = self.elements[i].name }, newData) - end + -- Change skin element + exports["skinchanger"]:Change(element.name, 0) + skin[element.name] = data.current.value - self.elements = newData - menu.refresh() + menu.update({ name = self.elements[i].name }, self.elements[i]) + menu.refresh() + break + end end end diff --git a/[core]/skinchanger/config.lua b/[core]/skinchanger/config.lua index 2401b9c73..1d5a0fed5 100644 --- a/[core]/skinchanger/config.lua +++ b/[core]/skinchanger/config.lua @@ -237,6 +237,7 @@ Config.Components = { min = 0, zoomOffset = 0.6, camOffset = 0.65, + textureof = "hair_1", max = function(playerPed, Character) return GetNumberOfPedTextureVariations(playerPed, 2, Character["hair_1"]) - 1 end