fix: bug with not tracking limit of spawned players in custom roles - #585
Merged
louis1706 merged 1 commit intoJul 8, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR addresses a bug in the custom role spawn system by enforcing the configured player limit.
- Added a check to skip role assignment once the spawn limit is reached.
- Treated a limit of 0 as “unlimited” to maintain prior behavior.
Comments suppressed due to low confidence (2)
EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs:927
- There’s no test verifying that
SpawnProperties.Limitis enforced correctly. Consider adding unit or integration tests to cover scenarios where the limit is reached and when it’s treated as unlimited (limit == 0).
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit))
EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs:927
- [nitpick] Using
Limit == 0to represent "unlimited" can be non-intuitive. You might consider usingnullor-1, or ensure the API docs clearly state that zero disables the limit check.
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit))
Comment on lines
+927
to
930
| if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit)) | ||
| AddRole(ev.Player); | ||
| } | ||
|
|
There was a problem hiding this comment.
[nitpick] This condition is becoming quite long and could be extracted into a well-named helper method (e.g. CanSpawnMorePlayers(ev.Player)) to improve readability and reduce complexity.
Suggested change
| if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance && (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit)) | |
| AddRole(ev.Player); | |
| } | |
| if (CanSpawnMorePlayers(ev.Player)) | |
| AddRole(ev.Player); | |
| } | |
| private bool CanSpawnMorePlayers(Player player) | |
| { | |
| return !IgnoreSpawnSystem && | |
| SpawnChance > 0 && | |
| !Check(player) && | |
| player.Role.Type == Role && | |
| Loader.Random.NextDouble() * 100 <= SpawnChance && | |
| (SpawnProperties.Limit == 0 || TrackedPlayers.Count < SpawnProperties.Limit); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Describe the changes
Fixes bug with custom roles spawn system
What is the current behavior? (You can also link to an open issue here)
ignores limit for spawn
What is the new behavior? (if this is a feature change)
do not give custom role if limit was reached
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
no
Other information:
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other