diff --git a/Content.Shared/Trigger/Components/Conditions/RandomChanceTriggerConditionComponent.cs b/Content.Shared/Trigger/Components/Conditions/RandomChanceTriggerConditionComponent.cs
new file mode 100644
index 0000000000..2612f16007
--- /dev/null
+++ b/Content.Shared/Trigger/Components/Conditions/RandomChanceTriggerConditionComponent.cs
@@ -0,0 +1,16 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Trigger.Components.Conditions;
+
+///
+/// This condition will cancel triggers based on random chance.
+///
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+public sealed partial class RandomChanceTriggerConditionComponent : BaseTriggerConditionComponent
+{
+ ///
+ /// Chance for the trigger to succeed.
+ ///
+ [DataField, AutoNetworkedField]
+ public float SuccessChance = .9f;
+}
diff --git a/Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs b/Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs
index a917f1ad48..2d0756556a 100644
--- a/Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs
+++ b/Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs
@@ -1,5 +1,7 @@
-using Content.Shared.Trigger.Components.Conditions;
+using Content.Shared.Random.Helpers;
+using Content.Shared.Trigger.Components.Conditions;
using Content.Shared.Verbs;
+using Robust.Shared.Random;
namespace Content.Shared.Trigger.Systems;
@@ -13,6 +15,8 @@ public sealed partial class TriggerSystem
SubscribeLocalEvent(OnToggleTriggerAttempt);
SubscribeLocalEvent>(OnToggleGetAltVerbs);
+
+ SubscribeLocalEvent(OnRandomChanceTriggerAttempt);
}
private void OnWhitelistTriggerAttempt(Entity ent, ref AttemptTriggerEvent args)
@@ -54,4 +58,23 @@ public sealed partial class TriggerSystem
ent.Comp.Enabled = !ent.Comp.Enabled;
Dirty(ent);
}
+
+ private void OnRandomChanceTriggerAttempt(Entity ent,
+ ref AttemptTriggerEvent args)
+ {
+ if (args.Key == null || ent.Comp.Keys.Contains(args.Key))
+ {
+ // TODO: Replace with RandomPredicted once the engine PR is merged
+ var hash = new List
+ {
+ (int)_timing.CurTick.Value,
+ GetNetEntity(ent).Id,
+ args.User == null ? 0 : GetNetEntity(args.User.Value).Id,
+ };
+ var seed = SharedRandomExtensions.HashCodeCombine(hash);
+ var rand = new System.Random(seed);
+
+ args.Cancelled |= !rand.Prob(ent.Comp.SuccessChance); // When not successful, Cancelled = true
+ }
+ }
}