Skip to content

Commit 8a18969

Browse files
wopox1337dystopm
andauthored
New CVar: mp_dying_time (#483)
* Add new CVar: mp_dying_time < 0 .. 999> * Add description * magic numbers to named const * magic numbers to named const (№2) * cvar value handling * update description * a better description * resolve conflicts * lil order fixes & indent * remove death animation skip * DYING_TIME -> DEATH_ANIMATION_TIME * Fix death animation when mp_dying_time < 3.0 depending on animation * change desc * change cvar desc --------- Co-authored-by: dystopm <[email protected]>
1 parent e1d1c11 commit 8a18969

File tree

6 files changed

+68
-7
lines changed

6 files changed

+68
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
109109
| mp_give_c4_frags | 3 | - | - | How many bonuses (frags) will get the player who defused or exploded the bomb. |
110110
| mp_hostages_rescued_ratio | 1.0 | 0.0 | 1.0 | Ratio of hostages rescued to win the round. |
111111
| mp_legacy_vehicle_block | 1 | 0 | 1 | Legacy func_vehicle behavior when blocked by another entity.<br/>`0` New behavior <br/>`1` Legacy behavior |
112+
| mp_dying_time | 3.0 | 0.0 | - | Time for switch to free observing after death.<br/>`0` - disable spectating around death.<br/>`>0.00001` - time delay to start spectate.<br/>`NOTE`: The countdown starts when the player’s death animation is finished.|
112113
</details>
113114

114115
## How to install zBot for CS 1.6?

dist/game.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,11 @@ mp_hostages_rescued_ratio "1.0"
521521
//
522522
// Default value: "1"
523523
mp_legacy_vehicle_block "1"
524+
525+
// Time for switch to free observing after death.
526+
// NOTE: The countdown starts when the player’s death animation is finished.
527+
// 0 - disable spectating around death
528+
// >0.00001 - time delay to start spectate
529+
//
530+
// Default value: "3.0"
531+
mp_dying_time "3.0"

regamedll/dlls/game.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ cvar_t hostages_rescued_ratio = { "mp_hostages_rescued_ratio", "1.0", 0, 1.0f, n
170170

171171
cvar_t legacy_vehicle_block = { "mp_legacy_vehicle_block", "1", 0, 0.0f, nullptr };
172172

173+
cvar_t dying_time = { "mp_dying_time", "3.0", 0, 3.0f, nullptr };
174+
173175
void GameDLL_Version_f()
174176
{
175177
if (Q_stricmp(CMD_ARGV(1), "version") != 0)
@@ -418,6 +420,8 @@ void EXT_FUNC GameDLLInit()
418420

419421
CVAR_REGISTER(&legacy_vehicle_block);
420422

423+
CVAR_REGISTER(&dying_time);
424+
421425
// print version
422426
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");
423427

regamedll/dlls/game.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ extern cvar_t sv_enablebunnyhopping;
192192
extern cvar_t plant_c4_anywhere;
193193
extern cvar_t give_c4_frags;
194194
extern cvar_t hostages_rescued_ratio;
195-
196195
extern cvar_t legacy_vehicle_block;
196+
extern cvar_t dying_time;
197+
197198
#endif
198199

199200
extern cvar_t scoreboard_showmoney;

regamedll/dlls/gamerules.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const float ROUND_RESPAWN_TIME = 20.0f;
4646
const float ROUND_BEGIN_DELAY = 5.0f; // delay before beginning new round
4747
const float ITEM_KILL_DELAY = 300.0f;
4848
const float RADIO_TIMEOUT = 1.5f;
49+
const float DEATH_ANIMATION_TIME = 3.0f;
4950

5051
const int MAX_INTERMISSION_TIME = 120; // longest the intermission can last, in seconds
5152

@@ -206,7 +207,7 @@ enum
206207
SCENARIO_BLOCK_PRISON_ESCAPE_TIME = BIT(8), // flag "i"
207208
SCENARIO_BLOCK_BOMB_TIME = BIT(9), // flag "j"
208209
SCENARIO_BLOCK_HOSTAGE_RESCUE_TIME = BIT(10), // flag "k"
209-
210+
210211
};
211212

212213
// Player relationship return codes
@@ -336,6 +337,7 @@ class CGameRules
336337
inline void SetGameOver() { m_bGameOver = true; }
337338
static float GetItemKillDelay();
338339
static float GetRadioTimeout();
340+
static float GetDyingTime();
339341

340342
public:
341343
BOOL m_bFreezePeriod; // TRUE at beginning of round, set to FALSE when the period expires
@@ -921,6 +923,15 @@ inline float CGameRules::GetRadioTimeout()
921923
#endif
922924
}
923925

926+
inline float CGameRules::GetDyingTime()
927+
{
928+
#ifdef REGAMEDLL_ADD
929+
return dying_time.value;
930+
#else
931+
return DEATH_ANIMATION_TIME;
932+
#endif
933+
}
934+
924935
bool IsBotSpeaking();
925936
void SV_Continue_f();
926937
void SV_Tutor_Toggle_f();

regamedll/dlls/player.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3857,7 +3857,7 @@ void CBasePlayer::PlayerDeathThink()
38573857
{
38583858
// if the player has been dead for one second longer than allowed by forcerespawn,
38593859
// forcerespawn isn't on. Send the player off to an intermission camera until they choose to respawn.
3860-
if (g_pGameRules->IsMultiplayer() && HasTimePassedSinceDeath(3.0f) && !(m_afPhysicsFlags & PFLAG_OBSERVER))
3860+
if (g_pGameRules->IsMultiplayer() && HasTimePassedSinceDeath(CGameRules::GetDyingTime()) && !(m_afPhysicsFlags & PFLAG_OBSERVER))
38613861
{
38623862
// Send message to everybody to spawn a corpse.
38633863
SpawnClientSideCorpse();
@@ -8818,9 +8818,7 @@ void CBasePlayer::SpawnClientSideCorpse()
88188818
if (pev->effects & EF_NODRAW)
88198819
return;
88208820

8821-
// do not make a corpse if the player goes to respawn.
8822-
if (pev->deadflag == DEAD_RESPAWNABLE)
8823-
return;
8821+
// deadflag == DEAD_RESPAWNABLE already checked before
88248822
#endif
88258823

88268824
#ifdef REGAMEDLL_ADD
@@ -8830,6 +8828,41 @@ void CBasePlayer::SpawnClientSideCorpse()
88308828

88318829
char *infobuffer = GET_INFO_BUFFER(edict());
88328830
char *pModel = GET_KEY_VALUE(infobuffer, "model");
8831+
float timeDiff = pev->animtime - gpGlobals->time;
8832+
8833+
#ifdef REGAMEDLL_ADD
8834+
if (CGameRules::GetDyingTime() < DEATH_ANIMATION_TIME) // a short time, timeDiff estimates to be small
8835+
{
8836+
float animDuration = -1.0;
8837+
8838+
studiohdr_t *pstudiohdr = (studiohdr_t *)GET_MODEL_PTR(ENT(pev));
8839+
if (pstudiohdr && pev->sequence < pstudiohdr->numseq) // model ptr and sequence validation
8840+
{
8841+
// get current sequence time
8842+
mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + int(pev->sequence);
8843+
animDuration = pseqdesc->numframes / pseqdesc->fps;
8844+
}
8845+
8846+
if (animDuration <= 0.0)
8847+
{
8848+
// in case of failure
8849+
animDuration = DEATH_ANIMATION_TIME;
8850+
}
8851+
8852+
// client receives a negative value
8853+
animDuration *= -1.0;
8854+
8855+
if (animDuration < timeDiff) // reasonable way to fix client side unfinished sequence bug
8856+
{
8857+
// by some reason, if client receives a value less
8858+
// than "(negative current sequence time) * 100"
8859+
// animation will play visually awkward
8860+
// at this function call time, player death animation
8861+
// has already finished so we can safely fake it
8862+
timeDiff = animDuration;
8863+
}
8864+
}
8865+
#endif
88338866

88348867
MESSAGE_BEGIN(MSG_ALL, gmsgSendCorpse);
88358868
WRITE_STRING(pModel);
@@ -8839,14 +8872,17 @@ void CBasePlayer::SpawnClientSideCorpse()
88398872
WRITE_COORD(pev->angles.x);
88408873
WRITE_COORD(pev->angles.y);
88418874
WRITE_COORD(pev->angles.z);
8842-
WRITE_LONG((pev->animtime - gpGlobals->time) * 100);
8875+
WRITE_LONG(timeDiff * 100);
88438876
WRITE_BYTE(pev->sequence);
88448877
WRITE_BYTE(pev->body);
88458878
WRITE_BYTE(m_iTeam);
88468879
WRITE_BYTE(entindex());
88478880
MESSAGE_END();
88488881

8882+
#ifndef REGAMEDLL_FIXES
8883+
// already defined in StartDeathCam
88498884
m_canSwitchObserverModes = true;
8885+
#endif
88508886

88518887
if (TheTutor)
88528888
{

0 commit comments

Comments
 (0)