C++ Suit power bar

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

C++ Suit power bar

Postby Xoom3r » Sat Jul 04, 2009 4:40 pm

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: 1812
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Postby Neico » Sat Jul 04, 2009 5:22 pm

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...

User avatar
Xoom3r
prop_static
prop_static
Posts: 65
Joined: Fri Jun 26, 2009 7:40 pm
Location: Russian Israel
Contact:

Postby Xoom3r » Sat Jul 04, 2009 8:08 pm

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: 1812
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Postby Neico » Sun Jul 05, 2009 2:35 pm

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/