Wayback Machine
Jul AUG FEB
Previous capture 8 Next capture
2006 2007 2008
3 captures
8 Aug 07 - 15 Sep 08
sparklines
Close Help

VGUI HUD Tutorial

Part IV (Adding an ammo indicator to the HUD)

By: Mazor (mazor@spudgunmod.net)

My code is in RED

Half-Life code is in BLUE

Comments are in GREEN

 

Open the hud.h file, find the CHudAmmo class... add these variables under the PUBLIC defines:

// Mazor

int m_iClip;

int m_iAmmo1;

int m_iAmmo2;

// Mazor

Ok, now, you can close the hud.h file

 

Now open up ammo.cpp

Find the CHudAmmo::Draw(float flTime) function

Right at the end, before the return 1; add this:

// Mazor

m_iClip = pw->iClip;

m_iAmmo1 = gWR.CountAmmo(pw->AmmoType);

m_iAmmo2 = gWR.CountAmmo(pw->Ammo2Type);

// Mazor

 

Now, whenever you need to access the variables from the new HUD, you can use them just like any other variable like I showed before, eg: player health.

Here is how you access your new variables:

// Mazor

gHUD.m_Ammo->m_iClip // that is the player's current clip ammount for the current weapon

gHUD.m_Ammo->m_iAmmo1 // the total ammo count of the primary ammo for the current weapon

gHUD.m_Ammo->m_iAmmo2 // the total ammo count of the secondary ammo for the current weapon

// Mazor

If you don't know how to turn those into a VGUI label, you can do one of two things, you can either look back in the second tutorial in the VGUI HUD series or you can read up on VGUI over at the Half-Life Coding Index under the Client Tutorials section.

Any Q's, e-mail me: mazor@spudgunmod.net