From 45da8007011542ca3b5979b7f85827b10632f1fc Mon Sep 17 00:00:00 2001 From: Mircea Kitsune Date: Sat, 6 Oct 2012 02:18:50 +0300 Subject: [PATCH] Show respawn information below the scoreboard when dead. Useful to know if you've already triggered a respawn, or how long you have to wait until you can spawn back. Uses a single extra stat for all info --- qcsrc/client/scoreboard.qc | 19 +++++++++++++++++++ qcsrc/common/constants.qh | 2 ++ qcsrc/server/cl_client.qc | 8 ++++++++ qcsrc/server/defs.qh | 2 ++ qcsrc/server/g_world.qc | 3 +++ 5 files changed, 34 insertions(+) diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 48a7217fc..9bcb516a5 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -1374,6 +1374,25 @@ void HUD_DrawScoreboard() } } + // add information about respawn status + float respawn_time = getstatf(STAT_RESPAWN_SCHEDULE); + if(respawn_time) + { + if(respawn_time < 0) + { + // a negative value means we are awaiting respawn, time value is still the same + respawn_time *= -1; // remove our mark now that we checked it + str = strcat(str, "\n\nRespawning in ", ftos(respawn_time - time), " seconds..."); + } + else if(time < respawn_time) + { + str = strcat(str, "\n\nYou are dead, wait ", ftos(respawn_time - time), " seconds before respawning"); + } + else if(time >= respawn_time) + { + str = strcat(str, "\n\nYou are dead, press fire to respawn"); + } + } pos_y += 1.2 * hud_fontsize_y; drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, hud_fontsize)), str, hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL); diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index c270b61a9..8bbbd2ee2 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -179,6 +179,8 @@ const float STAT_VEHICLESTAT_RELOAD2 = 66; const float STAT_SECRETS_TOTAL = 70; const float STAT_SECRETS_FOUND = 71; +const float STAT_RESPAWN_SCHEDULE = 72; + // mod stats (1xx) const float STAT_REDALIVE = 100; const float STAT_BLUEALIVE = 101; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 9d6bcf798..3cae45e4f 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -461,6 +461,7 @@ void PutObserverInServer (void) self.damageforcescale = 0; self.death_time = 0; self.respawn_time = 0; + self.respawn_schedule = 0; self.alpha = 0; self.scale = 0; self.fade_time = 0; @@ -779,6 +780,7 @@ void PutClientInServer (void) self.damageforcescale = 2; self.death_time = 0; self.respawn_time = 0; + self.respawn_schedule = 0; self.scale = 0; self.fade_time = 0; self.pain_frame = 0; @@ -2730,6 +2732,12 @@ void PlayerPreThink (void) } ShowRespawnCountdown(); } + + if(self.respawn_schedule != self.respawn_time) + self.respawn_schedule = self.respawn_time; + if(self.deadflag == DEAD_RESPAWNING && self.respawn_schedule > 0) + self.respawn_schedule *= -1; // invert to indicate we're awaiting respawn, the client translates this + return; } // FIXME from now on self.deadflag is always 0 (and self.health is never < 1) diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index 9068fa75b..6203456cb 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -647,6 +647,8 @@ float serverflags; .entity muzzle_flash; .float misc_bulletcounter; // replaces uzi & hlac bullet counter. +.float respawn_schedule; // shows respawn time, and is negative when awaiting respawn + void PlayerUseKey(); typedef vector(entity player, entity spot, vector current) spawn_evalfunc_t; diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 4cd5cc810..798933a30 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -830,6 +830,9 @@ void spawnfunc_worldspawn (void) // secrets addstat(STAT_SECRETS_TOTAL, AS_FLOAT, stat_secrets_total); addstat(STAT_SECRETS_FOUND, AS_FLOAT, stat_secrets_found); + + // misc + addstat(STAT_RESPAWN_SCHEDULE, AS_FLOAT, respawn_schedule); next_pingtime = time + 5; -- 2.39.2