Files
community_bridge/modules/inventory/codem-inventory/client.lua
T

65 lines
2.2 KiB
Lua
Raw Normal View History

2025-05-09 02:00:02 -04:00
---@diagnostic disable: duplicate-set-field
if GetResourceState('codem-inventory') ~= 'started' then return end
Inventory = Inventory or {}
2025-02-22 20:25:35 -05:00
local codem = exports['codem-inventory']
2025-05-09 03:17:28 -04:00
---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
2025-02-22 20:25:35 -05:00
Inventory.GetItemInfo = function(item)
local itemData = codem:GetItemList(item)
2025-05-09 02:00:02 -04:00
if not itemData then return {} end
2025-04-16 05:24:03 -05:00
local image = itemData.image and Inventory.GetImagePath(itemData.image) or Inventory.GetImagePath(item)
2025-05-09 02:00:02 -04:00
return {
2025-02-22 20:25:35 -05:00
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",
2025-04-16 05:24:03 -05:00
image = image,
2025-02-22 20:25:35 -05:00
}
end
2025-07-09 17:26:16 -04:00
---This will return the entire items table from the inventory.
---@return table
Inventory.Items = function()
return codem:GetItemList()
end
2025-05-09 03:17:28 -04:00
---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("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
---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 = {}
local inventory = codem: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
2025-05-09 06:03:09 -04:00
RegisterNetEvent('community_bridge:client:codem-inventory:openStash', function(id, data)
if source ~= 65535 then return end
TriggerServerEvent('codem-inventory:server:openstash', id, data.slots, data.weight, data.label)
end)
return Inventory