Skip to content

[TF2] Improve the random class selection algorithm to reduce the chance of failure #1434

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bradasparky
Copy link

Description

When picking a random class, the game requires that the randomly chosen class meets the following criteria:

  • The class isn't your current class
  • The class is able to be chosen after checking for gamerules such as tournament mode class limits

Currently, when you choose the random button on the class select menu, the game rolls the dice upwards of 20 times and compares the randomly chosen class to the criteria above on each roll. In the unlikely event that this algorithm fails to find a valid class, the player will be shown the class select menu again. It's possible for this algorithm to fail even when there are valid classes to randomly choose from. This algorithm fails the most when strict class limits are involved on a full server.

This PR reworks the random class selection algorithm to form a list of valid classes before rolling for a valid class from the list. If the only class available is your current class, then it won't redisplay the menu unnecessarily. If there are two classes available and you are already one of them, the random button will always choose the other available class when rolling the dice. The only case where the class select menu will redisplay (to my knowledge) is when every class's limit is full, in which case there's a problem with the server's configuration.

This video showcases a before and after of what happens when the algorithm fails to pick a valid class despite your current class being the only one available. This also happens when the old algorithm picks invalid classes 20 times.

random.class.select.improvement.mp4

Bitl added a commit to BitlDevelopmentStudios/source-sdk-2013-bds-base that referenced this pull request Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant