From 801db83402638de2f10b2902d0270c44fa718b4a Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sat, 12 Apr 2025 02:30:38 -0400 Subject: [PATCH] GetItemInfo fixes, oops Ive also adjusted comments in here because it bugged me. --- modules/framework/qb-core/server.lua | 19 +++++++++++++- modules/inventory/_default/server.lua | 30 +++++++++++------------ modules/inventory/qb-inventory/server.lua | 1 - 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index d72ce64..5a48503 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -71,6 +71,23 @@ Framework.GetItem = function(src, item, metadata) return repackedTable end +---This will get the data about an item such as name, label, stack, weight, description and image. +---@param item string +---@return table +Framework.GetItemInfo = function(item) + local itemData = QBCore.Shared.Items[item] + if not itemData then return {} end + local repackedTable = { + name = itemData.name, + label = itemData.label, + stack = itemData.unique, + weight = itemData.weight, + description = itemData.description, + image = itemData.image + } + return repackedTable +end + -- Framework.GetItemCount(src, item, metadata) -- Returns the count of items matching the specified name and if passed metadata from the player's inventory. Framework.GetItemCount = function(src, item, metadata) @@ -255,8 +272,8 @@ end ---@param job any ---@return table Framework.GetPlayersByJob = function(job) - local players = QBCore.Functions.GetPlayers() local playerList = {} + local players = QBCore.Functions.GetPlayers() for _, src in pairs(players) do local player = QBCore.Functions.GetPlayer(src).PlayerData if player.job.name == job then diff --git a/modules/inventory/_default/server.lua b/modules/inventory/_default/server.lua index d179eaf..87eb68c 100644 --- a/modules/inventory/_default/server.lua +++ b/modules/inventory/_default/server.lua @@ -1,36 +1,36 @@ Inventory = Inventory or {} ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param src number ---@param item string ---@param count number ---@param slot number ---@param metadata table ----@return boolean +---@return boolean|nil Inventory.AddItem = function(src, item, count, slot, metadata) return Framework.AddItem(src, item, count, slot, metadata) end ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param src number ---@param item string ---@param count number ---@param slot number ---@param metadata table ----@return boolean +---@return boolean|nil Inventory.RemoveItem = function(src, item, count, slot, metadata) item = type(item) == "table" and item.name or item return Framework.RemoveItem(src, item, count, slot, metadata) end ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param item string ----@return boolean +---@return table Inventory.GetItemInfo = function(item) - return false, print("This Inventory Has Not Been Bridged For An Item Info Feature.") + return Framework.GetItemInfo(item) end ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param src number ---@param item string ---@param metadata table @@ -39,14 +39,14 @@ Inventory.GetItemCount = function(src, item, metadata) return Framework.GetItemCount(src, item, metadata) end ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param src number ---@return table Inventory.GetPlayerInventory = function(src) return Framework.GetPlayerInventory(src) end ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param src number ---@param slot number ---@return table @@ -54,7 +54,7 @@ Inventory.GetItemBySlot = function(src, slot) return Framework.GetItemBySlot(src, slot) end ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param src number ---@param item string ---@param slot number @@ -64,7 +64,7 @@ Inventory.SetMetadata = function(src, item, slot, metadata) return Framework.SetMetadata(src, item, slot, metadata) end ----comment +---This will fallback to framework add item functions when an inventory does not have the specifiec function. ---@param src number ---@param id string||number ---@param label string @@ -75,12 +75,12 @@ end ---@param coords table ---@return boolean Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - return false, print("This Inventory Has Not Been Bridged For A Stash Feature.") + return false, Prints.Error("This Inventory Has Not Been Bridged For A Stash Feature.") end ----comment +---This will provide a image of the community bridge logo if the inventory isnt bridged for the specific path. ---@param item string ---@return string Inventory.GetImagePath = function(item) return "https://avatars.githubusercontent.com/u/47620135" -end +end \ No newline at end of file diff --git a/modules/inventory/qb-inventory/server.lua b/modules/inventory/qb-inventory/server.lua index 86ea1d4..03b43ff 100644 --- a/modules/inventory/qb-inventory/server.lua +++ b/modules/inventory/qb-inventory/server.lua @@ -76,7 +76,6 @@ Inventory.GetItemBySlot = function(src, slot) } end - ---comment ---@param oldplate string ---@param newplate string