- entity destination_team = TeamBalance_GetTeamFromIndex(balance,
- destination_team_index);
- if ((destination_team.m_num_players <= source_team.m_num_players) ||
- (destination_team.m_lowest_bot == NULL))
+ TeamBalance_Destroy(balance);
+ entity lowest_bot = NULL;
+ if (MUTATOR_CALLHOOK(TeamBalance_GetPlayerForTeamSwitch, source_team_index,
+ destination_team_index, true))
+ {
+ lowest_bot = M_ARGV(3, entity);
+ }
+ else
+ {
+ float lowest_score = FLOAT_MAX;
+ FOREACH_CLIENT(IS_BOT_CLIENT(it) && (Entity_GetTeamIndex(it) ==
+ source_team_index),
+ {
+ float temp_score = PlayerScore_Get(it, SP_SCORE);
+ if (temp_score >= lowest_score)
+ {
+ continue;
+ }
+ balance = TeamBalance_CheckAllowedTeams(it);
+ if (TeamBalance_IsTeamAllowed(balance, destination_team_index))
+ {
+ lowest_bot = it;
+ lowest_score = temp_score;
+ }
+ TeamBalance_Destroy(balance);
+ });
+ }
+ if (lowest_bot == NULL)