From 2a326c48112050cd3a7b6b73f98cc808ce143c53 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Wed, 5 Feb 2025 01:54:55 -0500 Subject: [PATCH] GetPlayerInventory client side, event fires client now community_bridge:client:inventory:updateInventory --- fxmanifest.lua | 2 +- modules/framework/qb-core/client.lua | 16 +++++++++++++- modules/framework/qb-core/server.lua | 2 ++ modules/framework/qbx_core/server.lua | 2 ++ modules/inventory/codem-inventory/client.lua | 18 ++++++++++++++++ modules/inventory/codem-inventory/server.lua | 4 ++++ modules/inventory/origen_inventory/client.lua | 18 ++++++++++++++++ modules/inventory/origen_inventory/server.lua | 2 ++ modules/inventory/ox_inventory/client.lua | 4 ++++ modules/inventory/ox_inventory/server.lua | 2 ++ modules/inventory/qs-inventory/client.lua | 21 ++++++++++++++++++- modules/inventory/qs-inventory/server.lua | 2 ++ modules/inventory/tgiann-inventory/client.lua | 18 ++++++++++++++++ modules/inventory/tgiann-inventory/server.lua | 2 ++ 14 files changed, 110 insertions(+), 3 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 437e01c..2fa8cc8 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ lua54 'yes' use_experimental_fxv2_oal 'yes' author 'The Order of the Sacred Framework' description 'A bridge made for the community to use as a base for their own projects. This bridge will allow a single format to work with nearly all commonly used systems while still offering expandability.' -version '0.2.1' +version '0.2.2' shared_scripts { '@ox_lib/init.lua', diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index 0b4f254..b7dd1f8 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -46,7 +46,21 @@ Framework.GetPlayerJob = function() end Framework.GetPlayerInventory = function() - return QBCore.Functions.GetPlayerData().items + local items = {} + local frameworkInv = QBCore.Functions.GetPlayerData().items + for _, v in pairs(frameworkInv) 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 Framework.GetIsPlayerDead = function() diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index 274790a..6a52056 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -240,6 +240,7 @@ end -- Adds the specified item to the player's inventory. Framework.AddItem = function(src, item, amount, slot, metadata) local player = QBCore.Functions.GetPlayer(src) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) return player.Functions.AddItem(item, amount, slot, metadata) end @@ -247,6 +248,7 @@ end -- Removes the specified item from the player's inventory. Framework.RemoveItem = function(src, item, amount, slot, metadata) local player = QBCore.Functions.GetPlayer(src) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) return player.Functions.RemoveItem(item, amount, slot or nil) end diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index f2b68e9..4459593 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -218,6 +218,7 @@ end -- Adds the specified item to the player's inventory. Framework.AddItem = function(src, item, amount, slot, metadata) local player = QBox:GetPlayer(src) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) return player.Functions.AddItem(item, amount, slot, metadata) end @@ -225,6 +226,7 @@ end -- Removes the specified item from the player's inventory. Framework.RemoveItem = function(src, item, amount, slot, metadata) local player = QBox:GetPlayer(src) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) return player.Functions.RemoveItem(item, amount, slot) end diff --git a/modules/inventory/codem-inventory/client.lua b/modules/inventory/codem-inventory/client.lua index f09c41f..6ad452c 100644 --- a/modules/inventory/codem-inventory/client.lua +++ b/modules/inventory/codem-inventory/client.lua @@ -20,4 +20,22 @@ 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" +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 \ No newline at end of file diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index 9164fab..dce5135 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -5,17 +5,21 @@ 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 diff --git a/modules/inventory/origen_inventory/client.lua b/modules/inventory/origen_inventory/client.lua index 389cf2f..ebb4154 100644 --- a/modules/inventory/origen_inventory/client.lua +++ b/modules/inventory/origen_inventory/client.lua @@ -21,4 +21,22 @@ Inventory.GetImagePath = function(item) local file = LoadResourceFile("origen_inventory", string.format("html/images/%s.png", item)) local imagePath = file and string.format("nui://origen_inventory/html/images/%s.png", item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +Inventory.GetPlayerInventory = function() + local items = {} + local inventory = origin:GetInventory() + for _, v in pairs(inventory) do + table.insert(items, { + name = v.name, + label = v.label, + count = v.count, + slot = v.slot, + metadata = v.metadata, + stack = v.unique, + close = v.useable, + weight = v.weight + }) + end + return items end \ No newline at end of file diff --git a/modules/inventory/origen_inventory/server.lua b/modules/inventory/origen_inventory/server.lua index 86d5ec3..a281302 100644 --- a/modules/inventory/origen_inventory/server.lua +++ b/modules/inventory/origen_inventory/server.lua @@ -5,10 +5,12 @@ Inventory = Inventory or {} local origen_inventory = exports.origen_inventory 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 origen_inventory:AddItem(src, item, count, metadata, slot, true) end Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) return origen_inventory:removeItem(src, item, count, metadata, slot, true) end diff --git a/modules/inventory/ox_inventory/client.lua b/modules/inventory/ox_inventory/client.lua index 83a2f18..3f1c239 100644 --- a/modules/inventory/ox_inventory/client.lua +++ b/modules/inventory/ox_inventory/client.lua @@ -23,4 +23,8 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end +Inventory.GetPlayerInventory = function() + return exports.ox_inventory:GetPlayerItems() +end + --Bridge.RegisterModule("Inventory", Inventory) \ No newline at end of file diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 364a173..442b14d 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -5,10 +5,12 @@ local ox_inventory = exports.ox_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 ox_inventory:AddItem(src, item, count, metadata) end Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) return ox_inventory:RemoveItem(src, item, count, metadata, slot) end diff --git a/modules/inventory/qs-inventory/client.lua b/modules/inventory/qs-inventory/client.lua index be612bd..a7b7c1d 100644 --- a/modules/inventory/qs-inventory/client.lua +++ b/modules/inventory/qs-inventory/client.lua @@ -25,4 +25,23 @@ Inventory.GetImagePath = function(item) local file = LoadResourceFile("qs-inventory", string.format("html/images/%s.png", item)) local imagePath = file and string.format("nui://qs-inventory/html/images/%s.png", item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" -end \ No newline at end of file +end + +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 + diff --git a/modules/inventory/qs-inventory/server.lua b/modules/inventory/qs-inventory/server.lua index bca1d5f..d8aecb9 100644 --- a/modules/inventory/qs-inventory/server.lua +++ b/modules/inventory/qs-inventory/server.lua @@ -6,10 +6,12 @@ Inventory = Inventory or {} Inventory.AddItem = function(src, item, count, slot, metadata) if not quasar:CanCarryItem(src, item, count) then return false end + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) return quasar:AddItem(src, item, count, slot, metadata) end Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) return quasar:RemoveItem(src, item, count, slot, metadata) end diff --git a/modules/inventory/tgiann-inventory/client.lua b/modules/inventory/tgiann-inventory/client.lua index 41cfc13..9508c85 100644 --- a/modules/inventory/tgiann-inventory/client.lua +++ b/modules/inventory/tgiann-inventory/client.lua @@ -26,4 +26,22 @@ Inventory.GetImagePath = function(item) local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item)) local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" +end + +Inventory.GetPlayerInventory = function() + local items = {} + local inventory = tgiann:GetPlayerItems() + 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 \ No newline at end of file diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index d190e26..8a0a914 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -6,10 +6,12 @@ Inventory = Inventory or {} Inventory.AddItem = function(src, item, count, slot, metadata) if not tgiann:CanCarryItem(src, item, count) then return false end + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata}) return tgiann:AddItem(src, item, count, slot, metadata, false) end Inventory.RemoveItem = function(src, item, count, slot, metadata) + TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = count, slot = slot, metadata = metadata}) return tgiann:RemoveItem(src, item, count, slot, metadata) end