forked from Simnation/Main
Update client.lua
This commit is contained in:
parent
5f826a44a3
commit
28b4007be3
1 changed files with 99 additions and 10 deletions
|
@ -34,10 +34,32 @@ function ConsumeItem(name)
|
||||||
if PerformingAction then return end
|
if PerformingAction then return end
|
||||||
PerformingAction = "consume"
|
PerformingAction = "consume"
|
||||||
local cfg = Config.Items[name]
|
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
|
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()
|
local ped = PlayerPedId()
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local timeLeft = anim.time
|
local timeLeft = anim.time -- Now we know this won't be nil
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = "holdInteract",
|
type = "holdInteract",
|
||||||
bool = true
|
bool = true
|
||||||
|
@ -52,6 +74,7 @@ function ConsumeItem(name)
|
||||||
Wait(10)
|
Wait(10)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = "holdInteract",
|
type = "holdInteract",
|
||||||
bool = false
|
bool = false
|
||||||
|
@ -62,23 +85,35 @@ function ConsumeItem(name)
|
||||||
PerformingAction = nil
|
PerformingAction = nil
|
||||||
elseif timeLeft <= 0 then
|
elseif timeLeft <= 0 then
|
||||||
lib.callback("pickle_consumables:useItem", "", function(result, uses)
|
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()
|
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
|
ProcessingEffect = true
|
||||||
Config.Effects[cfg.effect.name].process(cfg.effect)
|
Config.Effects[effectName].process(cfg.effect)
|
||||||
ProcessingEffect = false
|
ProcessingEffect = false
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not ItemData then
|
||||||
|
PerformingAction = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
ItemData.uses = uses
|
ItemData.uses = uses
|
||||||
if uses < 1 then
|
if uses < 1 then
|
||||||
return RemoveItem()
|
return RemoveItem()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Re-fetch config to ensure it's current
|
||||||
local cfg = Config.Items[name]
|
local cfg = Config.Items[name]
|
||||||
SendNUIMessage({
|
if cfg and cfg.animation then
|
||||||
type = "displayApp",
|
SendNUIMessage({
|
||||||
data = { quantity = uses, time = cfg.animation.time }
|
type = "displayApp",
|
||||||
})
|
data = { quantity = uses, time = cfg.animation.time }
|
||||||
|
})
|
||||||
|
end
|
||||||
PerformingAction = nil
|
PerformingAction = nil
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
|
@ -87,6 +122,7 @@ function ConsumeItem(name)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function RemoveItem()
|
function RemoveItem()
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
|
@ -105,10 +141,21 @@ function ItemThread(name, metadata)
|
||||||
ItemData = metadata
|
ItemData = metadata
|
||||||
AttachProp(name)
|
AttachProp(name)
|
||||||
local cfg = Config.Items[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({
|
SendNUIMessage({
|
||||||
type = "displayApp",
|
type = "displayApp",
|
||||||
data = { quantity = ItemData.uses, time = cfg.animation.time }
|
data = { quantity = ItemData.uses, time = animTime }
|
||||||
})
|
})
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local pressTime = 0
|
local pressTime = 0
|
||||||
local holding = false
|
local holding = false
|
||||||
|
@ -149,6 +196,7 @@ function ItemThread(name, metadata)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
RegisterNetEvent("pickle_consumables:equipItem", function(name, metadata)
|
RegisterNetEvent("pickle_consumables:equipItem", function(name, metadata)
|
||||||
if not Config.Items[name] then return print("^1ERROR: This item is not configured.^0") end
|
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
|
if EquippedItem then return ShowNotification(_L("item_active")) end
|
||||||
|
@ -164,3 +212,44 @@ AddEventHandler("onResourceStop", function(name)
|
||||||
TransitionFromBlurred(0)
|
TransitionFromBlurred(0)
|
||||||
RemoveAttachedProp()
|
RemoveAttachedProp()
|
||||||
end)
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue