diff --git a/client/main.lua b/client/main.lua index 51000ee92..95111ff7d 100644 --- a/client/main.lua +++ b/client/main.lua @@ -55,6 +55,31 @@ end exports('HasItem', HasItem) +function GetItemCount(items) + assert((type(items) == 'table' or type(items) == 'string') and table.type(table) == 'hash', "Table in ^3GetItemCount^7 cannot be dictionary!") + + local check = type(items) == 'table' and 1 or 2 + local count = 0 + + for _,item in pairs(PlayerData.items) do + if check == 1 then + for k,v in pairs(items) do + if v == item.name then + count+=item.amount + end + end + elseif check == 2 then + if items == item.name then + count+=item.amount + end + end + end + + return count +end + +exports('GetItemCount', GetItemCount) + ---Gets the closest vending machine object to the client ---@return integer closestVendingMachine local function GetClosestVending() diff --git a/server/main.lua b/server/main.lua index 3050efe54..bed160df2 100644 --- a/server/main.lua +++ b/server/main.lua @@ -446,6 +446,33 @@ end exports('HasItem', HasItem) +function GetItemCount(source, items) + assert((type(items) == 'table' or type(items) == 'string') and table.type(table) == 'hash', "Table in ^3GetItemCount^7 cannot be dictionary!") + + local Player = QBCore.Functions.GetPlayer(source) + if not Player then return 0 end + local check = type(items) == 'table' and 1 or 2 + local count = 0 + + for _,item in pairs(Player.PlayerData.items) do + if check == 1 then + for k,v in pairs(items) do + if v == item.name then + count+=item.amount + end + end + else + if items == item.name then + count+=item.amount + end + end + end + + return count +end + +exports('GetItemCount', GetItemCount) + ---Create a usable item with a callback on use ---@param itemName string The name of the item to make usable ---@param data any