From: z411 Date: Mon, 5 Jun 2023 22:05:03 +0000 (-0400) Subject: Add warning before removing an excess player X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d6af8e5966d927a3da62c5e6c75f9b0f985cc9fe;p=xonotic%2Fxonotic-data.pk3dir.git Add warning before removing an excess player --- diff --git a/qcsrc/common/notifications/all.inc b/qcsrc/common/notifications/all.inc index b854c04a1..10008a200 100644 --- a/qcsrc/common/notifications/all.inc +++ b/qcsrc/common/notifications/all.inc @@ -680,6 +680,7 @@ string multiteam_info_sprintf(string input, string teamname) { return ((input != MSG_CENTER_NOTIF(DISCONNECT_IDLING, N_ENABLE, 0, 1, "", CPID_IDLING, "1 f1", BOLD(_("^K1Stop idling!\n^BGDisconnecting in ^COUNT...")), "") MSG_CENTER_NOTIF(MOVETOSPEC_IDLING, N_ENABLE, 0, 1, "", CPID_IDLING, "1 f1", BOLD(_("^K1Stop idling!\n^BGMoving to spectators in ^COUNT...")), "") + MSG_CENTER_NOTIF(MOVETOSPEC_REMOVE, N_ENABLE, 1, 1, "s1", CPID_REMOVE, "1 f1", BOLD(_("^K1Teams unbalanced!\n^BGMoving %s^BG to spectators in ^COUNT...")), "") MSG_CENTER_NOTIF(DOOR_LOCKED_NEED, N_ENABLE, 1, 0, "s1", CPID_Null, "0 0", _("^BGYou need %s^BG!"), "") MSG_CENTER_NOTIF(DOOR_LOCKED_ALSONEED, N_ENABLE, 1, 0, "s1", CPID_Null, "0 0", _("^BGYou also need %s^BG!"), "") diff --git a/qcsrc/common/notifications/all.qh b/qcsrc/common/notifications/all.qh index 00bd94bb7..680e339e0 100644 --- a/qcsrc/common/notifications/all.qh +++ b/qcsrc/common/notifications/all.qh @@ -52,6 +52,7 @@ ENUMCLASS(CPID) CASE(CPID, STALEMATE) CASE(CPID, NADES) CASE(CPID, IDLING) + CASE(CPID, REMOVE) CASE(CPID, ITEM) CASE(CPID, PREVENT_JOIN) CASE(CPID, KEEPAWAY) diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index f0e68ce26..148c51461 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -717,6 +717,36 @@ bool TeamBalance_AreEqual(entity ignore) return true; } +entity remove_countdown; +entity remove_player; +int remove_time; + +void Remove_Countdown(entity this) +{ + if(remove_time <= 0 || TeamBalance_AreEqual(NULL)) + { + if(remove_time <= 0) + { + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MOVETOSPEC_REMOVE, remove_player.netname); + PutObserverInServer(remove_player, true, true); + } + + Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_REMOVE); + + delete(this); + remove_countdown = NULL; + remove_player = NULL; + remove_time = 0; + + TeamBalance_RemoveExcessPlayers(NULL); // Check again for excess players in case someone also left while in countdown + return; + } + + Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MOVETOSPEC_REMOVE, remove_player.netname, remove_time); + --remove_time; + this.nextthink = time + 1; +} + void TeamBalance_RemoveExcessPlayers(entity ignore) { if(AVAILABLE_TEAMS != 2 || autocvar_g_campaign) return; @@ -736,7 +766,7 @@ void TeamBalance_RemoveExcessPlayers(entity ignore) for(int tmi = 1; tmi <= AVAILABLE_TEAMS; ++tmi) { int cur = TeamBalance_GetTeamFromIndex(balance, tmi).m_num_players; - if(cur > 0 && cur > min) + if(cur > 0 && cur > min) // If this team has excess players { // Get newest player int latest_join = 0; @@ -753,8 +783,18 @@ void TeamBalance_RemoveExcessPlayers(entity ignore) // Force player to spectate if(latest_join_pl) { - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MOVETOSPEC_REMOVE, latest_join_pl.netname); - PutObserverInServer(latest_join_pl, true, true); + // Send player to spectate + remove_player = latest_join_pl; + remove_time = 10; + + if (!remove_countdown) + { + remove_countdown = new_pure(remove_countdown); + setthink(remove_countdown, Remove_Countdown); + remove_countdown.nextthink = time; + } + //Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MOVETOSPEC_REMOVE, latest_join_pl.netname); + //PutObserverInServer(latest_join_pl, true, true); } } }