From 26db32e8845647cf024e38f11cb3da3071ac0dd1 Mon Sep 17 00:00:00 2001 From: s1lent Date: Thu, 31 May 2018 14:53:34 +0700 Subject: [PATCH] Enhance mp_respawn_immunitytime Minor refactoring --- regamedll/dlls/player.cpp | 46 ++++++++++++------- .../GameDefinitionFile/regamedll-cs.fgd | 2 +- regamedll/public/regamedll/API/CSPlayer.h | 24 ++++++++++ 3 files changed, 55 insertions(+), 17 deletions(-) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 6d1bff76..d36f4bc5 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -577,9 +577,18 @@ void EXT_FUNC CBasePlayer::__API_HOOK(TraceAttack)(entvars_t *pevAttacker, float bool bHitShield = IsHittingShield(vecDir, ptr); CBasePlayer *pAttacker = CBasePlayer::Instance(pevAttacker); + #ifdef REGAMEDLL_ADD - if (pAttacker && pAttacker->IsPlayer() && !CSGameRules()->FPlayerCanTakeDamage(this, pAttacker)) - bShouldBleed = false; + if (pAttacker && pAttacker->IsPlayer()) + { + // don't take damage if victim has protection + if (CSPlayer()->GetProtectionState() == CCSPlayer::ProtectionSt_Active) + return; + + if (!CSGameRules()->FPlayerCanTakeDamage(this, pAttacker)) + bShouldBleed = false; + } + #else if (pAttacker && pAttacker->IsPlayer() && m_iTeam == pAttacker->m_iTeam && !friendlyfire.value) bShouldBleed = false; @@ -812,6 +821,16 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(TakeDamage)(entvars_t *pevInflictor, entva int armorHit = 0; CBasePlayer *pAttack = nullptr; +#ifdef REGAMEDLL_ADD + { + CBaseEntity *pAttacker = GET_PRIVATE(ENT(pevAttacker)); + + // don't take damage if victim has protection + if (((pAttacker && pAttacker->IsPlayer()) || (bitsDamageType & DMG_FALL)) && CSPlayer()->GetProtectionState() == CCSPlayer::ProtectionSt_Active) + return FALSE; + } +#endif + if (bitsDamageType & (DMG_EXPLOSION | DMG_BLAST | DMG_FALL)) m_LastHitGroup = HITGROUP_GENERIC; @@ -4378,7 +4397,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() UpdateLocation(); #ifdef REGAMEDLL_ADD - if (CSPlayer()->m_flSpawnProtectionEndTime > 0 && gpGlobals->time > CSPlayer()->m_flSpawnProtectionEndTime) + if (CSPlayer()->GetProtectionState() == CCSPlayer::ProtectionSt_Expired) { RemoveSpawnProtection(); } @@ -5719,19 +5738,16 @@ void CSprayCan::Spawn(entvars_t *pevOwner) void CSprayCan::Think() { - TraceResult tr; - int playernum; - int nFrames; - CBasePlayer *pPlayer; - - pPlayer = (CBasePlayer *)GET_PRIVATE(pev->owner); + CBasePlayer *pPlayer = GET_PRIVATE(pev->owner); + int nFrames = -1; if (pPlayer) + { nFrames = pPlayer->GetCustomDecalFrames(); - else - nFrames = -1; + } - playernum = ENTINDEX(pev->owner); + TraceResult tr; + int playernum = ENTINDEX(pev->owner); UTIL_MakeVectors(pev->angles); UTIL_TraceLine(pev->origin, pev->origin + gpGlobals->v_forward * 128, ignore_monsters, pev->owner, &tr); @@ -5797,7 +5813,7 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(GiveNamedItem)(const char *pszName DispatchSpawn(pent); DispatchTouch(pent, ENT(pev)); - return (CBaseEntity *)GET_PRIVATE(pent); + return GET_PRIVATE(pent); } // external function for 3rd-party @@ -5818,7 +5834,7 @@ CBaseEntity *CBasePlayer::GiveNamedItemEx(const char *pszName) DispatchSpawn(pent); DispatchTouch(pent, ENT(pev)); - CBaseEntity *pEntity = (CBaseEntity *)GET_PRIVATE(pent); + CBaseEntity *pEntity = GET_PRIVATE(pent); #ifdef REGAMEDLL_FIXES // not allow the item to fall to the ground. @@ -9507,7 +9523,6 @@ LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayer, SetSpawnProtection, (float flProtectionT void EXT_FUNC CBasePlayer::__API_HOOK(SetSpawnProtection)(float flProtectionTime) { - pev->takedamage = DAMAGE_NO; pev->rendermode = kRenderTransAdd; pev->renderamt = 100.0; @@ -9518,7 +9533,6 @@ LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayer, RemoveSpawnProtection) void CBasePlayer::__API_HOOK(RemoveSpawnProtection)() { - pev->takedamage = DAMAGE_AIM; pev->rendermode = kRenderNormal; CSPlayer()->m_flSpawnProtectionEndTime = 0.0f; diff --git a/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd b/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd index 42b6a181..1a2f80a0 100644 --- a/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd +++ b/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd @@ -2534,7 +2534,7 @@ 1 : "Only Trigger" : 0 2 : "Broken on touch is buggy" : 0 4 : "Pressure is buggy" : 0 - 128: "Breakable" : 1 + 128: "Breakable" : 1 256: "Instant Crowbar" : 1 ] friction(integer) : "Friction (0-400)" : 50 diff --git a/regamedll/public/regamedll/API/CSPlayer.h b/regamedll/public/regamedll/API/CSPlayer.h index fc31c512..96d425e3 100644 --- a/regamedll/public/regamedll/API/CSPlayer.h +++ b/regamedll/public/regamedll/API/CSPlayer.h @@ -85,6 +85,16 @@ public: CBasePlayer *BasePlayer() const; +public: + enum EProtectionState + { + ProtectionSt_NoSet, + ProtectionSt_Active, + ProtectionSt_Expired, + }; + + EProtectionState GetProtectionState() const; + public: char m_szModel[32]; bool m_bForceShowMenu; @@ -97,3 +107,17 @@ inline CBasePlayer *CCSPlayer::BasePlayer() const { return reinterpret_cast(this->m_pContainingEntity); } + +inline CCSPlayer::EProtectionState CCSPlayer::GetProtectionState() const +{ + // no protection set + if (m_flSpawnProtectionEndTime <= 0.0f) + return ProtectionSt_NoSet; + + // check if end time of protection isn't expired yet + if (m_flSpawnProtectionEndTime >= gpGlobals->time) + return ProtectionSt_Active; + + // has expired + return ProtectionSt_Expired; +}