C++ Suit power bar

C++ Got ya down? Half-Life 2 Coding Related.
Post Reply
User avatar
Xoom3r
prop_static
prop_static
Posts: 61
Joined: Fri Jun 26, 2009 7:40 pm
Location: Russian Israel
Contact:

C++ Suit power bar

Post by Xoom3r »

Hey.. I want to show the Battery level on a bar..

hud_armor.cpp (OnThink)

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(pHL2Player->ArmorValue(), 0);


	if (newArmor == m_flArmor)
		return;

	m_flArmor = newArmor;
}
That does not seems to work.. Can you help me sort it out?
Image
Image
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Post by Neico »

this code is a bit messy, also i don't understand in how would it help you displaying something on an bar, more infos and / or more code needed...
Image
User avatar
Xoom3r
prop_static
prop_static
Posts: 61
Joined: Fri Jun 26, 2009 7:40 pm
Location: Russian Israel
Contact:

Post by Xoom3r »

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?
Image
Image
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Post by Neico »

CHL2_Player is an Server Class, you can't access it from the client...

i'll make you a fixed file, i'll edit this post as soon as i'm done

Edit: http://neic0.de/codepaste/
Image
Post Reply