From 330458a574f7047df69981f42116ba4e29db49c0 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Tue, 29 Jul 2025 00:44:44 +0200 Subject: [PATCH] Update client.lua --- .../modules/items/client.lua | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/resources/[inventory]/pickle_consumables/modules/items/client.lua b/resources/[inventory]/pickle_consumables/modules/items/client.lua index 295b9069b..01702d0d0 100644 --- a/resources/[inventory]/pickle_consumables/modules/items/client.lua +++ b/resources/[inventory]/pickle_consumables/modules/items/client.lua @@ -64,6 +64,7 @@ function ConsumeItem(name) type = "holdInteract", bool = true }) + while PerformingAction == "consume" and timeLeft > 0 do if anim.time - timeLeft > 100 and not IsEntityPlayingAnim(ped, anim.dict, anim.anim, 13) then timeLeft = timeLeft - 100 @@ -79,14 +80,35 @@ function ConsumeItem(name) type = "holdInteract", bool = false }) + ClearPedTasks(ped) - if timeLeft > 0 and anim.time - timeLeft <= 100 then + + -- Store animation time in a local variable to avoid nil reference + local animTime = anim.time + + -- Check if timeLeft is nil and provide a default + if timeLeft == nil then + timeLeft = 0 + end + + -- Now use the local variable for comparison + if timeLeft > 0 and animTime and (animTime - timeLeft <= 100) then OptionsMenu() PerformingAction = nil elseif timeLeft <= 0 then lib.callback("pickle_consumables:useItem", "", function(result, uses) + -- Check if cfg still exists (could have changed during callback) + if not cfg then + PerformingAction = nil + return + end + -- Safe access to cfg.effect - local effectName = cfg.effect and cfg.effect.name or "" + local effectName = "" + if cfg.effect and cfg.effect.name then + effectName = cfg.effect.name + end + if result and Config.Effects[effectName] and Config.Effects[effectName].process then CreateThread(function() if ProcessingEffect and not Config.Effects[effectName].canOverlap then return end @@ -96,6 +118,7 @@ function ConsumeItem(name) end) end + -- Check if ItemData exists if not ItemData then PerformingAction = nil return @@ -108,11 +131,17 @@ function ConsumeItem(name) -- Re-fetch config to ensure it's current local cfg = Config.Items[name] - if cfg and cfg.animation then + if cfg and cfg.animation and cfg.animation.time then SendNUIMessage({ type = "displayApp", data = { quantity = uses, time = cfg.animation.time } }) + else + -- Fallback if config is missing + SendNUIMessage({ + type = "displayApp", + data = { quantity = uses, time = 2000 } + }) end PerformingAction = nil end) @@ -123,6 +152,7 @@ function ConsumeItem(name) end + function RemoveItem() local ped = PlayerPedId() SendNUIMessage({