qs-advancedinventory -- untested
This commit is contained in:
1 parent
68e81b720a
commit
5eeef298b6
2 files changed
+280
No files matched your search
@@ -0,0 +1,78 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
if GetResourceState('qs-advancedinventory') ~= 'started' then return end
|
||||
local quasar = exports["qs-advancedinventory"]
|
||||
|
||||
Inventory = Inventory or {}
|
||||
|
||||
---Return the item info in oxs format, {name, label, stack, weight, description, image}
|
||||
---@param item string
|
||||
---@return table
|
||||
Inventory.GetItemInfo = function(item)
|
||||
local itemsData = quasar:GetItemList()
|
||||
if not itemsData then return {} end
|
||||
local itemData = itemsData[item]
|
||||
if not itemData then return {} end
|
||||
return {
|
||||
name = itemData.name or "Missing Name",
|
||||
label = itemData.label or "Missing Label",
|
||||
stack = itemData.unique or "false",
|
||||
weight = itemData.weight or "0",
|
||||
description = itemData.description or "none",
|
||||
image = itemData.image or Inventory.GetImagePath(item),
|
||||
}
|
||||
end
|
||||
|
||||
---Will return boolean if the player has the item.
|
||||
---@param item string
|
||||
---@return boolean
|
||||
Inventory.HasItem = function(item)
|
||||
local check = quasar:Search(item)
|
||||
return check and true or false
|
||||
end
|
||||
|
||||
---This will return th count of the item in the players inventory, if not found will return 0.
|
||||
---@param item string
|
||||
---@return number
|
||||
Inventory.GetItemCount = function(item)
|
||||
local searchItem = quasar:Search(item)
|
||||
return searchItem or 0
|
||||
end
|
||||
|
||||
---This will get the image path for this item, if not found will return placeholder.
|
||||
---@param item string
|
||||
---@return string
|
||||
Inventory.GetImagePath = function(item)
|
||||
item = Inventory.StripPNG(item)
|
||||
local file = LoadResourceFile("qs-advancedinventory", string.format("html/images/%s.png", item))
|
||||
local imagePath = file and string.format("nui://qs-advancedinventory/html/images/%s.png", item)
|
||||
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||
end
|
||||
|
||||
---This will return the players inventory in the format of {name, label, count, slot, metadata}
|
||||
---@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,
|
||||
slot = v.slot,
|
||||
metadata = v.info,
|
||||
stack = v.unique,
|
||||
close = v.useable,
|
||||
weight = v.weight
|
||||
})
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param id any
|
||||
---@return nil
|
||||
Inventory.OpenStash = function(id)
|
||||
quasar:RegisterStash(id, 50, 50000)
|
||||
end
|
||||
|
||||
return Inventory
|
||||
Reference in new issue
Block a user