From 6e18de8a1c1595066523e9dd848612480fa53cf8 Mon Sep 17 00:00:00 2001 From: DoopieWop <62191983+DoopieWop@users.noreply.github.com> Date: Sat, 18 Jan 2025 18:48:22 +0100 Subject: [PATCH 1/3] simplified INVENTORY:Remove() function --- gamemode/core/meta/sh_inventory.lua | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/gamemode/core/meta/sh_inventory.lua b/gamemode/core/meta/sh_inventory.lua index ffd3db3c6..6e282e4f9 100644 --- a/gamemode/core/meta/sh_inventory.lua +++ b/gamemode/core/meta/sh_inventory.lua @@ -338,19 +338,15 @@ end -- @treturn number The Y position that the item was removed from function META:Remove(id, bNoReplication, bNoDelete, bTransferring) local x2, y2 + local item = ix.item.instances[id] - for x = 1, self.w do - if (self.slots[x]) then - for y = 1, self.h do - local item = self.slots[x][y] - - if (item and item.id == id) then - self.slots[x][y] = nil + if (item and item.invID == self.id) then + local x, y = item.gridX, item.gridY + if (self.slots[x] and self.slots[x][y] and self.slots[x][y].id == id) then + self.slots[x][y] = nil - x2 = x2 or x - y2 = y2 or y - end - end + x2 = x + y2 = y end end From 8129323adde05d1f55b5bb420b98c76875bc3087 Mon Sep 17 00:00:00 2001 From: DoopieWop <62191983+DoopieWop@users.noreply.github.com> Date: Sat, 18 Jan 2025 18:49:52 +0100 Subject: [PATCH 2/3] simplified ITEM:Remove() function and removed non-functional code --- gamemode/core/meta/sh_item.lua | 36 ++++------------------------------ 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/gamemode/core/meta/sh_item.lua b/gamemode/core/meta/sh_item.lua index a95845d6c..f65d04dec 100644 --- a/gamemode/core/meta/sh_item.lua +++ b/gamemode/core/meta/sh_item.lua @@ -419,38 +419,10 @@ function ITEM:Remove(bNoReplication, bNoDelete) local inv = ix.item.inventories[self.invID] if (self.invID > 0 and inv) then - local failed = false - - for x = self.gridX, self.gridX + (self.width - 1) do - if (inv.slots[x]) then - for y = self.gridY, self.gridY + (self.height - 1) do - local item = inv.slots[x][y] - - if (item and item.id == self.id) then - inv.slots[x][y] = nil - else - failed = true - end - end - end - end - - if (failed) then - inv.slots = {} - for k, _ in inv:Iter() do - if (k.invID == inv:GetID()) then - for x = self.gridX, self.gridX + (self.width - 1) do - for y = self.gridY, self.gridY + (self.height - 1) do - inv.slots[x][y] = k.id - end - end - end - end - - if (IsValid(inv.owner) and inv.owner:IsPlayer()) then - inv:Sync(inv.owner, true) - end - + local x, y = self.gridX, self.gridY + if (inv.slots[x] and inv.slots[x][y] and inv.slots[x][y].id == self.id) then + inv.slots[x][y] = nil + else return false end else From f73af6658a57de0eca4af35eed6264e2fa3bb611 Mon Sep 17 00:00:00 2001 From: DoopieWop <62191983+DoopieWop@users.noreply.github.com> Date: Sat, 18 Jan 2025 19:11:22 +0100 Subject: [PATCH 3/3] fixed shadowing definition for "item" variable in INVENTORY:Remove() --- gamemode/core/meta/sh_inventory.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/gamemode/core/meta/sh_inventory.lua b/gamemode/core/meta/sh_inventory.lua index 6e282e4f9..67a951c26 100644 --- a/gamemode/core/meta/sh_inventory.lua +++ b/gamemode/core/meta/sh_inventory.lua @@ -366,8 +366,6 @@ function META:Remove(id, bNoReplication, bNoDelete, bTransferring) end if (!bNoDelete) then - local item = ix.item.instances[id] - if (item and item.OnRemoved) then item:OnRemoved() end