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 | ||||
|     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) | ||||
| 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
	
	 Nordi98
						Nordi98