From 5392f38c7a080f676693e204f3e46da25ae1f45b Mon Sep 17 00:00:00 2001 From: Ilias Rbayti <63159154+Kenshiin13@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:36:54 +0100 Subject: [PATCH 1/4] feat(es_extended/shared/functions): add ESX.IsFunctionReference --- [core]/es_extended/shared/functions.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/[core]/es_extended/shared/functions.lua b/[core]/es_extended/shared/functions.lua index fc342bce..1a5d0090 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 From 346ce349020256aac4f46c4bbaae9d9e8535a7b4 Mon Sep 17 00:00:00 2001 From: Ilias Rbayti <63159154+Kenshiin13@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:38:19 +0100 Subject: [PATCH 2/4] fix(skinchanger/config): add missing textureof --- [core]/skinchanger/config.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/[core]/skinchanger/config.lua b/[core]/skinchanger/config.lua index 2401b9c7..1d5a0fed 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 From 2b8841c95a308e2df257e1d580a72262f21110dc Mon Sep 17 00:00:00 2001 From: Ilias Rbayti <63159154+Kenshiin13@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:38:48 +0100 Subject: [PATCH 3/4] fix(esx_skin/client/modules/menu): fix texture variations not updating --- [core]/esx_skin/client/modules/menu.lua | 38 +++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/[core]/esx_skin/client/modules/menu.lua b/[core]/esx_skin/client/modules/menu.lua index 0137f40a..f1179151 100644 --- a/[core]/esx_skin/client/modules/menu.lua +++ b/[core]/esx_skin/client/modules/menu.lua @@ -47,7 +47,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] @@ -78,27 +78,35 @@ 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 + -- Texture variation changed. We don't have to update anything. + if data.current.textureof then + return + end + + -- Texture changed. Update variation max value. + for i = 1, #self.elements, 1 do + local element = self.elements[i] + + if element.textureof == data.current.name then local component = self.components[i] - newData.max = type(component.max) == "function" and component.max(PlayerPedId(), skin) or component.max - - if self.elements[i].textureof ~= nil and data.current.name == self.elements[i].textureof then - newData.value = 0 + 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) + menu.update({ name = self.elements[i].name }, self.elements[i]) + menu.refresh() + break end - - self.elements = newData - menu.refresh() end end From 166fdff8eb3e295ec207fc85c4488f6777d273c2 Mon Sep 17 00:00:00 2001 From: Ilias Rbayti <63159154+Kenshiin13@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:52:15 +0100 Subject: [PATCH 4/4] refactor(esx_skin/client/modules/menu): bad habbits --- [core]/esx_skin/client/modules/menu.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[core]/esx_skin/client/modules/menu.lua b/[core]/esx_skin/client/modules/menu.lua index f1179151..effed0d8 100644 --- a/[core]/esx_skin/client/modules/menu.lua +++ b/[core]/esx_skin/client/modules/menu.lua @@ -98,7 +98,7 @@ function Menu:Change(data, menu) if element.textureof == data.current.name then local component = self.components[i] - if (ESX.IsFunctionReference(component.max)) then + if ESX.IsFunctionReference(component.max) then self.elements[i].max = component.max(PlayerPedId(), skin) end self.elements[i].value = 0