diff --git a/resources/[inventory]/cs_shops/config/functions/sv_function.lua b/resources/[inventory]/cs_shops/config/functions/sv_function.lua index 280e92a84..4863bdd60 100644 --- a/resources/[inventory]/cs_shops/config/functions/sv_function.lua +++ b/resources/[inventory]/cs_shops/config/functions/sv_function.lua @@ -103,27 +103,29 @@ function AddItem(source, item, amount, metadata) exports['qs-inventory']:AddItem(source, item, amount, false, metadata) elseif GetResourceState('tgiann-inventory') == 'started' then - -- Convert item name to uppercase for consistent comparison - local upperItem = string.upper(item) + -- For tgiann-inventory, we need to handle weapons differently + local upperItem = string.upper(tostring(item)) - -- Handle weapons specifically if string.match(upperItem, "WEAPON_") then - -- Always generate a new string serie for weapons - metadata.serie = tostring(math.random(100000, 999999)) + -- Create a completely new metadata table for weapons to avoid any reference issues + local weaponMetadata = { + -- Always use a string for serie, generated fresh each time + serie = tostring(math.random(100000, 999999)), + -- Copy any existing metadata values that should be preserved + ammo = metadata.ammo or 0, + quality = metadata.quality or 100 + } - -- Set default weapon metadata if not provided - metadata.ammo = metadata.ammo or 0 - metadata.quality = metadata.quality or 100 + -- Debug output to verify the metadata structure + print("Adding weapon: " .. item) + print("Metadata: serie=" .. weaponMetadata.serie .. ", type=" .. type(weaponMetadata.serie)) - -- Special handling for carbine rifle - if upperItem == "WEAPON_CARBINERIFLE" then - -- Additional specific settings for carbine rifle if needed - -- This ensures the carbine rifle always has valid metadata - end + -- Use the clean weapon metadata instead of the original + exports["tgiann-inventory"]:AddItem(source, item, amount, nil, weaponMetadata, nil) + else + -- For non-weapon items, use the original metadata + exports["tgiann-inventory"]:AddItem(source, item, amount, nil, metadata, nil) end - - -- Call the tgiann-inventory export with properly formatted metadata - exports["tgiann-inventory"]:AddItem(source, item, amount, nil, metadata, nil) elseif GetResourceState('origen_inventory') == 'started' then exports['origen_inventory']:addItem(source, item, amount, metadata, false)