Skip to content

Commit

Permalink
Don't respawn if m_flRespawnPending isn't set
Browse files Browse the repository at this point in the history
Minor refactoring
  • Loading branch information
s1lentq committed Sep 22, 2019
1 parent e199b16 commit 0b517e0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
20 changes: 20 additions & 0 deletions regamedll/dlls/API/CSPlayer.cpp
Expand Up @@ -533,3 +533,23 @@ void CCSPlayer::Reset()
m_iWeaponInfiniteAmmo = 0;
m_iWeaponInfiniteIds = 0;
}

void CCSPlayer::OnSpawn()
{
m_flRespawnPending = 0.0f;
}

void CCSPlayer::OnKilled()
{
#ifdef REGAMEDLL_ADD
if (forcerespawn.value > 0)
{
m_flRespawnPending = gpGlobals->time + forcerespawn.value;
}

if (GetProtectionState() == ProtectionSt_Active)
{
BasePlayer()->RemoveSpawnProtection();
}
#endif
}
16 changes: 8 additions & 8 deletions regamedll/dlls/player.cpp
Expand Up @@ -2168,13 +2168,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
BuyZoneIcon_Clear(this);

#ifdef REGAMEDLL_ADD
if (forcerespawn.value > 0) {
CSPlayer()->m_flRespawnPending = gpGlobals->time + forcerespawn.value;
}

if (CSPlayer()->GetProtectionState() == CCSPlayer::ProtectionSt_Active) {
RemoveSpawnProtection();
}
CSPlayer()->OnKilled();
#endif

SetThink(&CBasePlayer::PlayerDeathThink);
Expand Down Expand Up @@ -5294,6 +5288,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Spawn)()
m_idrowndmg = 0;
m_idrownrestored = 0;

#ifdef REGAMEDLL_ADD
CSPlayer()->OnSpawn();
#endif

if (m_iObserverC4State)
{
m_iObserverC4State = 0;
Expand Down Expand Up @@ -9800,7 +9798,9 @@ void CBasePlayer::PlayerRespawnThink()
if (pev->deadflag < DEAD_DYING)
return;

if (forcerespawn.value > 0 && gpGlobals->time > CSPlayer()->m_flRespawnPending)
if (forcerespawn.value > 0 &&
CSPlayer()->m_flRespawnPending > 0 &&
CSPlayer()->m_flRespawnPending <= gpGlobals->time)
{
Spawn();
pev->button = 0;
Expand Down
4 changes: 4 additions & 0 deletions regamedll/public/regamedll/API/CSPlayer.h
Expand Up @@ -96,6 +96,10 @@ class CCSPlayer: public CCSMonster {
virtual bool HintMessageEx(const char *pMessage, float duration = 6.0f, bool bDisplayIfPlayerDead = false, bool bOverride = false);

void Reset();

void OnSpawn();
void OnKilled();

CBasePlayer *BasePlayer() const;

public:
Expand Down

0 comments on commit 0b517e0

Please sign in to comment.