Posted by: Mercalli
Date posted: Aug 08 2005 User Rating: 4.3 out of 5.0 | Number of views: 9663 Number of comments: 4 | Description: Change the frag grenade in MP HL to a smoke grenade |
This is a fairly simple snippet as the main chunk of code we use to make a smoke grenade is already avaible in the SDK. (Look for "test_smokeGrenade")
First thing we need to do is add a variable so that only the frag grenade releases smoke when it explodes. It will also help us tell the engine to not do damage to the player when it explodes.
open up basegrenade_shared.h and after the line
and add a bool variable
Next thing we need to do is go into the file grenade_frag.cpp and scroll down to the ::Spawn function and find the line:
We need to say that we want this grenade to be a smoke grenade so we set our bool to true. So after the CreateEffects(); line add this:
| | m_bIsSmokeGrenade = true;
|
Open up basegrenade_shared.cpp and find the line void CBaseGrenade::Explode( trace_t *pTrace, int bitsDamageType ) This is the function where we will put our code to actually create the smoke cloud. It should look like this:
| | void CBaseGrenade::Explode( trace_t *pTrace, int bitsDamageType ) { #if !defined( CLIENT_DLL ) SetModelName( NULL_STRING ); AddSolidFlags( FSOLID_NOT_SOLID );
m_takedamage = DAMAGE_NO;
if ( pTrace->fraction != 1.0 ) { SetLocalOrigin( pTrace->endpos + (pTrace->plane.normal * 0.6) ); } Vector vecAbsOrigin = GetAbsOrigin(); int contents = UTIL_PointContents ( vecAbsOrigin );
if ( pTrace->fraction != 1.0 ) { Vector vecNormal = pTrace->plane.normal; surfacedata_t *pdata = physprops->GetSurfaceData( pTrace->surface.surfaceProps ); CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, -1.0, &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage, &vecNormal, (char) pdata->game.material ); } else { CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, -1.0, &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage ); } #if !defined( CLIENT_DLL ) CSoundEnt::InsertSound ( SOUND_COMBAT, GetAbsOrigin(), BASEGRENADE_EXPLOSION_VOLUME, 3.0 ); #endif
Vector vecReported = m_ hThrower ? m_hThrower->GetAbsOrigin() : vec3_origin; ...
|
We need to check to see if the grenade that is exploding is a smoke grenade and if so create a smoke cloud. So after the line
| | int contents = UTIL_PointContents ( vecAbsOrigin );
|
we are going to add our check and the actual smoke creating code.
| | if ( m_bIsSmokeGrenade == true ) { ParticleSmokeGrenade *pSmoke = dynamic_cast<ParticleSmokeGrenade*>( CreateEntityByName(PARTICLESMOKEGRENADE_ENTITYNAME) );
Vector vForward; AngleVectors( GetLocalAngles(), &vForward ); vForward.z = 0; VectorNormalize( vForward );
pSmoke->SetLocalOrigin( GetLocalOrigin() + vForward * 75 ); pSmoke->SetFadeTime(25, 30); pSmoke->Activate(); pSmoke->SetLifetime(30); pSmoke->FillVolume(); }
else {
|
And don't forget the else { bit at the end. So that if it's not a smoke grenade we need to just explode. To close that else add a closing bracket "}") at the end of
| | else { CPASFilter filter( vecAbsOrigin ); te->Explosion( filter, -1.0, &vecAbsOrigin, !( contents & MASK_WATER ) ? g_sModelIndexFireball : g_sModelIndexWExplosion, m_DmgRadius * .03, 25, TE_EXPLFLAG_NONE, m_DmgRadius, m_flDamage ); } } <--the new closing bracket
|
While we are still working inside the ::Explode function we can make sure that when the smoke grenade explodes it doesn't do damage. So go to the line
| | RadiusDamage( info, GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );
| and right above that add this:
if you want it to still do damage just negate this part. We also need to reset the bool we have back to false at the end of the ::Explode function right before the #endif add:
| | m_bIsSmokeGrenade = false;
|
We're almost done. Last thing we must do is add a header file so that the ParticleSmokeGrenade class functions are usuable.
Go up to the top and after #if !defined( CLIENT_DLL ) add in
| | #include "particle_smokegrenade.h"
|
and we're finished!
Now when the frag grenade explodes it will start releasing a smoke plume.
Known Issues:Sometimes when the grenade is thrown and explodes close to a wall the smoke cloud never materializes. This code has also only been tested on the HL MP SDK. |
|
User Comments
Showing comments 1-4
This is very hacky, shouldnt you make totally new classes and implement a new Explode function there? ....I also remember with cs 1.6, there were bubbles, think you're up to the challenge? Does the smoke cloud make the player's screen fade?Edited by ts2do on Aug 21 2005, 08:32:22
|
|
-Yes, it is 'hacky'. that's why I submitted it to the snippet section, I think this gives someone with a basic knowledge of C++ enough information to code a new explode function on their own, and use it wherever they want..
-Bubbles? not sure what you mean there..
-Yes the screen will fade when you start to enter the smoke cloud. |
|
Remove: Vector vForward; AngleVectors( GetLocalAngles(), &vForward ); vForward.z = 0; VectorNormalize( vForward );
pSmoke->SetLocalOrigin( GetLocalOrigin() + vForward * 75 ); Add pSmoke->SetLocalOrigin( GetLocalOrigin() );
No more issues with smoke not showing up. You were changing the origin, while this could go easily into a wall and never materialize. I'm not sure what the purpose of the original code was? |
|
Is there a way to change the color of the smoke? And how do I set my own sprite? :) |
|
You must register to post a comment. If you have already registered, you must login.
|
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (10 guests)
|
|