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 1/4] 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 From 7b03dba08f14250e93fb002b7934ff33378c62d4 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sat, 22 Feb 2025 20:20:08 -0500 Subject: [PATCH 2/4] death check tweaks --- modules/framework/es_extended/client.lua | 9 ++++++--- modules/framework/qb-core/client.lua | 3 ++- modules/framework/qbx_core/client.lua | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 6841e62..328530c 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -21,7 +21,8 @@ Framework.Notify = function(message, type, time) end Framework.GetPlayerIdentifier = function() - return ESX.GetPlayerData().identifier + local playerData = ESX.GetPlayerData() + return playerData.identifier end Framework.GetPlayerName = function() @@ -40,11 +41,13 @@ Framework.HasItem = function(item) end Framework.GetPlayerInventory = function() - return ESX.GetPlayerData().inventory + local playerData = ESX.GetPlayerData() + return playerData.inventory end Framework.GetIsPlayerDead = function() - return ESX.GetPlayerData().dead + local playerData = ESX.GetPlayerData() + return playerData.dead end RegisterNetEvent('esx:playerLoaded', function(xPlayer) diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index cb62bc9..727787d 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -80,7 +80,8 @@ Framework.GetPlayerInventory = function() end Framework.GetIsPlayerDead = function() - return QBCore.Functions.GetPlayerData().metadata["isdead"] or QBCore.GetPlayerData().metadata["inlaststand"] + local playerData = QBCore.Functions.GetPlayerData() + return playerData.metadata["isdead"] or playerData.metadata["inlaststand"] end Framework.Shared = QBCore.Shared diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index dd8fc95..f11dcd8 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -36,7 +36,8 @@ Framework.GetPlayerInventory = function() end Framework.GetIsPlayerDead = function() - return QBox.GetPlayerData().metadata["isdead"] or QBox.GetPlayerData().metadata["inlaststand"] + local platerData = QBox.GetPlayerData() + return platerData.metadata["isdead"] or platerData.metadata["inlaststand"] end RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() From 8b08ba17354e3ce30984c3b8452ad9760f521f7f Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sat, 22 Feb 2025 20:25:35 -0500 Subject: [PATCH 3/4] codem tweak --- modules/inventory/codem-inventory/client.lua | 33 +++++++++ modules/inventory/codem-inventory/server.lua | 75 +++++++++++++++++++- 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index ee43071..a6bfaad 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -1,6 +1,39 @@ if GetResourceState('codem-inventory') ~= 'started' then return end Inventory = Inventory or {} +local codem = exports['codem-inventory'] + +Inventory.GetItemInfo = function(item) + local itemData = codem:GetItemList(item) + 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 or {} +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 + Inventory.GetImagePath = function(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) diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index 0b74cc3..0d8a635 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -1,8 +1,81 @@ if GetResourceState('codem-inventory') ~= 'started' then return end +Inventory = Inventory or {} + local codem = exports['codem-inventory'] -Inventory = Inventory or {} +Inventory.GetItemInfo = function(item) + local itemData = codem:GetItemList(item) + 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 or {} +end + +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.GetItemBySlot = function(src, slot) + return codem:GetItemBySlot(src, slot) +end + +Inventory.GetPlayerInventory = function(src) + local identifier = Framework.GetPlayerIdentifier(src) + local playerItems = codem:GetInventory(identifier, src) + local repackedTable = {} + for _, v in pairs(playerItems) do + table.insert(repackedTable, { + name = v.name, + count = v.amount, + metadata = v.info, + slot = v.slot, + }) + end + return repackedTable +end + +Inventory.RemoveItem = function(src, item, count, slot, metadata) + if not slot and metadata then + local inv = Inventory.GetPlayerInventory(src) + if not inv then return false end + for _, v in pairs(inv) do + if v.name == item and v.metadata == metadata then + slot = v.slot + break + end + end + end + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return codem:RemoveItem(src, item, count, slot) +end + +Inventory.SetMetadata = function(src, item, slot, metadata) + return codem:SetItemMetadata(src, slot, metadata) +end + +Inventory.GetItemBySlot = function(src, slot) + local slotData = codem:GetItemBySlot(src, slot) + if not slotData then return {} end + 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 +end Inventory.GetImagePath = function(item) local file = LoadResourceFile("codem-inventory", string.format("html/images/%s.png", item)) From 8eb15bb1563fca4c3c2d29503ea97915972f9a30 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:08:52 -0500 Subject: [PATCH 4/4] framework + codem inventory tweak --- modules/framework/es_extended/client.lua | 9 +- modules/framework/qb-core/client.lua | 3 +- modules/framework/qbx_core/client.lua | 3 +- modules/inventory/codem-inventory/client.lua | 16 +-- modules/inventory/codem-inventory/server.lua | 104 ++++++++----------- 5 files changed, 61 insertions(+), 74 deletions(-) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 6841e62..328530c 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -21,7 +21,8 @@ Framework.Notify = function(message, type, time) end Framework.GetPlayerIdentifier = function() - return ESX.GetPlayerData().identifier + local playerData = ESX.GetPlayerData() + return playerData.identifier end Framework.GetPlayerName = function() @@ -40,11 +41,13 @@ Framework.HasItem = function(item) end Framework.GetPlayerInventory = function() - return ESX.GetPlayerData().inventory + local playerData = ESX.GetPlayerData() + return playerData.inventory end Framework.GetIsPlayerDead = function() - return ESX.GetPlayerData().dead + local playerData = ESX.GetPlayerData() + return playerData.dead end RegisterNetEvent('esx:playerLoaded', function(xPlayer) diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index cb62bc9..727787d 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -80,7 +80,8 @@ Framework.GetPlayerInventory = function() end Framework.GetIsPlayerDead = function() - return QBCore.Functions.GetPlayerData().metadata["isdead"] or QBCore.GetPlayerData().metadata["inlaststand"] + local playerData = QBCore.Functions.GetPlayerData() + return playerData.metadata["isdead"] or playerData.metadata["inlaststand"] end Framework.Shared = QBCore.Shared diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index dd8fc95..f11dcd8 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -36,7 +36,8 @@ Framework.GetPlayerInventory = function() end Framework.GetIsPlayerDead = function() - return QBox.GetPlayerData().metadata["isdead"] or QBox.GetPlayerData().metadata["inlaststand"] + local platerData = QBox.GetPlayerData() + return platerData.metadata["isdead"] or platerData.metadata["inlaststand"] end RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index 83a0228..a6bfaad 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -4,8 +4,7 @@ Inventory = Inventory or {} local codem = exports['codem-inventory'] Inventory.GetItemInfo = function(item) - local itemData = codem:GetItemList() - if not itemData[item] then return {} end + local itemData = codem:GetItemList(item) local repackedTable = { name = itemData.name or "Missing Name", label = itemData.label or "Missing Label", @@ -14,12 +13,7 @@ Inventory.GetItemInfo = function(item) 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) - return imagePath or "https://avatars.githubusercontent.com/u/47620135" + return repackedTable or {} end Inventory.GetPlayerInventory = function() @@ -39,3 +33,9 @@ Inventory.GetPlayerInventory = function() end return items end + +Inventory.GetImagePath = function(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 diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index dce5135..0d8a635 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -1,35 +1,11 @@ if GetResourceState('codem-inventory') ~= 'started' then return end -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 +local codem = exports['codem-inventory'] Inventory.GetItemInfo = function(item) - local itemData = codem:GetItemList() - if not itemData[item] then return {} end + local itemData = codem:GetItemList(item) local repackedTable = { name = itemData.name or "Missing Name", label = itemData.label or "Missing Label", @@ -38,27 +14,55 @@ Inventory.GetItemInfo = function(item) description = itemData.description or "none", image = itemData.image or Inventory.GetImagePath(item), } + return repackedTable or {} +end + +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.GetItemBySlot = function(src, slot) + return codem:GetItemBySlot(src, slot) +end + +Inventory.GetPlayerInventory = function(src) + local identifier = Framework.GetPlayerIdentifier(src) + local playerItems = codem:GetInventory(identifier, src) + local repackedTable = {} + for _, v in pairs(playerItems) do + table.insert(repackedTable, { + name = v.name, + count = v.amount, + metadata = v.info, + slot = v.slot, + }) + end 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 +Inventory.RemoveItem = function(src, item, count, slot, metadata) + if not slot and metadata then + local inv = Inventory.GetPlayerInventory(src) + if not inv then return false end + for _, v in pairs(inv) do + if v.name == item and v.metadata == metadata then + slot = v.slot + break end - return count end end + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) + return codem:RemoveItem(src, item, count, slot) +end + +Inventory.SetMetadata = function(src, item, slot, metadata) + return codem:SetItemMetadata(src, slot, metadata) end Inventory.GetItemBySlot = function(src, slot) local slotData = codem:GetItemBySlot(src, slot) - -- The keys are not documented, so this is a best guess + if not slotData then return {} end for _, v in pairs(slotData) do return { name = v.name, @@ -71,32 +75,10 @@ Inventory.GetItemBySlot = function(src, slot) 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