PDA

View Full Version : Issue trying to display a hud element on hit


foomanchurocks
05-20-2007, 03:06 PM
Alright so let me start off by saying that I'm neither a child :P nor a noob to programming, but I am new to coding for the source engine. I thought it would be a fun project to work on in my spare time.

I have made a new class that properly displays an overlay on the HUD, and I have tested it, so I know it works. The problem is I want to display the HUD element when the player is damaged by either bullets, melee, fall dmg etc etc.

I tried to activate the HUD element in both CBasePlayer::OnTakeDamage_Alive (player.cpp) and CHL2_Player::OnTakeDamage_Alive (HL2_Player.cpp) but neither seem to work. I tried to use a UTIL_ function to get the local player but when I try to access the local players functions the game crashes (NULL pointer exception I believe). I then tried to check if(pPlayer) and #ifndef CLIENT_DLL so that the lines would run only for a client but to no avail. For some reason I can't get the local player. Any help would be greatly appreciated and if you need the code I'm using to activate the HUD element I can supply it. Thanks in advance.

Jordan

NokiaTokia
05-20-2007, 03:29 PM
One problem is that you cant rely on the client in player.cpp as its a server only file. So, even if you put "#ifdef CLIENT_DLL" the client will never EVER see what gets called in between the ifdef and endif blocks.

( Also, "#ifndef CLIENT_DLL" will only run on the server, hence "if not def". You would want to use "#ifdef CLIENT_DLL" to run only client code. )

Instead, you should use a HUD Messages that will relay server information to the client. A good example of this is the CHudDamageIndicator class.
More information here, http://developer.valvesoftware.com/wiki/Special:Search?search=HOOK_HUD_MESSAGE&fulltext=Search

foomanchurocks
05-20-2007, 03:37 PM
Thanks NokiaTokia

I didn't take the time to notice that player.cpp was server side :P. Also, thanks for pointing me to the CHudDamageIndicator class because that is the sort of thing I was looking for. I'm trying to get a blood splatter effect instead of the damage indicators.

Jordan

NokiaTokia
05-20-2007, 03:48 PM
N/p

If you get stuck with the messaging or anything else, ill be happy to post an example..

foomanchurocks
05-20-2007, 04:46 PM
Brilliant! Thanks NokiaTokia.

Apparently I was using HUD Messages all along. They are the 'messages' set in hl2_usermessages :P I just wasn't using them the correct way when writing to them. When using a Message in player.cpp (havn't tried hl2_Player.cpp because server side works great) you apparently have to use 'this' as your filter argument instead of grabbing the player with UTIL_'s.

I may try to use it in hl2_Player.cpp later though because I believe that would probably be more efficient in the end. 1 less byte needing to be sent across to clients :P.

Jordan

foomanchurocks
05-23-2007, 06:03 PM
Hello again,

I moved the HUD message code into the HL2_Player.cpp to keep it client side, and imagine that, the player is grabbed using 'this' in that file also. I feel dumb.

So anyways, I have a new issue. I have the HUD element disappearing after 2 seconds, but making it fade away instead of simply disappearing is causing some troubles. I thought I might try setting the HUD message byte to a numerical value (being a byte it's between 0-255) and using that to set the Alpha of the HUD element while using it for IF's. Apparently this line of code that draws the HUD element doesn't actually set the alpha though...

m_pBlood->DrawSelf(0, 0, GetWide(), GetTall(), Color(255,255,255,m_bShow));

I tried manually setting the byte to a value like 50 but there were no changes to the transparency of my texture. Any help or tips would be greatly appreciated. Thanks.

Jordan

lodle
05-23-2007, 07:32 PM
Have a look at hud_health because it uses animations to do just that. (i think they are defined in hud_animations.txt in scripts folder)

foomanchurocks
05-23-2007, 07:38 PM
Thanks Lodle!

I was just looking at the hud_suitpower.cpp and noticed that it
had some animations that I was unable to locate. Now I think I can figure out the rest from there!

Jordan