From 28b4007be3203dabe5bffe304e48d689390c48d3 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Tue, 29 Jul 2025 00:41:23 +0200 Subject: [PATCH] Update client.lua --- .../modules/items/client.lua | 109 ++++++++++++++++-- 1 file changed, 99 insertions(+), 10 deletions(-) diff --git a/resources/[inventory]/pickle_consumables/modules/items/client.lua b/resources/[inventory]/pickle_consumables/modules/items/client.lua index c8c57ef7d..295b9069b 100644 --- a/resources/[inventory]/pickle_consumables/modules/items/client.lua +++ b/resources/[inventory]/pickle_consumables/modules/items/client.lua @@ -34,10 +34,32 @@ function ConsumeItem(name) if PerformingAction then return end PerformingAction = "consume" local cfg = Config.Items[name] + + -- Check if config exists + if not cfg then + print("^1ERROR: Configuration missing for item: " .. name .. "^0") + PerformingAction = nil + return + end + local anim = cfg.animation + + -- Check if animation exists + if not anim then + print("^1ERROR: Animation configuration missing for item: " .. name .. "^0") + PerformingAction = nil + return + end + + -- Ensure animation time exists + if not anim.time then + print("^1ERROR: Animation time not defined for item: " .. name .. "^0") + anim.time = 2000 -- Default to 2 seconds if missing + end + local ped = PlayerPedId() CreateThread(function() - local timeLeft = anim.time + local timeLeft = anim.time -- Now we know this won't be nil SendNUIMessage({ type = "holdInteract", bool = true @@ -52,6 +74,7 @@ function ConsumeItem(name) Wait(10) end end + SendNUIMessage({ type = "holdInteract", bool = false @@ -62,23 +85,35 @@ function ConsumeItem(name) PerformingAction = nil elseif timeLeft <= 0 then lib.callback("pickle_consumables:useItem", "", function(result, uses) - if result and Config.Effects[cfg.effect?.name or ""] then + -- Safe access to cfg.effect + local effectName = cfg.effect and cfg.effect.name or "" + if result and Config.Effects[effectName] and Config.Effects[effectName].process then CreateThread(function() - if ProcessingEffect and not Config.Effects[cfg.effect.name].canOverlap then return end + if ProcessingEffect and not Config.Effects[effectName].canOverlap then return end ProcessingEffect = true - Config.Effects[cfg.effect.name].process(cfg.effect) + Config.Effects[effectName].process(cfg.effect) ProcessingEffect = false end) end + + if not ItemData then + PerformingAction = nil + return + end + ItemData.uses = uses if uses < 1 then return RemoveItem() end + + -- Re-fetch config to ensure it's current local cfg = Config.Items[name] - SendNUIMessage({ - type = "displayApp", - data = { quantity = uses, time = cfg.animation.time } - }) + if cfg and cfg.animation then + SendNUIMessage({ + type = "displayApp", + data = { quantity = uses, time = cfg.animation.time } + }) + end PerformingAction = nil end) else @@ -87,6 +122,7 @@ function ConsumeItem(name) end) end + function RemoveItem() local ped = PlayerPedId() SendNUIMessage({ @@ -105,10 +141,21 @@ function ItemThread(name, metadata) ItemData = metadata AttachProp(name) local cfg = Config.Items[name] + + -- Check if config exists + if not cfg then + print("^1ERROR: Configuration missing for item: " .. name .. "^0") + return RemoveItem() + end + + -- Safe access to animation time + local animTime = (cfg.animation and cfg.animation.time) or 2000 + SendNUIMessage({ type = "displayApp", - data = { quantity = ItemData.uses, time = cfg.animation.time } + data = { quantity = ItemData.uses, time = animTime } }) + CreateThread(function() local pressTime = 0 local holding = false @@ -149,6 +196,7 @@ function ItemThread(name, metadata) end) end + RegisterNetEvent("pickle_consumables:equipItem", function(name, metadata) if not Config.Items[name] then return print("^1ERROR: This item is not configured.^0") end if EquippedItem then return ShowNotification(_L("item_active")) end @@ -163,4 +211,45 @@ AddEventHandler("onResourceStop", function(name) if name ~= GetCurrentResourceName() then return end TransitionFromBlurred(0) RemoveAttachedProp() -end) \ No newline at end of file +end) + +function ValidateItemConfigs() + print("^2Validating item configurations...^0") + local issues = 0 + + for itemName, itemConfig in pairs(Config.Items) do + -- Check for required properties + if not itemConfig.animation then + print("^1WARNING: Item '" .. itemName .. "' is missing animation configuration^0") + issues = issues + 1 + elseif not itemConfig.animation.time then + print("^1WARNING: Item '" .. itemName .. "' is missing animation time configuration^0") + issues = issues + 1 + end + + if not itemConfig.prop then + print("^1WARNING: Item '" .. itemName .. "' is missing prop configuration^0") + issues = issues + 1 + end + + -- Check for effect configuration if referenced + if itemConfig.effect and itemConfig.effect.name then + if not Config.Effects[itemConfig.effect.name] then + print("^1WARNING: Item '" .. itemName .. "' references non-existent effect: " .. itemConfig.effect.name .. "^0") + issues = issues + 1 + end + end + end + + if issues > 0 then + print("^1Found " .. issues .. " configuration issues. Please fix them to ensure proper functionality.^0") + else + print("^2All item configurations validated successfully!^0") + end +end + +-- Call this when the resource starts +AddEventHandler('onResourceStart', function(resourceName) + if (GetCurrentResourceName() ~= resourceName) then return end + ValidateItemConfigs() +end)