Add member m_iGibDamageThreshold to control GIB damage threshold (#904)

* Add member m_iGibDamageThreshold to control GIB damage threshold
This commit is contained in:
Francisco Muñoz 2023-12-13 20:01:34 -03:00 committed by GitHub
parent 8c0b684046
commit f63b154637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 4 deletions

View File

@ -2451,7 +2451,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
HintMessage("#Hint_cannot_play_because_tk", TRUE, TRUE);
}
if ((pev->health < -9000 && iGib != GIB_NEVER) || iGib == GIB_ALWAYS)
if (ShouldGibPlayer(iGib))
{
#ifndef REGAMEDLL_FIXES

View File

@ -448,7 +448,7 @@ public:
edict_t *EntSelectSpawnPoint_OrigFunc();
void PlayerDeathThink_OrigFunc();
void Observer_Think_OrigFunc();
CCSPlayer *CSPlayer() const;
#endif // REGAMEDLL_API
@ -641,6 +641,7 @@ public:
bool ShouldToShowAccount(CBasePlayer *pReceiver) const;
bool ShouldToShowHealthInfo(CBasePlayer *pReceiver) const;
const char *GetKillerWeaponName(entvars_t *pevInflictor, entvars_t *pevKiller) const;
bool ShouldGibPlayer(int iGib);
CBasePlayerItem *GetItemByName(const char *itemName);
CBasePlayerItem *GetItemById(WeaponIdType weaponID);
@ -954,7 +955,24 @@ inline bool CBasePlayer::HasTimePassedSinceDeath(float duration) const
inline CCSPlayer *CBasePlayer::CSPlayer() const {
return reinterpret_cast<CCSPlayer *>(this->m_pEntity);
}
#endif
#else // !REGAMEDLL_API
// Determine whether player can be gibbed or not
inline bool CBasePlayer::ShouldGibPlayer(int iGib)
{
// Always gib the player regardless of incoming damage
if (iGib == GIB_ALWAYS)
return true;
// Gib the player if health is below the gib damage threshold
if (pev->health < GIB_PLAYER_THRESHOLD && iGib != GIB_NEVER)
return true;
// do not gib the player
return false;
}
#endif // !REGAMEDLL_API
#ifdef REGAMEDLL_FIXES

View File

@ -56,7 +56,8 @@ public:
m_flLongJumpHeight(0),
m_flLongJumpForce(0),
m_flDuckSpeedMultiplier(0),
m_iUserID(-1)
m_iUserID(-1),
m_iGibDamageThreshold(GIB_PLAYER_THRESHOLD)
{
m_szModel[0] = '\0';
@ -172,6 +173,8 @@ public:
void RecordDamage(CBasePlayer *pAttacker, float flDamage, float flFlashDurationTime = -1);
int m_iNumKilledByUnanswered[MAX_CLIENTS]; // [0-31] how many unanswered kills this player has been dealt by each other player
bool m_bPlayerDominated[MAX_CLIENTS]; // [0-31] array of state per other player whether player is dominating other players
int m_iGibDamageThreshold; // negative health to reach to gib player
};
// Inlines
@ -210,3 +213,20 @@ inline void CCSPlayer::SetPlayerDominated(CBasePlayer *pPlayer, bool bDominated)
Assert(iPlayerIndex > 0 && iPlayerIndex <= MAX_CLIENTS);
m_bPlayerDominated[iPlayerIndex - 1] = bDominated;
}
#ifdef REGAMEDLL_API
// Determine whether player can be gibbed or not
inline bool CBasePlayer::ShouldGibPlayer(int iGib)
{
// Always gib the player regardless of incoming damage
if (iGib == GIB_ALWAYS)
return true;
// Gib the player if health is below the gib damage threshold
if (pev->health < CSPlayer()->m_iGibDamageThreshold && iGib != GIB_NEVER)
return true;
// do not gib the player
return false;
}
#endif

View File

@ -106,3 +106,4 @@
#define GIB_NEVER 1 // Never gib, no matter how much death damage is done ( freezing, etc )
#define GIB_ALWAYS 2 // Always gib ( Houndeye Shock, Barnacle Bite )
#define GIB_HEALTH_VALUE -30
#define GIB_PLAYER_THRESHOLD -9000