Here, take a look at this
code.
The OnThink function of hud_hull.cpp
Code: Select all
void CHudHull:: OnThink (void)
{
float newHull = 0;
C_BasePlayer * local = C_BasePlayer:: GetLocalPlayer ();
if (!local)
return;
// Never below zero
newHull = max(local->GetHealth(), 0);
// DevMsg("Sheild at is at: %f\n",newShield);
// Only update the fade if we've changed health
if (newHull == m_flHull)
return;
m_flHull = newHull;
}
I am trying to do something similar, but instead of showing the players
health level, it will show the suit battery power.
And I'm almost 100% sure I'm doing it wrong. I mean, all what needs to be edited in hud_hull.cpp is the OnThink function,
Code: Select all
void CHudArmor:: OnThink (void)
{
float newArmor = 0;
C_BasePlayer * local = C_BasePlayer:: GetLocalPlayer ();
CHL2_Player *pHL2Player = dynamic_cast<CHL2_Player *>( pPlayer );
if (!local)
return;
// Never below zero
// newArmor = max(local->GetHealth(), 0);
newArmor = max(pHL2Player->ArmorValue(), 0);
// DevMsg("Sheild at is at: %f\n",newShield);
// Only update the fade if we've changed health
if (newArmor == m_flArmor)
return;
m_flArmor = newArmor;
}
Can you try help me sort it out please?