Skip to content

fix: bug with not tracking limit of spawned players in custom roles #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EXILED/Exiled.CustomRoles/API/Features/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ private void OnInternalChangingNickname(ChangingNicknameEventArgs ev)

private void OnInternalSpawned(SpawnedEventArgs ev)
{
if (!IgnoreSpawnSystem && SpawnChance > 0 && !Check(ev.Player) && ev.Player.Role.Type == Role && Loader.Random.NextDouble() * 100 <= SpawnChance)
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);
}

Comment on lines +927 to 930
Copy link
Preview

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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);
}

Copilot uses AI. Check for mistakes.

Expand Down
Loading