From 3d1a1fec8848b95b45f74bb910d5208026a8b3c6 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 26 Jan 2025 04:12:57 +0100 Subject: [PATCH] Make sure team is consistently set to -1 on connection for human players and bots Thanks to this change * the Player_ChangeTeam and Player_ChangedTeam mutator hooks (currently unused by any mutator / gamemode) are consistently no longer called on connection * the workaround in Player_SetTeamIndex that handles the situation where a bot unintentionally spawns with a valid team set depending on its personal colors is no longer needed --- qcsrc/server/bot/default/bot.qc | 3 ++- qcsrc/server/client.qc | 1 + qcsrc/server/teamplay.qc | 14 ++++---------- qcsrc/server/teamplay.qh | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index 6965b0795..e4356fb02 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -312,8 +312,9 @@ void bot_setnameandstuff(entity this) this.bot_config_loaded = true; - // this is really only a default, TeamBalance_JoinBestTeam is called later setcolor(this, stof(bot_shirt) * 16 + stof(bot_pants)); + this.team = -1; // undo team change by setcolor + // save clientcolors now because they may be overriden when joining a team this.bot_preferredcolors = this.clientcolors; string prefix = (autocvar_g_campaign ? "" : autocvar_bot_prefix); diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 9c2aaf892..b3a9a806c 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1141,6 +1141,7 @@ void ClientConnect(entity this) bot_clientconnect(this); + this.team = -1; Player_DetermineForcedTeam(this); TRANSMUTE(Observer, this); diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index c442a78d6..478ba1491 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -165,8 +165,10 @@ void setcolor(entity this, int clr) if(teamplay) this.team = (clr & 15) + 1; else - this.team = 0; + this.team = -1; #else + // sets clientcolors and team (even in FFA games) + // and sends notification to all clients builtin_setcolor(this, clr); #endif } @@ -209,16 +211,8 @@ bool Player_SetTeamIndex(entity player, int index) { int new_team = Team_IndexToTeam(index); if (player.team == new_team) - { - if (new_team != -1) - { - // This is important when players join the game and one of their - // color matches the team color while other doesn't. For example - // [BOT]Lion: color 0 4. - SetPlayerColors(player, new_team - 1); - } return true; - } + int old_index = Team_TeamToIndex(player.team); if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, old_index, index) == true) { diff --git a/qcsrc/server/teamplay.qh b/qcsrc/server/teamplay.qh index b1f1255c1..947da8bae 100644 --- a/qcsrc/server/teamplay.qh +++ b/qcsrc/server/teamplay.qh @@ -354,7 +354,7 @@ int TeamBalance_CompareTeamsInternal(entity team_a, entity team_index_b, entity player, bool use_score); /// \brief Called when the player changes color with the "color" command. -/// Note that the "color" command is always called early on player connection +/// \note the "color" command is always called early on player connection /// \param[in,out] player Player that requested a new color. /// \param[in] new_color Requested color. void SV_ChangeTeam(entity player, int new_color); -- 2.39.5