diff --git a/QuickStackToBag/Lua/Autorun/init.lua b/QuickStackToBag/Lua/Autorun/init.lua index cc206fc..024ec62 100644 --- a/QuickStackToBag/Lua/Autorun/init.lua +++ b/QuickStackToBag/Lua/Autorun/init.lua @@ -650,19 +650,25 @@ Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptab local items = cargoManager:GetBuyCrateItems(store) for item in items do -- We have already added this many of item - toAdd[item.ItemPrefab.Identifier.Value] = -item.Quantity + toAdd[item.ItemPrefab.Identifier.Value] = { + quantity = -item.Quantity, + prefab = item.ItemPrefab -- Store the ItemPrefab object + } end for item in store.Stock do -- So if we add the total amount available -- We get the amount we have to add to buy entire stock - if toAdd[item.ItemPrefab.Identifier.Value] then - toAdd[item.ItemPrefab.Identifier.Value] = toAdd[item.ItemPrefab.Identifier.Value] + item.Quantity + local idValue = item.ItemPrefab.Identifier.Value + if toAdd[idValue] then + toAdd[idValue].quantity = toAdd[idValue].quantity + item.Quantity end end - for item, amount in pairs(toAdd) do - if amount > 0 then - print(string.format("Adding %d of %s to the buy crate", amount, item)) - cargoManager.ModifyItemQuantityInBuyCrate(store.Identifier, item, amount) + + for idValue, info in pairs(toAdd) do + if info.quantity > 0 then + print(string.format("Adding %d of %s to the buy crate", info.quantity, idValue)) + -- Use the stored ItemPrefab object, not the string identifier + cargoManager:ModifyItemQuantityInBuyCrate(store.Identifier, info.prefab, info.quantity) end end end