From 791c43c91c9281d44eac3484c20cc988e1ac1873 Mon Sep 17 00:00:00 2001 From: Andrew De palma Date: Sun, 19 Oct 2025 23:00:34 +0200 Subject: [PATCH 1/3] added MinPlayers property --- EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index f29e2d525c..c865044e10 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -110,6 +110,11 @@ public abstract class CustomRole /// public virtual SpawnProperties SpawnProperties { get; set; } = new(); + /// + /// Gets or sets the minimum number of players connected needed in order to add the role. + /// + public virtual int MinPlayers { get; set; } + /// /// Gets or sets a value indicating whether players keep their current position when gaining this role. /// @@ -548,7 +553,7 @@ public virtual void AddRole(Player player) Log.Debug($"{Name}: Adding role to {player.Nickname}."); player.UniqueRole = Name; - if (Role != RoleTypeId.None) + if (Role != RoleTypeId.None && (MinPlayers is 0 || Server.PlayerCount == MinPlayers)) { try { @@ -1020,4 +1025,4 @@ private void OnSpawningRagdoll(SpawningRagdollEventArgs ev) private void OnDestroying(DestroyingEventArgs ev) => RemoveRole(ev.Player); } -} +} \ No newline at end of file From afe167ca8b8f6b925ddbfd20346e22bc017e13dc Mon Sep 17 00:00:00 2001 From: Andrew De palma Date: Thu, 23 Oct 2025 21:59:48 +0200 Subject: [PATCH 2/3] changed MinPlayer check's position --- EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs | 2 +- EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs index c865044e10..f4c8a72264 100644 --- a/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs +++ b/EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs @@ -553,7 +553,7 @@ public virtual void AddRole(Player player) Log.Debug($"{Name}: Adding role to {player.Nickname}."); player.UniqueRole = Name; - if (Role != RoleTypeId.None && (MinPlayers is 0 || Server.PlayerCount == MinPlayers)) + if (Role != RoleTypeId.None) { try { diff --git a/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs b/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs index 1a10e38dcf..f4a0b46b51 100644 --- a/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs +++ b/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs @@ -75,7 +75,7 @@ internal void OnSpawned(SpawnedEventArgs ev) foreach (CustomRole role in CustomRole.Registered) { - if (role.Role == ev.Player.Role.Type && !role.IgnoreSpawnSystem && role.SpawnChance > 0 && !role.Check(ev.Player) && (role.SpawnProperties is null || role.SpawnedPlayers < role.SpawnProperties.Limit)) + if (role.Role == ev.Player.Role.Type && !role.IgnoreSpawnSystem && role.SpawnChance > 0 && !role.Check(ev.Player) && (role.SpawnProperties is null || role.SpawnedPlayers < role.SpawnProperties.Limit) && (role.MinPlayers is 0 || Server.PlayerCount == role.MinPlayers)) { eligibleRoles.Add(role); totalChance += role.SpawnChance; @@ -123,4 +123,4 @@ internal void OnSpawned(SpawnedEventArgs ev) } } } -} +} \ No newline at end of file From 1c117e70a3ba0790b3c45dbc058068968db9f529 Mon Sep 17 00:00:00 2001 From: Andrew De palma Date: Tue, 28 Oct 2025 15:47:05 +0100 Subject: [PATCH 3/3] changed == to >= --- EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs b/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs index f4a0b46b51..a52a00f6d7 100644 --- a/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs +++ b/EXILED/Exiled.CustomRoles/Events/PlayerHandlers.cs @@ -75,7 +75,7 @@ internal void OnSpawned(SpawnedEventArgs ev) foreach (CustomRole role in CustomRole.Registered) { - if (role.Role == ev.Player.Role.Type && !role.IgnoreSpawnSystem && role.SpawnChance > 0 && !role.Check(ev.Player) && (role.SpawnProperties is null || role.SpawnedPlayers < role.SpawnProperties.Limit) && (role.MinPlayers is 0 || Server.PlayerCount == role.MinPlayers)) + if (role.Role == ev.Player.Role.Type && !role.IgnoreSpawnSystem && role.SpawnChance > 0 && !role.Check(ev.Player) && (role.SpawnProperties is null || role.SpawnedPlayers < role.SpawnProperties.Limit) && (role.MinPlayers is 0 || Server.PlayerCount >= role.MinPlayers)) { eligibleRoles.Add(role); totalChance += role.SpawnChance;