From 78ad6c29324aaaaf7bb8e2e72300feb727a1ef2a Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Thu, 6 Feb 2025 23:33:31 -0500 Subject: [PATCH] attempt to clean up clothing start --- lib/client/utility.lua | 11 ++-- modules/clothing/_default/client.lua | 42 +++++++++++--- modules/clothing/_default/server.lua | 31 ++++++++--- modules/clothing/esx_skin/client.lua | 6 -- modules/clothing/esx_skin/server.lua | 24 -------- modules/clothing/fivem-appearance/client.lua | 21 ++++--- modules/clothing/fivem-appearance/server.lua | 19 ------- .../clothing/illenium-appearance/client.lua | 9 +-- .../clothing/illenium-appearance/server.lua | 19 ------- modules/clothing/qb-clothing/client.lua | 55 +++++++++---------- modules/clothing/qb-clothing/server.lua | 24 +------- 11 files changed, 106 insertions(+), 155 deletions(-) delete mode 100644 modules/clothing/esx_skin/server.lua delete mode 100644 modules/clothing/fivem-appearance/server.lua delete mode 100644 modules/clothing/illenium-appearance/server.lua diff --git a/lib/client/utility.lua b/lib/client/utility.lua index 07d9897..63d6fb3 100644 --- a/lib/client/utility.lua +++ b/lib/client/utility.lua @@ -133,10 +133,12 @@ end Utility.GetEntitySkinData = function(entity) local skinData = {} - skinData.clothing = {} for i = 0, 11 do skinData.clothing[i] = {GetPedDrawableVariation(entity, i), GetPedTextureVariation(entity, i)} end + for i = 0, 13 do + skinData.props[i] = {GetPedPropIndex(entity, i), GetPedPropTextureIndex(entity, i)} + end return skinData end @@ -144,6 +146,9 @@ Utility.SetEntitySkinData = function(entity, skinData) for i = 0, 11 do SetPedComponentVariation(entity, i, skinData.clothing[i][1], skinData.clothing[i][2], 0) end + for i = 0, 13 do + SetPedPropIndex(entity, i, skinData.props[i][1], skinData.props[i][2], 0) + end return true end @@ -160,10 +165,6 @@ Utility.ReloadSkin = function() return true end -Utility.RestoreAppearance = function(data) - return Utility.SetEntitySkinData(cache.ped, data) -end - Utility.HelpText = function(text, duration) AddTextEntry(text, text) BeginTextCommandDisplayHelp(text) diff --git a/modules/clothing/_default/client.lua b/modules/clothing/_default/client.lua index bbf6d70..9d72391 100644 --- a/modules/clothing/_default/client.lua +++ b/modules/clothing/_default/client.lua @@ -1,23 +1,49 @@ Clothing = Clothing or {} -StoredOldClothing = {} - -Clothing.SetAppearance = function(clothingData) +ClothingBackup = {} +Clothing.SetAppearance = function(data) + ClothingBackup = Clothing.GetAppearance() + Utility.SetEntitySkinData(cache.ped, data) return true end Clothing.GetAppearance = function() - local clothing = {} - - return clothing + return Utility.GetEntitySkinData(cache.ped) end Clothing.RestoreAppearance = function() - + Utility.SetEntitySkinData(cache.ped, ClothingBackup) return true end Clothing.ReloadSkin = function() + Utility.SetEntitySkinData(cache.ped, ClothingBackup) + return true +end -end \ No newline at end of file + + +Clothing.UpdateAppearanceBackup = function(data) + ClothingBackup = data +end + +RegisterNetEvent('community_bridge:client:updateClothingBackup', function(skindata) + ClothingBackup = skindata +end) + +RegisterNetEvent('community_bridge:client:SetAppearance', function(data) + Clothing.SetAppearance(data) +end) + +RegisterNetEvent('community_bridge:client:GetAppearance', function() + Clothing.GetAppearance() +end) + +RegisterNetEvent('community_bridge:client:RestoreAppearance', function() + Clothing.RestoreAppearance() +end) + +RegisterNetEvent('community_bridge:client:ReloadSkin', function() + Clothing.ReloadSkin() +end) \ No newline at end of file diff --git a/modules/clothing/_default/server.lua b/modules/clothing/_default/server.lua index c0c1787..2ec1460 100644 --- a/modules/clothing/_default/server.lua +++ b/modules/clothing/_default/server.lua @@ -1,17 +1,32 @@ Clothing = Clothing or {} Clothing.SetAppearance = function(src, data) - --wip -end - -Clothing.GetAppearance = function(src) - --wip + TriggerClientEvent('community_bridge:client:SetAppearance', src, data) end Clothing.RestoreAppearance = function(src) - --wip + TriggerClientEvent('community_bridge:client:RestoreAppearance', src) end Clothing.ReloadSkin = function(src) - --wip -end \ No newline at end of file + TriggerClientEvent('community_bridge:client:ReloadSkin', src) +end + + + + +RegisterNetEvent('community_bridge:client:SetAppearance', function(data) + Clothing.SetAppearance(data) +end) + +RegisterNetEvent('community_bridge:client:GetAppearance', function() + Clothing.GetAppearance() +end) + +RegisterNetEvent('community_bridge:client:RestoreAppearance', function() + Clothing.RestoreAppearance() +end) + +RegisterNetEvent('community_bridge:client:ReloadSkin', function() + Clothing.ReloadSkin() +end) \ No newline at end of file diff --git a/modules/clothing/esx_skin/client.lua b/modules/clothing/esx_skin/client.lua index 8cf5681..d3261e0 100644 --- a/modules/clothing/esx_skin/client.lua +++ b/modules/clothing/esx_skin/client.lua @@ -2,12 +2,6 @@ if GetResourceState('esx_skin') ~= 'started' then return end Clothing = Clothing or {} -StoredOldClothing = {} - -RegisterNetEvent('community_bridge:client:updateStoredClothing', function(skindata) - StoredOldClothing = skindata -end) - local clothingData = { male = { components = { diff --git a/modules/clothing/esx_skin/server.lua b/modules/clothing/esx_skin/server.lua deleted file mode 100644 index b4fad63..0000000 --- a/modules/clothing/esx_skin/server.lua +++ /dev/null @@ -1,24 +0,0 @@ -if GetResourceState('esx_skin') ~= 'started' then return end - -RegisterNetEvent("esx_skin:save", function(skin) - local src = source - TriggerClientEvent('community_bridge:client:updateStoredClothing', src, skin) -end) - -Clothing = Clothing or {} - -Clothing.SetAppearance = function(src, data) - --wip -end - -Clothing.GetAppearance = function(src) - --wip -end - -Clothing.RestoreAppearance = function(src) - --wip -end - -Clothing.ReloadSkin = function(src) - --wip -end \ No newline at end of file diff --git a/modules/clothing/fivem-appearance/client.lua b/modules/clothing/fivem-appearance/client.lua index cb271c5..96dc98f 100644 --- a/modules/clothing/fivem-appearance/client.lua +++ b/modules/clothing/fivem-appearance/client.lua @@ -1,17 +1,15 @@ if GetResourceState('fivem-appearance') ~= 'started' then return end - Clothing = Clothing or {} -StoredOldClothing = {} - -Clothing.SetAppearance = function(clothingData) +Clothing.SetAppearance = function(data) + local clothing = {} if GetEntityModel(cache.ped) == `mp_m_freemode_01` then - clothingData = clothingData.male + clothing = data.male else - clothingData = clothingData.female + clothing = data.female end - StoredOldClothing = exports['fivem-appearance']:getPedAppearance(cache.ped) - exports['fivem-appearance']:setPedAppearance(cache.ped, clothingData) + ClothingBackup = exports['fivem-appearance']:getPedAppearance(cache.ped) + exports['fivem-appearance']:setPedAppearance(cache.ped, clothing) return true end @@ -20,9 +18,14 @@ Clothing.GetAppearance = function() end Clothing.RestoreAppearance = function() - return exports['fivem-appearance']:setPedAppearance(cache.ped, StoredOldClothing) + if not next(ClothingBackup) then + return false + end + exports['fivem-appearance']:setPedAppearance(cache.ped, ClothingBackup) + return true end Clothing.ReloadSkin = function() TriggerEvent("fivem-appearance:client:reloadSkin", true) + return true end \ No newline at end of file diff --git a/modules/clothing/fivem-appearance/server.lua b/modules/clothing/fivem-appearance/server.lua deleted file mode 100644 index cf1fc19..0000000 --- a/modules/clothing/fivem-appearance/server.lua +++ /dev/null @@ -1,19 +0,0 @@ -if GetResourceState('fivem-appearance') ~= 'started' then return end - -Clothing = Clothing or {} - -Clothing.SetAppearance = function(src, data) - --wip -end - -Clothing.GetAppearance = function(src) - --wip -end - -Clothing.RestoreAppearance = function(src) - --wip -end - -Clothing.ReloadSkin = function(src) - --wip -end \ No newline at end of file diff --git a/modules/clothing/illenium-appearance/client.lua b/modules/clothing/illenium-appearance/client.lua index 5c27b46..92736ab 100644 --- a/modules/clothing/illenium-appearance/client.lua +++ b/modules/clothing/illenium-appearance/client.lua @@ -1,9 +1,6 @@ if GetResourceState('illenium-appearance') ~= 'started' then return end - Clothing = Clothing or {} -StoredOldClothing = {} - Clothing.SetAppearance = function(clothingData) local clothing = {} if GetEntityModel(cache.ped) == `mp_m_freemode_01` then @@ -15,7 +12,7 @@ Clothing.SetAppearance = function(clothingData) clothing.props = exports['illenium-appearance']:getPedProps(cache.ped) Prints.Debug(json.encode(clothingData, {indent = true})) - StoredOldClothing = clothing + ClothingBackup = clothing exports['illenium-appearance']:setPedComponents(cache.ped, clothingData.components) exports['illenium-appearance']:setPedProp(cache.ped, clothingData.props) return true @@ -35,8 +32,8 @@ Clothing.GetAppearance = function() end Clothing.RestoreAppearance = function() - exports['illenium-appearance']:setPedComponents(cache.ped, StoredOldClothing.components) - exports['illenium-appearance']:setPedProp(cache.ped, StoredOldClothing.props) + exports['illenium-appearance']:setPedComponents(cache.ped, ClothingBackup.components) + exports['illenium-appearance']:setPedProp(cache.ped, ClothingBackup.props) return true end diff --git a/modules/clothing/illenium-appearance/server.lua b/modules/clothing/illenium-appearance/server.lua deleted file mode 100644 index 8325041..0000000 --- a/modules/clothing/illenium-appearance/server.lua +++ /dev/null @@ -1,19 +0,0 @@ -if GetResourceState('illenium-appearance') ~= 'started' then return end - -Clothing = Clothing or {} - -Clothing.SetAppearance = function(src, data) - --wip -end - -Clothing.GetAppearance = function(src) - --wip -end - -Clothing.RestoreAppearance = function(src) - --wip -end - -Clothing.ReloadSkin = function(src) - --wip -end \ No newline at end of file diff --git a/modules/clothing/qb-clothing/client.lua b/modules/clothing/qb-clothing/client.lua index 12a9cbb..6d96122 100644 --- a/modules/clothing/qb-clothing/client.lua +++ b/modules/clothing/qb-clothing/client.lua @@ -2,20 +2,15 @@ if GetResourceState('qb-clothing') ~= 'started' then return end Clothing = Clothing or {} -StoredOldClothing = {} - -RegisterNetEvent('community_bridge:client:updateStoredClothing', function(skindata) - StoredOldClothing = skindata -end) - -Clothing.SetAppearance = function(clothingData) - if GetEntityModel(cache.ped) == `mp_m_freemode_01` then - clothingData = clothingData.male - else - clothingData = clothingData.female - end +Clothing.SetAppearance = function(data) + local clothingData = {} local repackedTable = {} - StoredOldClothing = Clothing.GetAppearance + if GetEntityModel(cache.ped) == `mp_m_freemode_01` then + clothingData = data.male + else + clothingData = data.female + end + ClothingBackup = Clothing.GetAppearance local componentMap = { [1] = 'mask', [3] = 'arms', @@ -45,21 +40,21 @@ Clothing.SetAppearance = function(clothingData) face_id = 'face' } - for _, data in pairs(clothingData) do - if componentMap[data.component_id] then - repackedTable[componentMap[data.component_id]] = {drawable = data.drawable, texture = data.texture} - elseif propMap[data.prop_id] then - repackedTable[propMap[data.prop_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.eye_color_id] then - repackedTable[specialMap[data.eye_color_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.moles_id] then - repackedTable[specialMap[data.moles_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.ageing_id] then - repackedTable[specialMap[data.ageing_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.hair_id] then - repackedTable[specialMap[data.hair_id]] = {drawable = data.drawable, texture = data.texture} - elseif specialMap[data.face_id] then - repackedTable[specialMap[data.face_id]] = {drawable = data.drawable, texture = data.texture} + for _, v in pairs(clothingData) do + if componentMap[v.component_id] then + repackedTable[componentMap[v.component_id]] = {drawable = v.drawable, texture = v.texture} + elseif propMap[v.prop_id] then + repackedTable[propMap[v.prop_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.eye_color_id] then + repackedTable[specialMap[v.eye_color_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.moles_id] then + repackedTable[specialMap[v.moles_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.ageing_id] then + repackedTable[specialMap[v.ageing_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.hair_id] then + repackedTable[specialMap[v.hair_id]] = {drawable = v.drawable, texture = v.texture} + elseif specialMap[v.face_id] then + repackedTable[specialMap[v.face_id]] = {drawable = v.drawable, texture = v.texture} end end TriggerEvent('qb-clothing:client:loadOutfit', repackedTable) @@ -67,12 +62,12 @@ Clothing.SetAppearance = function(clothingData) end Clothing.GetAppearance = function() - StoredOldClothing = Utility.GetEntitySkinData(cache.ped) + ClothingBackup = Utility.GetEntitySkinData(cache.ped) return Utility.GetEntitySkinData(cache.ped) end Clothing.RestoreAppearance = function() - return Utility.SetEntitySkinData(cache.ped, StoredOldClothing) + return Utility.SetEntitySkinData(cache.ped, ClothingBackup) end Clothing.ReloadSkin = function() diff --git a/modules/clothing/qb-clothing/server.lua b/modules/clothing/qb-clothing/server.lua index 63e73e1..c95f1bc 100644 --- a/modules/clothing/qb-clothing/server.lua +++ b/modules/clothing/qb-clothing/server.lua @@ -2,25 +2,7 @@ if GetResourceState('qb-clothing') ~= 'started' then return end RegisterNetEvent('qb-clothing:saveSkin', function(model, skin) local src = source - if model ~= nil and skin ~= nil then - TriggerClientEvent('community_bridge:client:updateStoredClothing', src, skin) + if model and skin then + TriggerClientEvent('community_bridge:client:updateClothingBackup', src, skin) end -end) - -Clothing = Clothing or {} - -Clothing.SetAppearance = function(src, data) - --wip -end - -Clothing.GetAppearance = function(src) - --wip -end - -Clothing.RestoreAppearance = function(src) - --wip -end - -Clothing.ReloadSkin = function(src) - --wip -end \ No newline at end of file +end) \ No newline at end of file