From aa02123992b49d8f6b36ea3ad97b9bd059ef9f69 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Sun, 27 Jul 2025 05:14:09 +0200 Subject: [PATCH] Update sv_function.lua --- .../cs_shops/config/functions/sv_function.lua | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/resources/[inventory]/cs_shops/config/functions/sv_function.lua b/resources/[inventory]/cs_shops/config/functions/sv_function.lua index 92817367f..280e92a84 100644 --- a/resources/[inventory]/cs_shops/config/functions/sv_function.lua +++ b/resources/[inventory]/cs_shops/config/functions/sv_function.lua @@ -93,26 +93,43 @@ function RemovePlayerMoney(player, amount, bank) end function AddItem(source, item, amount, metadata) - if not metadata then metadata = {} end + -- Initialize metadata if not provided + metadata = metadata or {} if GetResourceState('ox_inventory') == 'started' then exports['ox_inventory']:AddItem(source, item, amount, metadata) + elseif GetResourceState('qs-inventory') == 'started' then exports['qs-inventory']:AddItem(source, item, amount, false, metadata) -elseif GetResourceState('tgiann-inventory') == 'started' then - -- Ensure metadata is a table - metadata = metadata or {} - -- Check if the item is a weapon and ensure 'serie' exists in metadata as a string - if string.match(item:upper(), "WEAPON_") then - if not metadata.serie or type(metadata.serie) ~= "string" then + elseif GetResourceState('tgiann-inventory') == 'started' then + -- Convert item name to uppercase for consistent comparison + local upperItem = string.upper(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)) + + -- Set default weapon metadata if not provided + metadata.ammo = metadata.ammo or 0 + metadata.quality = metadata.quality or 100 + + -- 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 end - end - exports["tgiann-inventory"]:AddItem(source, item, amount, nil, metadata, nil) + + -- 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) + else + -- Default handling for QB/ESX local Player = GetPlayer(source) if CodeStudio.ServerType == 'QB' then Player.Functions.AddItem(item, amount, nil, metadata) @@ -123,6 +140,8 @@ elseif GetResourceState('tgiann-inventory') == 'started' then end + + function BuyItems(data) local item = data.item local amount = tonumber(data.amount) or 1