From 64c19983e3cd3dfb647b0485bdfd91cd89c182d5 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sat, 22 Feb 2025 19:20:49 -0500 Subject: [PATCH] no access to test, rely in framework fallbacks --- modules/inventory/codem-inventory/client.lua | 39 +------- modules/inventory/codem-inventory/server.lua | 95 +------------------- 2 files changed, 5 insertions(+), 129 deletions(-) diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index 83a0228..ee43071 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -1,41 +1,8 @@ if GetResourceState('codem-inventory') ~= 'started' then return end Inventory = Inventory or {} -local codem = exports['codem-inventory'] - -Inventory.GetItemInfo = function(item) - local itemData = codem:GetItemList() - if not itemData[item] then return {} end - local repackedTable = { - 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), - } - return repackedTable -end - Inventory.GetImagePath = function(item) - local imagePath = string.format("nui://codem-inventory/html/images/%s.png", 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 - -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 +end \ No newline at end of file diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index dce5135..0b74cc3 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -4,99 +4,8 @@ local codem = exports['codem-inventory'] Inventory = Inventory or {} -Inventory.AddItem = function(src, item, count, slot, metadata) - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) - - return codem:AddItem(src, item, count, slot, metadata) -end - -Inventory.RemoveItem = function(src, item, count, slot, metadata) - if metadata == nil then - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) - return codem:RemoveItem(src, item, count, slot) - else - local items = codem:GetInventory(nil, src) - for _, itemInfo in pairs(items) do - if itemInfo.name == item then - if itemInfo.info == metadata then - TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = itemInfo.slot, metadata = metadata}) - return codem:RemoveItem(src, item, count, itemInfo.slot) - end - end - end - end -end - -Inventory.GetItemInfo = function(item) - local itemData = codem:GetItemList() - if not itemData[item] then return {} end - local repackedTable = { - 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), - } - return repackedTable -end - -Inventory.GetItemCount = function(src, item, metadata) - if metadata == nil then - return codem:GetItemsTotalAmount(src, item) - else - local count = 0 - local items = codem:GetInventory(nil, src) - for _, itemInfo in pairs(items) do - if itemInfo.name == item and itemInfo.info == metadata then - count = count + itemInfo.amount - end - return count - end - end -end - -Inventory.GetItemBySlot = function(src, slot) - local slotData = codem:GetItemBySlot(src, slot) - -- The keys are not documented, so this is a best guess - for _, v in pairs(slotData) do - return { - name = v.name, - label = v.name, - weight = v.weight, - slot = v.slot, - count = v.amount, - metadata = v.info, - stack = v.unique, - description = v.description - } - end - return {} -end - -Inventory.GetPlayerInventory = function(src) - local items = codem:GetInventory(nil, src) - local repackedTable = {} - for _, v in pairs(items) do - table.insert(repackedTable, { - name = v.name, - count = v.amount, - metadata = v.info, - slot = v.slot, - }) - end - return items -end - -Inventory.SetMetadata = function(src, item, slot, metadata) - codem:SetItemMetadata(src, slot, metadata) -end - -Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords) - TriggerEvent('codem-inventory:server:openstash', id, slots, weight, label) -end - Inventory.GetImagePath = function(item) - local imagePath = string.format("nui://codem-inventory/html/images/%s.png", 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 \ No newline at end of file