Files

83 lines
2.7 KiB
Lua
Raw Permalink Normal View History

2025-05-09 02:00:02 -04:00
---@diagnostic disable: duplicate-set-field
if GetResourceState('qs-inventory') == 'missing' then return end
local quasar = exports["qs-inventory"]
2025-05-09 03:17:28 -04:00
Inventory = Inventory or {}
---@description This will get the name of the in use resource.
---@return string
Inventory.GetResourceName = function()
return "qs-inventory"
end
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
2025-03-03 01:09:24 -05:00
---@param item string
---@return table
Inventory.GetItemInfo = function(item)
local itemsData = quasar:GetItemList()
if not itemsData then return {} end
itemsData = itemsData[item]
if not itemsData then return {} end
2025-05-09 02:00:02 -04:00
return {
name = itemsData.name or "Missing Name",
label = itemsData.label or "Missing Label",
stack = itemsData.unique or "false",
weight = itemsData.weight or "0",
description = itemsData.description or "none",
2025-08-11 00:46:26 -04:00
image = Inventory.GetImagePath(item),
}
end
---@description This will return the entire items table from the inventory.
2025-07-09 17:26:16 -04:00
---@return table
Inventory.Items = function()
return quasar:GetItemList()
end
---@description Will return boolean if the player has the item.
2025-03-03 01:09:24 -05:00
---@param item string
---@return boolean
2025-02-17 13:02:36 -05:00
Inventory.HasItem = function(item)
local check = quasar:Search(item)
2025-02-17 13:26:10 -05:00
return check and true or false
2025-02-17 13:02:36 -05:00
end
---@description This will return th count of the item in the players inventory, if not found will return 0.
2025-05-09 03:17:28 -04:00
---@param item string
---@return number
Inventory.GetItemCount = function(item)
local searchItem = quasar:Search(item)
return searchItem or 0
end
---@description This will get the image path for this item, if not found will return placeholder.
2025-03-03 01:09:24 -05:00
---@param item string
---@return string
Inventory.GetImagePath = function(item)
2025-04-16 05:24:03 -05:00
item = Inventory.StripPNG(item)
local file = LoadResourceFile("qs-inventory", string.format("html/images/%s.png", item))
local imagePath = file and string.format("nui://qs-inventory/html/images/%s.png", item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---@description This will return the players inventory in the format of {name, label, count, slot, metadata}
2025-03-03 01:09:24 -05:00
---@return table
Inventory.GetPlayerInventory = function()
local items = {}
local inventory = quasar:getUserInventory()
for _, v in pairs(inventory) do
table.insert(items, {
name = v.name,
label = v.label,
count = v.amount or v.count,
slot = v.slot,
metadata = v.info or v.metadata or {},
stack = v.unique or v.stack or false,
close = v.useable,
weight = v.weight
})
end
return items
end
return Inventory