Automatically buy entire stock

This commit is contained in:
2025-03-30 01:44:32 +01:00
parent d0cbb14f40
commit 2ae13a7577

View File

@@ -650,19 +650,25 @@ Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptab
local items = cargoManager:GetBuyCrateItems(store) local items = cargoManager:GetBuyCrateItems(store)
for item in items do for item in items do
-- We have already added this many of item -- 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 end
for item in store.Stock do for item in store.Stock do
-- So if we add the total amount available -- So if we add the total amount available
-- We get the amount we have to add to buy entire stock -- We get the amount we have to add to buy entire stock
if toAdd[item.ItemPrefab.Identifier.Value] then local idValue = item.ItemPrefab.Identifier.Value
toAdd[item.ItemPrefab.Identifier.Value] = toAdd[item.ItemPrefab.Identifier.Value] + item.Quantity if toAdd[idValue] then
toAdd[idValue].quantity = toAdd[idValue].quantity + item.Quantity
end end
end end
for item, amount in pairs(toAdd) do
if amount > 0 then for idValue, info in pairs(toAdd) do
print(string.format("Adding %d of %s to the buy crate", amount, item)) if info.quantity > 0 then
cargoManager.ModifyItemQuantityInBuyCrate(store.Identifier, item, amount) 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 end
end end