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

Conversation

TiBarification
Copy link

@TiBarification TiBarification commented Jul 5, 2025

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentations

Submission checklist

  • I have checked the project can be compiled
  • I have tested my changes and it worked as expected

Patches (if there are any changes related to Harmony patches)

  • I have checked no IL patching errors in the console

Other

  • Still requires more testing

@Copilot Copilot AI review requested due to automatic review settings July 5, 2025 15:28
@TiBarification TiBarification changed the title fixes bug with not tracking limit of spawned players fix: bug with not tracking limit of spawned players in custom roles Jul 5, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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.Limit is 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 == 0 to represent "unlimited" can be non-intuitive. You might consider using null or -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);
}

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.

@louis1706 louis1706 merged commit 7ea3ccc into ExMod-Team:master Jul 8, 2025
5 of 6 checks passed
louis1706 added a commit that referenced this pull request Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants