2025-05-09 02:00:02 -04:00
---@diagnostic disable: duplicate-set-field
2025-12-14 16:22:35 -05:00
if GetResourceState ( 'codem-inventory' ) == 'missing' then return end
2025-01-10 16:36:20 -05:00
Inventory = Inventory or {}
2025-02-22 20:25:35 -05:00
local codem = exports [ 'codem-inventory' ]
2025-12-14 16:22:35 -05:00
---@description This will get the name of the in use resource.
2025-09-10 12:27:12 -04:00
---@return string
Inventory.GetResourceName = function ()
return "codem-inventory"
end
2025-12-14 16:22:35 -05:00
---@description Return the item info in oxs format, {name, label, stack, weight, description, image}
2025-09-13 18:04:05 -04:00
---@param item string
---@return table
Inventory.GetItemInfo = function ( item )
local itemData = Inventory.Items ()
if not itemData or not itemData [ item ] then return {} end
local image = Inventory.GetImagePath ( itemData [ item ]. image ) or Inventory.GetImagePath ( item )
return {
name = itemData [ item ]. name or "Missing Name" ,
label = itemData [ item ]. label or "Missing Label" ,
stack = itemData [ item ]. unique or "false" ,
weight = itemData [ item ]. weight or "0" ,
description = itemData [ item ]. description or "none" ,
image = image ,
}
2025-07-09 17:26:16 -04:00
end
2025-12-14 16:22:35 -05:00
---@description This will return the entire items table from the inventory.
---@return table
Inventory.Items = function ()
return codem : GetItemList () or {}
end
---@description This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
2025-05-09 03:17:28 -04:00
---@param item string
---@return string
Inventory.GetImagePath = function ( item )
item = Inventory.StripPNG ( item )
2025-12-14 16:22:35 -05:00
local file = LoadResourceFile ( "codem-inventory" , string.format ( "html/itemimages/%s.png" , item ))
local imagePath = file and string.format ( "nui://codem-inventory/html/itemimages/%s.png" , item )
2025-05-09 03:17:28 -04:00
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
2025-12-14 16:22:35 -05:00
---@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
2025-02-22 20:25:35 -05:00
Inventory.GetPlayerInventory = function ()
local items = {}
2025-12-14 16:22:35 -05:00
local inventory = codem : GetClientPlayerInventory ()
2025-02-22 20:25:35 -05:00
for _ , v in pairs ( inventory ) do
table.insert ( items , {
name = v.name ,
label = v.label ,
2025-12-14 16:22:35 -05:00
count = v.amount or v.count ,
2025-02-22 20:25:35 -05:00
slot = v.slot ,
2025-12-14 16:22:35 -05:00
metadata = v.info or v.metadata or {},
2025-02-22 20:25:35 -05:00
stack = v.unique ,
close = v.useable ,
weight = v.weight
})
end
return items
end
2025-05-10 00:01:56 -04:00
return Inventory