From ae0c45bb91e03a5b2a8507e517e314deb96a6bf8 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Tue, 9 May 2023 10:22:18 +1000 Subject: [PATCH] feat(server/inventory): GetContainerFromSlot --- modules/inventory/server.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/inventory/server.lua b/modules/inventory/server.lua index 3a66e98071..ad42d47851 100644 --- a/modules/inventory/server.lua +++ b/modules/inventory/server.lua @@ -270,6 +270,26 @@ exports('GetInventoryItems', function(inv, owner) return getInventory(inv, owner)?.items end) +---@param inv inventory +---@param slotId number +---@return OxInventory? +function Inventory.GetContainerFromSlot(inv, slotId) + local inventory = Inventory(inv) + local slotData = inventory and inventory.items[slotId] + + if not slotData then return end + + local container = Inventory(slotData.metadata.container) + + if not container then + container = Inventory.Create(slotData.metadata.container, slotData.label, 'container', slotData.metadata.size[1], 0, slotData.metadata.size[2], false) + end + + return container +end + +exports('GetContainerFromSlot', Inventory.GetContainerFromSlot) + ---@param inv? inventory ---@param ignoreId? number|false function Inventory.CloseAll(inv, ignoreId)