HasItem + partial support for shops

This commit is contained in:
MrNewb committed 2025-03-07 04:08:40 -05:00
1 parent f28e511de6
commit dee14600ba
14 files changed
+220 -7

No files matched your search

+40
View File
@@ -49,6 +49,13 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---comment
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
return qbInventory:HasItem(src, item, 1)
end
---comment
---@param src number
@@ -112,3 +119,36 @@ Inventory.RemoveItem = function(src, item, amount, slot, metadata)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
return exports['qb-inventory']:RemoveItem(src, item, amount, slot, 'community_bridge')
end
local registeredShops = {}
Inventory.OpenShop = function(src, shopTitle)
return exports['qb-inventory']:OpenShop(src, shopTitle)
end
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups)
if not shopTitle or not shopInventory or not shopCoords then return end
local newVersion = getInventoryNewVersion()
if newVersion then
if registeredShops[shopTitle] then return true end
registeredShops[shopTitle] = true
local repackedShopItems = {}
for _, v in pairs(shopInventory) do
table.insert(repackedShopItems, {name = v.name, price = v.price, amount = v.count or 1000})
end
exports['qb-inventory']:CreateShop({ name = shopTitle, label = shopTitle, coords = shopCoords, items = repackedShopItems, })
--exports['qb-inventory']:OpenShop(src, shopTitle)
--return Inventory.OpenShop(src, shopTitle)
return true
else
local shopData = { label = shopTitle, items = {}, slots = 0 }
for _, v in pairs(shopInventory) do
table.insert(shopData.items, { name = v.name, price = v.price, amount = v.count or 1000, info = {}, type = 'item' })
end
shopData.slots = #shopData.items
TriggerClientEvent("inventory:client:OpenInventory", src, "shop", shopTitle, shopData)
print("QB-INVENTORY: You are using an outdated version of qb-inventory, please update to the latest version. Stuff will still work but you are using litterally the most exploitable inventory in fivem.")
end
end