diff --git a/MiraAPI/Networking/CustomMurderRpc.cs b/MiraAPI/Networking/CustomMurderRpc.cs index 0a31cf1..43c86cd 100644 --- a/MiraAPI/Networking/CustomMurderRpc.cs +++ b/MiraAPI/Networking/CustomMurderRpc.cs @@ -287,7 +287,7 @@ public static class CustomMurderRpc source.CurrentOutfitType == PlayerOutfitType.Shapeshifted, source.shapeshiftTargetPlayerId, target.PlayerId); - source.MyPhysics.StartCoroutine(source.KillAnimations.Random()?.CoPerformCustomKill(source, target, createDeadBody, teleportMurderer)); + source.MyPhysics.StartCoroutine(source.KillAnimations.RandomSnapshot().CoPerformCustomKill(source, target, createDeadBody, teleportMurderer)); } /// diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index c45e4b2..8c4acc7 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -132,6 +132,31 @@ public static class Extensions button.SetCooldownFill(num); } + /// + /// Returns a random element from the specified sequence. + /// + /// + /// The sequence to select an element from. + /// + /// + /// The type of elements in the sequence. + /// + /// + /// A randomly selected element from . + /// + /// + /// Thrown when is empty. + /// + public static T RandomSnapshot(this IEnumerable input) + { + var list = input.ToList(); + + if (list.Count == 0) + throw new InvalidOperationException("Cannot get random element from an empty collection."); + + return list[UnityEngine.Random.Range(0, list.Count)]; + } + /// /// Gets a PlayerControl from their PlayerVoteArea in a meeting. ///