forked from Simnation/Main
ed
This commit is contained in:
parent
53a32aaa63
commit
747cfdf9a1
2 changed files with 34 additions and 12 deletions
|
@ -107,28 +107,50 @@ elseif GetResourceState('tgiann-inventory') == 'started' then
|
|||
local upperItem = string.upper(tostring(item))
|
||||
|
||||
if string.match(upperItem, "WEAPON_") then
|
||||
-- Create a completely new metadata table for weapons to avoid any reference issues
|
||||
-- Create a complete metadata table for weapons with all required fields
|
||||
local weaponMetadata = {
|
||||
-- Always use a string for serie, generated fresh each time
|
||||
-- Required fields with default values
|
||||
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,
|
||||
-- Add the required durabilityPercent parameter
|
||||
durabilityPercent = metadata.durabilityPercent or 100
|
||||
durabilityPercent = 100,
|
||||
usedTotalAmmo = 0,
|
||||
ammo = 0,
|
||||
quality = 100,
|
||||
|
||||
-- Override with any provided values from original metadata
|
||||
-- but ensure they are the correct type
|
||||
}
|
||||
|
||||
-- Debug output to verify the metadata structure
|
||||
print("Adding weapon: " .. item)
|
||||
print("Metadata: serie=" .. weaponMetadata.serie .. ", type=" .. type(weaponMetadata.serie))
|
||||
-- Copy values from original metadata if they exist and are valid
|
||||
if metadata then
|
||||
if metadata.ammo and type(metadata.ammo) == "number" then
|
||||
weaponMetadata.ammo = metadata.ammo
|
||||
end
|
||||
|
||||
if metadata.quality and type(metadata.quality) == "number" then
|
||||
weaponMetadata.quality = metadata.quality
|
||||
end
|
||||
|
||||
if metadata.durabilityPercent and type(metadata.durabilityPercent) == "number" then
|
||||
weaponMetadata.durabilityPercent = metadata.durabilityPercent
|
||||
end
|
||||
|
||||
if metadata.usedTotalAmmo and type(metadata.usedTotalAmmo) == "number" then
|
||||
weaponMetadata.usedTotalAmmo = metadata.usedTotalAmmo
|
||||
end
|
||||
|
||||
if metadata.serie and type(metadata.serie) == "string" then
|
||||
weaponMetadata.serie = metadata.serie
|
||||
end
|
||||
end
|
||||
|
||||
-- Use the clean weapon metadata instead of the original
|
||||
-- Use the properly formatted weapon metadata
|
||||
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
|
||||
|
||||
|
||||
|
||||
elseif GetResourceState('origen_inventory') == 'started' then
|
||||
exports['origen_inventory']:addItem(source, item, amount, metadata, false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue