Draw numbers in HUD Created 7 months ago2023-09-08 23:37:07 UTC by RoJAn RoJAn

Created 7 months ago2023-09-08 23:37:07 UTC by RoJAn RoJAn

Posted 7 months ago2023-09-08 23:37:07 UTC Post #347847
Hey, i was really interested in adding things to the HUD, and tried to create a new ammo counter for a specific weapon.
I take a look at the code and see the DrawHudNumber that some parts of the HUD like the ammo, health and battery have, so i was triyng to get this thing to work but it doesnt seems to have a result.

I tried to take a look at the Internet to see a way on getting my HUD to work, but surprisingly, i didn't find any, and the ones on this site seems to just show things like adding sprites similar to the flash light or the CS radar.

So i wanted to ask if someone haves a better idea on how these things work or if someone has a guide that can help me.
Posted 5 months ago2023-11-09 00:09:13 UTC Post #348004
Where exactly are you using DrawHudNumber()? Try running HL in Software renderer and see if the numbers are drawn, if so, than your using it the wrong way. If you want to do it fast just add this code into any registered hud element and draw inside the draw() function. However Best course of action would be to create your own hud class and register the hud element: gHud.AddHudElement() + set HUD_ACTIVE flag + add it into the .Init() & VidInit() lists.Base your class off of some stabndard hud elem class then you'll get a pretty good idea of what it's supposed to look like
Posted 5 months ago2023-11-09 22:00:10 UTC Post #348009
You mention a new ammo counter for a specific weapon. That'd require keeping track of a tertiary ammo source, which would require changes to some of the prediction code too.

Can you show your code? I just realised this thread is 2 months old, I've no idea how I managed to miss it...
Admer456 Admer456If it ain't broken, don't fox it!
Posted 2 months ago2024-02-10 01:38:04 UTC Post #348568
Hey, just wanted to say that i find my solution months ago.
What i wanted is to show the amount of grenades without select them, so here's my code writed in SendAmmoUpdate in player.cpp :
void CBasePlayer::SendAmmoUpdate(void)
{
for (int i=0; i < MAX_AMMO_SLOTS;i++)
{
if (m_rgAmmo[i] != m_rgAmmoLast[i])
{
m_rgAmmoLast[i] = m_rgAmmo[i];

ASSERT( m_rgAmmo[i] >= 0 );
ASSERT( m_rgAmmo[i] < 255 );

MESSAGE_BEGIN(MSG_ONE, gmsgGrenades, NULL, pev);//send message with the hitgroup they were just hit
WRITE_BYTE(0); //For some reason, there is some weapon ammo that is impossible to get his index, so instead of writing the grenade index, we just put a 0
`WRITE_BYTE(V_max(V_min(m_rgAmmo[GetAmmoIndex("Hand Grenade)"], 254), 0));`
MESSAGE_END();

// send "Ammo" update message
MESSAGE_BEGIN( MSG_ONE, gmsgAmmoX, NULL, pev );
WRITE_BYTE( i );
WRITE_BYTE( V_max( V_min( m_rgAmmo[i], 254 ), 0 ) ); // clamp the value to one byte
MESSAGE_END();
}
}
}
The gmsgGrenades can be replaced whit gmsgAmmoX , but i created a separated code just in case.
You must be logged in to post a response.