From 10c35355e55886011d8b7a90ccc9ae2655aa1254 Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Wed, 1 Jan 2020 17:04:12 +0100 Subject: [PATCH] Fixed item stacking bug --- gamemode/engine/lib/server/sv_inventory.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index 2c46c84..486d71d 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -91,12 +91,18 @@ local function sortItem( char, itemid, amount ) if( itemInSlot != nil ) then if( itemInSlot[1] == itemid && itemInSlot[2] < stacksize ) then - local setAmt = math.Clamp( itemInSlot[2] + amount, 1, stacksize ) - local diff = ( itemInSlot[2] + amount ) - setAmt - rest = rest - diff ------------------------------------------------------ FIX THIS (DIFF IS WRONG) + local add = itemInSlot[2] + amount + if( add > stacksize ) then + rest = rest - ( stacksize - itemInSlot[2] ) + else + rest = rest - amount + end + local setAmt = math.Clamp( add, 1, stacksize ) + --local diff = amount - setAmt + --rest = rest - diff ------------------------------------------------------ FIX THIS (DIFF IS WRONG) Quantum.Server.Inventory.SetSlotItem( char, index, itemid, setAmt ) - print( "1", setAmt, rest, index, diff ) + print( "1", setAmt, rest, index ) end else local setAmt = math.Clamp( amount, 1, stacksize )