diff --git a/Content.Server/VendingMachines/VendingMachineSystem.cs b/Content.Server/VendingMachines/VendingMachineSystem.cs index d30c48fe2fb..eefb1dcd4a8 100644 --- a/Content.Server/VendingMachines/VendingMachineSystem.cs +++ b/Content.Server/VendingMachines/VendingMachineSystem.cs @@ -415,17 +415,21 @@ public void EjectRandom(EntityUid uid, bool throwItem, bool forceEject = false, var item = _random.Pick(availableItems); - if (forceEject) + if (vendComponent.EjectRandomMax > vendComponent.EjectRandomCounter) { - vendComponent.NextItemToEject = item.ID; - vendComponent.ThrowNextItem = throwItem; - var entry = GetEntry(uid, item.ID, item.Type, vendComponent); - if (entry != null) - entry.Amount--; - //EjectItem(uid, vendComponent, forceEject); // Stop vending machine from giving free items + if (forceEject) + { + vendComponent.NextItemToEject = item.ID; + vendComponent.ThrowNextItem = throwItem; + var entry = GetEntry(uid, item.ID, item.Type, vendComponent); + if (entry != null) + entry.Amount--; + EjectItem(uid, vendComponent, forceEject); + } + else + TryEjectVendorItem(uid, item.Type, item.ID, throwItem, 0, vendComponent); + vendComponent.EjectRandomCounter += 1; } - //else - //TryEjectVendorItem(uid, item.Type, item.ID, throwItem, 0, vendComponent); // Stop vending machine from giving free items } private void EjectItem(EntityUid uid, VendingMachineComponent? vendComponent = null, bool forceEject = false) diff --git a/Content.Shared/VendingMachines/VendingMachineComponent.cs b/Content.Shared/VendingMachines/VendingMachineComponent.cs index b648d36f4e0..f87867397ad 100644 --- a/Content.Shared/VendingMachines/VendingMachineComponent.cs +++ b/Content.Shared/VendingMachines/VendingMachineComponent.cs @@ -32,6 +32,18 @@ public sealed class VendingMachineComponent : Component [DataField("ejectDelay")] public float EjectDelay = 1.2f; + /// + /// Used by the server to determine how many items the machine allowed to eject from random triggers. + /// + [DataField("ejectRandomMax")] + public float EjectRandomMax = 3f; + + /// + /// Used by the server to determine how many items the machine ejected from random triggers. + /// + [DataField("ejectRandomCounter")] + public float EjectRandomCounter = 0f; + [ViewVariables] public Dictionary Inventory = new();