From 561b5e1c20958312253a8478d71bdcdd7ddff0df Mon Sep 17 00:00:00 2001 From: terencehill Date: Thu, 25 Aug 2016 01:40:38 +0200 Subject: [PATCH] Enhance LeaveSpectatorMode code so it can handle the join command too (called by the teamselect dialog) allowing to remove some duplicated code --- qcsrc/server/client.qc | 17 ++++++++++++++--- qcsrc/server/command/cmd.qc | 33 +++++++++++---------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 0c4832425..c9a8dd5d8 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1861,11 +1861,12 @@ void ShowRespawnCountdown(entity this) } } +.int team_selected; void LeaveSpectatorMode(entity this) { if(nJoinAllowed(this, this)) { - if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0) + if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || this.team_selected || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0) { TRANSMUTE(Player, this); @@ -1880,8 +1881,10 @@ void LeaveSpectatorMode(entity this) Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN); PutClientInServer(this); + PlayerScore_Clear(this); if(IS_PLAYER(this)) { Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), this.netname); } + this.team_selected = false; } else stuffcmd(this, "menu_showteamselect\n"); @@ -1998,6 +2001,14 @@ void PrintWelcomeMessage(entity this) } } +bool spawnAllowed(entity this) +{ + if (this.version_mismatch) return false; + if (teamplay && lockteams) return false; + if (MUTATOR_CALLHOOK(ForbidSpawn, this)) return false; + return true; +} + void ObserverThink(entity this) { if ( this.impulse ) @@ -2007,7 +2018,7 @@ void ObserverThink(entity this) } if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) { + if (PHYS_INPUT_BUTTON_JUMP(this) && spawnAllowed(this)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) { @@ -2048,7 +2059,7 @@ void SpectatorThink(entity this) } if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) { + if (PHYS_INPUT_BUTTON_JUMP(this) && spawnAllowed(this)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) { diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index e23f9bc98..5d6ad3ada 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -159,33 +159,19 @@ void ClientCommand_mv_getpicture(entity caller, float request, float argc) // i } } +bool spawnAllowed(entity this); +void LeaveSpectatorMode(entity this); void ClientCommand_join(entity caller, float request) { switch (request) { case CMD_REQUEST_COMMAND: { - if (IS_CLIENT(caller)) - { - if (!IS_PLAYER(caller) && !lockteams && !gameover) - { - if (caller.caplayer) return; - if (nJoinAllowed(caller, caller)) - { - if (autocvar_g_campaign) campaign_bots_may_start = true; - TRANSMUTE(Player, caller); - PlayerScore_Clear(caller); - Kill_Notification(NOTIF_ONE_ONLY, caller, MSG_CENTER, CPID_PREVENT_JOIN); - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && caller.team != -1) ? APP_TEAM_ENT(caller, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), caller.netname); - PutClientInServer(caller); - } - else - { - // player may not join because of g_maxplayers is set - Send_Notification(NOTIF_ONE_ONLY, caller, MSG_CENTER, CENTER_JOIN_PREVENT); - } - } - } + if (!gameover) + if (IS_CLIENT(caller) && !IS_PLAYER(caller)) + if (spawnAllowed(caller)) + LeaveSpectatorMode(caller); + return; // never fall through to usage } @@ -326,6 +312,7 @@ void ClientCommand_say_team(entity caller, float request, float argc, string com } } +.int selectedteam; void ClientCommand_selectteam(entity caller, float request, float argc) { switch (request) @@ -363,7 +350,7 @@ void ClientCommand_selectteam(entity caller, float request, float argc) if (selection) { - if (caller.team == selection && !IS_DEAD(caller)) + if (caller.team == selection && selection != -1 && !IS_DEAD(caller)) { sprint(caller, "^7You already are on that team.\n"); } @@ -385,6 +372,8 @@ void ClientCommand_selectteam(entity caller, float request, float argc) } ClientKill_TeamChange(caller, selection); } + if(!IS_PLAYER(caller)) + caller.team_selected = true; // avoids asking again for team selection on join } } else -- 2.39.2