forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 105
feat: Rework and Fix Custom Role Spawn Logic & Limits #578
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
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
Spawn reasons have been set to prevent custom role assignment in incorrect situation.
Refactored the player spawning logic to be lock free by using Interlocked for atomic counters and a ConcurrentDictionary for safe concurrent processing.
louis1706
approved these changes
Jul 5, 2025
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
I changed the system custom roles spawn. The old way was causing many problems like server crashes, unfair selection, broken features and the random chance was not really random. So I moved all the logic to a central place in PlayerHandlers. The new logic uses a proper weighted system to choose roles based on their SpawnChance and it also handles the no role chance correctly. Additionally, the logic for selecting a custom spawn position has been refactored to ensure it is statistically fair.
What is the current behavior? (You can also link to an open issue here)
Currently the server can crash if you have two roles with 100 chance for the same class because they race each other. Also when it works, the selection is not fair, it just picks the first role that it finds in the list. The spawn limit feature is also not working reliably and can be easily bypassed by multiple players spawning at the same time. The spawn position selection is also not truly random, giving an unfair priority to points listed first in the config and not respecting the configured chances as part of a fair lottery.
What is the new behavior? (if this is a feature change)
The logic is all in one place so it is stable and doesnt crash. The role selection is now fair using a weight system. İf total chances of roles are less than 100, there is a chance for no role to be assigned. If total chance is 100 or more, a role is guaranteed. The limit is now handled using interlocked operations.The round based spawn limit (Limit in config) now works reliably. The system will not assign a role if its total spawn count for the round has reached its defined limit, even if many players spawn at once.
Similarly the spawn position selection now uses a proper weighted lottery, making the choice statistically fair and respecting all configured chances.
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No ❌
Other information:
This should fix all the problems with spawning.
https://discord.com/channels/656673194693885975/1368621700320854117
Types of changes
Submission checklist
Patches (if there are any changes related to Harmony patches)
Other