Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add member m_iGibDamageThreshold to control GIB damage threshold #904

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions regamedll/dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class CBasePlayer: public CBaseMonster {
edict_t *EntSelectSpawnPoint_OrigFunc();
void PlayerDeathThink_OrigFunc();
void Observer_Think_OrigFunc();

CCSPlayer *CSPlayer() const;
#endif // REGAMEDLL_API

Expand Down Expand Up @@ -641,6 +641,7 @@ class CBasePlayer: public CBaseMonster {
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);
Expand Down Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion regamedll/public/regamedll/API/CSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class CCSPlayer: public CCSMonster {
m_flLongJumpHeight(0),
m_flLongJumpForce(0),
m_flDuckSpeedMultiplier(0),
m_iUserID(-1)
m_iUserID(-1),
m_iGibDamageThreshold(GIB_PLAYER_THRESHOLD)
{
m_szModel[0] = '\0';

Expand Down Expand Up @@ -172,6 +173,8 @@ class CCSPlayer: public CCSMonster {
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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions regamedll/public/regamedll/regamedll_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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