Skip to content

Conversation

@MS-crew
Copy link

@MS-crew MS-crew commented Jun 21, 2025

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

  • 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

@MS-crew MS-crew changed the title feat: Rework and Fix Custom role spawn logic feat: Rework and Fix Custom Role Spawn Logic & Limits Jun 21, 2025
@louis1706 louis1706 merged commit 1aeeb08 into ExMod-Team:dev Jul 5, 2025
6 checks passed
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