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

+9
View File
@@ -60,6 +60,15 @@ Framework.GetItemCount = function(src, item, _)
return xPlayer.getInventoryItem(item).count
end
---comment
---@param src number
---@param item string
---@return boolean
Framework.HasItem = function(src, item)
local getCount = Framework.GetItemCount(src, item, nil)
return getCount > 0
end
-- Framework.GetPlayerInventory(src)
-- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, _, _}
+9
View File
@@ -72,6 +72,15 @@ Framework.GetItemCount = function(src, item, metadata)
return count
end
---comment
---@param src number
---@param item string
---@return boolean
Framework.HasItem = function(src, item)
local getCount = Framework.GetItemCount(src, item, nil)
return getCount > 0
end
-- Framework.GetPlayerInventory(src)
-- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
+9
View File
@@ -70,6 +70,15 @@ Framework.GetItemCount = function(src, item, metadata)
return count
end
---comment
---@param src number
---@param item string
---@return boolean
Framework.HasItem = function(src, item)
local getCount = Framework.GetItemCount(src, item, nil)
return getCount > 0
end
-- Framework.GetPlayerInventory(src)
-- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
+10 -1
View File
@@ -60,6 +60,14 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
return codem:SetItemMetadata(src, slot, metadata)
end
---comment
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
return codem:HasItem(src, item, 1)
end
Inventory.GetItemBySlot = function(src, slot)
local slotData = codem:GetItemBySlot(src, slot)
if not slotData then return {} end
@@ -81,4 +89,5 @@ Inventory.GetImagePath = function(item)
local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item))
local imagePath = file and string.format("nui://codem-inventory/html/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
end
@@ -17,6 +17,14 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner, groups, coor
return true
end
---comment
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
return jpr:HasItem(src, item, 1)
end
---comment
---@param src number
---@param id string||number
@@ -64,4 +72,27 @@ Inventory.UpdatePlate = function(oldplate, newplate)
if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
end
local registeredShops = {}
Inventory.OpenShop = function(src, shopTitle)
return jpr:OpenShop(src, shopTitle)
end
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups)
if not shopTitle or not shopInventory or not shopCoords then return end
if registeredShops[shopTitle] then return true end
local repackItems = {}
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #shopInventory, }
for k, v in pairs(shopInventory) do
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.count or 1, slot = k })
end
jpr:CreateShop(repackedShopItems)
registeredShops[shopTitle] = true
--Inventory.OpenShop(src, shopTitle)
return true
end
@@ -14,6 +14,15 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return origen_inventory:removeItem(src, item, count, metadata, slot, true)
end
---comment
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
local count = origen_inventory:getItemCount(src , item)
return count > 0
end
Inventory.GetItemInfo = function(item)
local itemData = origen_inventory:Items(item)
local repackedTable = {
@@ -44,4 +44,8 @@ Inventory.GetPlayerInventory = function()
return exports.ox_inventory:GetPlayerItems()
end
Inventory.OpenShop = function(shopTitle, shopInventory)
ox_inventory:openInventory("shop", { type = shopTitle, id = 1 })
end
--Bridge.RegisterModule("Inventory", Inventory)
+23
View File
@@ -54,6 +54,15 @@ Inventory.GetItemCount = function(src, item, metadata)
return ox_inventory:GetItemCount(src, item, metadata, false)
end
---comment
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
local count = ox_inventory:GetItemCount(src, item, nil, false)
return count > 0
end
---comment
---@param src number
---@return table
@@ -142,4 +151,18 @@ Inventory.GetImagePath = function(item)
local file = LoadResourceFile("ox_inventory", string.format("web/images/%s.png", item))
local imagePath = file and string.format("nui://ox_inventory/web/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
local registeredShops = {}
Inventory.OpenShop = function(src, shopTitle)
TriggerClientEvent('ox_inventory:openInventory', src, 'shop', {type = shopTitle})
end
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
if registeredShops[shopTitle] then return true end
registeredShops[shopTitle] = true
ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, })
--return Inventory.OpenShop(src, shopTitle)
return true
end
+32 -2
View File
@@ -41,6 +41,14 @@ 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 sloth:HasItem(src, item, 1)
end
---comment
---@param src number
---@param slot number
@@ -61,7 +69,7 @@ end
Inventory.AddItem = function(src, item, amount, slot, metadata)
TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add')
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata})
return exports['ps-inventory']:AddItem(src, item, amount, slot, metadata, 'community_bridge')
return sloth:AddItem(src, item, amount, slot, metadata, 'community_bridge')
end
@@ -75,7 +83,7 @@ end
Inventory.RemoveItem = function(src, item, amount, slot, metadata)
TriggerClientEvent('ps-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'remove')
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
return exports['ps-inventory']:RemoveItem(src, item, amount, slot, 'community_bridge')
return sloth:RemoveItem(src, item, amount, slot, 'community_bridge')
end
@@ -93,4 +101,26 @@ Inventory.UpdatePlate = function(oldplate, newplate)
if GetResourceState('jg-mechanic') ~= 'started' then return true end
exports["jg-mechanic"]:vehiclePlateUpdated(oldplate, newplate)
return true
end
local registeredShops = {}
Inventory.OpenShop = function(src, shopTitle)
return sloth:OpenShop(src, shopTitle)
end
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups)
if not shopTitle or not shopInventory or not shopCoords then return end
if registeredShops[shopTitle] then return true end
local repackItems = {}
local repackedShopItems = {name = shopTitle, label = shopTitle, coords = shopCoords, items = repackItems, slots = #shopInventory, }
for k, v in pairs(shopInventory) do
table.insert(repackItems, { name = v.name, price = v.price or 1000, amount = v.count or 1, slot = k })
end
sloth:CreateShop(repackedShopItems)
registeredShops[shopTitle] = true
--Inventory.OpenShop(src, shopTitle)
return true
end
+2 -2
View File
@@ -10,14 +10,14 @@ RegisterNetEvent('community_bridge:client:qb-inventory:openStash', function(id,
TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, { maxweight = data.weight, slots = data.slots })
end)
---comment
---This will return a boolean if the player has the item in their inventory
---@param item string
---@return boolean
Inventory.HasItem = function(item)
return qb:HasItem(item)
end
---comment
---This will return a string of the image path for the item
---@param item string
---@return string
Inventory.GetImagePath = function(item)
+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
+18
View File
@@ -4,6 +4,7 @@ local quasar = exports['qs-inventory']
Inventory = Inventory or {}
---This will add the item if found and return a boolean on success
---@param src number
---@param item string
---@param count number
@@ -16,6 +17,7 @@ Inventory.AddItem = function(src, item, count, slot, metadata)
return quasar:AddItem(src, item, count, slot, metadata)
end
---This will remove the item if found and return a boolean on success
---@param src number
---@param item string
---@param count number
@@ -27,6 +29,7 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return quasar:RemoveItem(src, item, count, slot, metadata)
end
---This will return a number of the items count in the inventory
---@param src number
---@param item string
---@param metadata table
@@ -35,6 +38,7 @@ Inventory.GetItemCount = function(src, item, metadata)
return quasar:GetItemTotalAmount(src, item)
end
---This will return the player inventory in a table following ox_inventory format
---@param src number
---@return table
Inventory.GetPlayerInventory = function(src)
@@ -51,6 +55,17 @@ Inventory.GetPlayerInventory = function(src)
return repackedTable
end
---This will return a boolean of if the player has the item in the inventory
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
local count = quasar:GetItemTotalAmount(src, item)
if not count then return false end
return count > 0
end
---This will return the item data in the inventory based on the slot if not found will return nil
---@param src number
---@param slot number
---@return table | nil
@@ -73,6 +88,7 @@ Inventory.GetItemBySlot = function(src, slot)
return nil
end
---This will return a boolean if the player can carry the item
---@param src number
---@param item string
---@param count number
@@ -107,6 +123,7 @@ Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coo
TriggerClientEvent("inventory:client:SetCurrentStash",src, id)
end
---This will return the data to an item
---@param item string
---@return table
Inventory.GetItemInfo = function(item)
@@ -123,6 +140,7 @@ Inventory.GetItemInfo = function(item)
return repackedTable
end
---@param src number
---@param item string
---@param slot number
@@ -25,12 +25,14 @@ Inventory.GetItemInfo = function(item)
return repackedTable
end
---This will return a boolean if the player has the item in the inventory
---@param item string
---@return boolean
Inventory.HasItem = function(item)
return tgiann:HasItem(item)
end
-- This will return the image path, it is incredibley useful for menus etc
---@param item string
---@return string
Inventory.GetImagePath = function(item)
@@ -40,6 +42,7 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---This will return the player inventory in a table
---@return table
Inventory.GetPlayerInventory = function()
local items = {}
+21 -2
View File
@@ -4,6 +4,7 @@ local tgiann = exports["tgiann-inventory"]
Inventory = Inventory or {}
---This Will add the item if found and return boolean on success
---@param src number
---@param item string
---@param count number
@@ -16,6 +17,7 @@ Inventory.AddItem = function(src, item, count, slot, metadata)
return tgiann:AddItem(src, item, count, slot, metadata, false)
end
---This Will remove the item if found and return boolean on success
---@param src number
---@param item string
---@param count number
@@ -27,6 +29,7 @@ Inventory.RemoveItem = function(src, item, count, slot, metadata)
return tgiann:RemoveItem(src, item, count, slot, metadata)
end
--
---@param src number
---@param item string
---@param metadata table
@@ -38,6 +41,15 @@ Inventory.GetItem = function(src, item, metadata)
return item
end
---This will return a boolean if the player has the item in their inventory
---@param src number
---@param item string
---@return boolean
Inventory.HasItem = function(src, item)
return tgiann:HasItem(src, item, 1)
end
---This will return the count of the item in the players inventory
---@param src number
---@param item string
---@param metadata optional table
@@ -47,6 +59,7 @@ Inventory.GetItemCount = function(src, item, metadata)
return _item.amount or 0
end
---This will return the players inventory in a table in the format ox_inventory uses
---@param src number
---@return table
Inventory.GetPlayerInventory = function(src)
@@ -60,7 +73,7 @@ Inventory.GetPlayerInventory = function(src)
return items
end
---comment
---This will return a boolean if the player can carry the item
---@param src number
---@param item string
---@param count number
@@ -68,6 +81,7 @@ end
Inventory.CanCarryItem = function(src, item, count)
return tgiann:CanCarryItem(src, item, count)
end
---comment
---@param id string or number
---@param label string
@@ -79,7 +93,7 @@ Inventory.RegisterStash = function(id, label, slots, weight, owner)
return tgiann:CreateCustomStashWithItem(id, {})
end
---comment
---This will return the item data in the slot the item is found
---@param src number
---@param slot number
---@return table
@@ -89,6 +103,7 @@ Inventory.GetItemBySlot = function(src, slot)
return {name = item.name, label = item.label, weight = item.weight, slot = slot, count = item.amount, metadata = item.info, stack = item.unique or false, description = item.description}
end
---This will return a table of the item data including the image (very useful for menus etc)
---@param item string
---@return table
Inventory.GetItemInfo = function(item)
@@ -105,6 +120,8 @@ Inventory.GetItemInfo = function(item)
return repackedTable
end
---This will update the item metadata for an item with the provided slot and metadata, its best to get the item first
---And then set the metadata
---@param src number
---@param item string
---@param slot number
@@ -114,6 +131,7 @@ Inventory.SetMetadata = function(src, item, slot, metadata)
tgiann:UpdateItemMetadata(src, item, slot, metadata)
end
---This will return the image path for the item
---@param item string
---@return string
Inventory.GetImagePath = function(item)
@@ -123,6 +141,7 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---This will update the plate to a vehicle in the inventory
---@param oldplate string
---@param newplate string
---@return boolean