Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified Item and Inventory "Remove" function as well as removed non-functional code #477

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions gamemode/core/meta/sh_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -370,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
Expand Down
36 changes: 4 additions & 32 deletions gamemode/core/meta/sh_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading