GetPlayerInventory client side, event fires client now

community_bridge:client:inventory:updateInventory
This commit is contained in:
MrNewb committed 2025-02-05 01:54:55 -05:00
1 parent 651c8ae6df
commit 2a326c4811
14 files changed
+110 -3

No files matched your search

@@ -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
@@ -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