• (C++ HL2 MOD) If the player runs out of sprint energy, it plays an animation and then he dies.
    7 replies, posted
Hi! I am very new to programming, and have basically being looking over the HL2 source code for my mod. A feature of the mod is to have the player play a stereotypical 'heart attack aka clutching chest' animation before dying (just a red screen would be fine rather than a first person ragdoll view) At the moment I have located Sprint and Health functions in hl2_player.cpp, but I have no idea on how to go about adding the animation in and then having a delay before death. I so far have only changed a couple of variables but I have no idea if they will work either. (SetPlayerHealth = 0 and changed m_HL2Local.m_flSuitPower to = 0 rahter than to be <10 Here's the code snippet so far. Will I need to define the variable SetPlayerHealth, because it is featured later in the full hl2_player.cpp? Or will it work fine? I apologise in advance if I ask really basic questions, I've read over the basics in the SDK, but I'm a mapper and modeller, not a programmer. Also, sorry if this is the wrong section. Oh and I doubt this place is a recruitment thread, but if anyone can see how terribly inept I am at coding, and thinks that a mod featuring a heart attack animation would be fun to work on, feel free to PM... [code]void CHL2_Player::StartSprinting( void ) { if( m_HL2Local.m_flSuitPower = 0 ) ( SetPlayerHealth = 0 ) { // Don't sprint unless there's a reasonable // amount of suit power. // debounce the button for sound playing if ( m_afButtonPressed & IN_SPEED ) { CPASAttenuationFilter filter( this ); filter.UsePredictionRules(); EmitSound( filter, entindex(), "HL2Player.SprintNoPower" ); } return; } if( !SuitPower_AddDevice( SuitDeviceSprint ) ) return; CPASAttenuationFilter filter( this ); filter.UsePredictionRules(); EmitSound( filter, entindex(), "HL2Player.SprintStart" ); SetMaxSpeed( HL2_SPRINT_SPEED ); m_fIsSprinting = true; } [/code]
Well, I haven't worked with HL2 mods before, but first of all [code]if( m_HL2Local.m_flSuitPower = 0 )[/code] if you're doing m_HL2Local.m_flSuitPower = 0, you're trying to assign. You should compare by doing [code]if( m_HL2Local.m_flSuitPower == 0 )[/code] I also have no idea what you're trying to do here [code] if( m_HL2Local.m_flSuitPower = 0 ) ( SetPlayerHealth = 0 ) { [/code] If you're trying to set the player health to 0 once the condition is met, it should be [code] if( m_HL2Local.m_flSuitPower == 0 ) { SetPlayerHealth = 0 } [/code] Although 'SetPlayerHealth' sounds more like a function name rather than a variable. In that case it should be [code] SetPlayerHealth(0); [/code]
Thanks! Does anyone know the ccommand/function I can use to play said animation (from a .mdl) and how to implement it? The effect won't be the same if the player just dies before it shows the player physically clutching his heart.
Sorry to go a little off topic, but could you post a video of this once you get it to work? It seems cool.
[QUOTE=buster925;40393657]Sorry to go a little off topic, but could you post a video of this once you get it to work? It seems cool.[/QUOTE] Hehe sure, once we get the basic mechanics done for our mod, we will probably make a thread here. At the moment we only have a few maps and models to show off, and no coder to help us...
[QUOTE=buster925;40393657]Sorry to go a little off topic, but could you post a video of this once you get it to work? It seems cool.[/QUOTE] Yeah, we will probably make a demonstration video which just shows off some of the features that will be in our mod. I'll PM you the link to the video once it's been uploaded.
You might want to get a foundation of the basics in C++ before you attempt this. For example, using '==' to compare things is a really basic part of the syntax that you should know if you're going to have a chance at pulling this off. That said, take a look at the programming section of Valve's developer wiki. [url]https://developer.valvesoftware.com/wiki/Category:Programming[/url]
[QUOTE=Dr. Evilcop;40455756]You might want to get a foundation of the basics in C++ before you attempt this. For example, using '==' to compare things is a really basic part of the syntax that you should know if you're going to have a chance at pulling this off. That said, take a look at the programming section of Valve's developer wiki. [url]https://developer.valvesoftware.com/wiki/Category:Programming[/url][/QUOTE] Thanks for the input, I've looked over a lot of the wiki, but I am having a hard time finding more HL2 specific functions anywhere else, and a lot of the pages on the wiki (e.g. decaltrace; also couldn't see anything on kill player functions) are quite short. I guess I'll either have to stick to copy-pasting weapons and replacing models, learning C++ in general (before learning HL2 specific functions) or find a coder. Hopefully the latter happens when we have some media releases and people (hopefully) become interested.
Sorry, you need to Log In to post a reply to this thread.