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

Conversation

dystopm
Copy link
Contributor

@dystopm dystopm commented Dec 4, 2023

The only way to "naturally" GIB on death for players is reaching -9000 health points. This PR adds a CCSPlayer member that controls that value individually per player. It defaults to -9000.

@justgo97
Copy link

justgo97 commented Dec 4, 2023

the flag GIB_ALWAYS is enough to make the player GIB on death. ( You can always check player health on PlayerKilled and decide if the player should GIB on death or not, so this member doesn't introduce anything new )

@StevenKal
Copy link
Contributor

The function "CBasePlayer::ShouldGibPlayer" should probably not be in "CSPlayer.h" (more on "player.h"), more due to the fact it is not only "API only feature", due to internal "REGAMEDLL_API" define.

@dystopm
Copy link
Contributor Author

dystopm commented Dec 4, 2023

The function "CBasePlayer::ShouldGibPlayer" should probably not be in "CSPlayer.h" (more on "player.h"), more due to the fact it is not only "API only feature", due to internal "REGAMEDLL_API" define.

Thing is, I don't know why it doesn't compile when I put this inline function after the CSPlayer method declaration inside player.h - by the way, @s1lentq implemented the DmgPenetrationLevel methods in CSEntity.h (#858) when their declarations are on cbase.h and I guess it's because the same compilation error (also did the same in (#896).

@StevenKal
Copy link
Contributor

StevenKal commented Dec 4, 2023

Maybe putting it inside the "#ifdef REGAMEDLL_API" on "player.h" line 953 could skip the compiler error, then a #else with duplicated function without the member.
However, a non-inline function, but does not worth to expose such tiny check function.

@dystopm
Copy link
Contributor Author

dystopm commented Dec 4, 2023

Maybe putting it inside the "#ifdef REGAMEDLL_API" on "player.h" line 953 could skip the compiler error, then a #else with duplicated function without the member. However, a non-inline function, but does not worth to expose such tiny check function.

#ifdef REGAMEDLL_API
inline CCSPlayer *CBasePlayer::CSPlayer() const {
	return reinterpret_cast<CCSPlayer *>(this->m_pEntity);
}
#endif
inline bool CBasePlayer::ShouldGibPlayer(int iGib)
{
#ifdef REGAMEDLL_API
	int threshold = CSPlayer()->m_iGibDamageThreshold;
#else 
	int threshold = GIB_PLAYER_THRESHOLD;
#endif
	return ((pev->health < threshold && iGib != GIB_NEVER) || iGib == GIB_ALWAYS);
}

It wont compile 💀 am I forgetting something?

@StevenKal
Copy link
Contributor

StevenKal commented Dec 4, 2023

I was thinking to something more like:

#ifdef REGAMEDLL_API
inline CCSPlayer *CBasePlayer::CSPlayer() const {
	return reinterpret_cast<CCSPlayer *>(this->m_pEntity);
}

inline bool CBasePlayer::ShouldGibPlayer(int iGib)
{
	return ((pev->health < CSPlayer()->m_iGibDamageThreshold && iGib != GIB_NEVER) || iGib == GIB_ALWAYS);
}
#else
inline bool CBasePlayer::ShouldGibPlayer(int iGib)
{
	return ((pev->health < GIB_PLAYER_THRESHOLD&& iGib != GIB_NEVER) || iGib == GIB_ALWAYS);
}
#endif

But might not compile too!
Sometimes compilers sucks & give us shitty errors or headhache! Just like when the test demos fails with this project!

@dystopm
Copy link
Contributor Author

dystopm commented Dec 4, 2023

I was thinking to more something like:

#ifdef REGAMEDLL_API
inline CCSPlayer *CBasePlayer::CSPlayer() const {
	return reinterpret_cast<CCSPlayer *>(this->m_pEntity);
}

inline bool CBasePlayer::ShouldGibPlayer(int iGib)
{
	return ((pev->health < CSPlayer()->m_iGibDamageThreshold && iGib != GIB_NEVER) || iGib == GIB_ALWAYS);
}
#else
inline bool CBasePlayer::ShouldGibPlayer(int iGib)
{
	return ((pev->health < GIB_PLAYER_THRESHOLD&& iGib != GIB_NEVER) || iGib == GIB_ALWAYS);
}
#endif

But might not compile too!

It wont recognize CSPlayer method, and I don't know why, it's getting defined above (lol). Some cpp coder may elaborate on this, I'm still a rookie :)

@s1lentq s1lentq merged commit f63b154 into s1lentq:master Dec 13, 2023
4 checks passed
@dystopm dystopm deleted the gibthreshold_member branch August 13, 2024 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants