Closed OciXCrom closed 5 years ago
Because player dies in takedamage
@fl0werD that doesn't explain why death is called before damage.
pre takedamage pre killed post killed post takedamage
First thing to notice, you are hooking Ham_TakeDamage as Post Your callback function will be called after TakeDamage is executed
If there is another function getting called is because it was called inside TakeDamage, so let's follow the function from the SDK:
It's TakeDamage from player, so let's find CBasePlayer::TakeDamage: https://github.com/ValveSoftware/halflife/blob/master/dlls/player.cpp#L443 Lines 443-673
There is a call in line 507 to CBaseMonster::TakeDamage, so let's go there and check: https://github.com/ValveSoftware/halflife/blob/master/dlls/combat.cpp#L838 Lines 838-968
Oh, what is in line 909? https://github.com/ValveSoftware/halflife/blob/master/dlls/combat.cpp#L909
if ( pev->health <= 0 )
{
g_pevLastInflictor = pevInflictor;
if ( bitsDamageType & DMG_ALWAYSGIB )
{
Killed( pevAttacker, GIB_ALWAYS );
}
else if ( bitsDamageType & DMG_NEVERGIB )
{
Killed( pevAttacker, GIB_NEVER );
}
else
{
Killed( pevAttacker, GIB_NORMAL );
}
g_pevLastInflictor = NULL;
return 0;
}
So CBasePlayer::Killed is called on TakeDamage...
So functions are called like this
CBasePlayer::TakeDamage() - Start || Pre hook gets called before running this
CBaseMonster::TakeDamage()
CBasePlayer::Killed() - Start || Pre hook of Ham_Killed on player before running this
CHalfLifeMultiplay::PlayerKilled()
CHalfLifeMultiplay::DeathNotice() || At here DeathMsg is sent, and your OnPlayerKilled() its called
CBasePlayer::Killed() - End || Post hook gets called here, so your OnPlayerKilledHam() gets called at here
CBasePlayer::TakeDamage() - End || Post hook gets called here, OnTakeDamage() gets called
Thats why are you getting that result
Thanks for the detailed explanation. If that's how the game works, I'm not going to judge it.
I don't think this is how it should work. Why is the damage dealt after the player has died?
Result: