Hey,
Welcome to HL Coders, and Cpp
If you want all your explosion's to have the same particular effects i would
recommend that you hunt down void CBasePlayer::OnDamagedByExplosion( const
CTakeDamageInfo &info ) in player.cpp - this would be better then flooding your
memory space with the same file many times - or precache the the weapons.cpp
file - seeing that this would be called for 99% of the weapons your going to
use.
This code explains it self (i hope) - its ep1 code, with gmod blur (found on
the VDC wiki)
//-----------------------------------------------------------------------------
// Purpose:
// This grabs how far the blast radias from explosives effects the player in
float
// 12.0f = 1 foot = ~30cm
// Code by Adam 'amckern' McKern
//-----------------------------------------------------------------------------
#define MIN_SHOCK_AND_CONFUSION_DAMAGE 30.0f
#define MIN_EAR_RINGING_DISTANCE 400.0f //~33Feet/~1.1M
//-----------------------------------------------------------------------------
// Purpose:
// Input : &info -
//-----------------------------------------------------------------------------
void CBasePlayer::OnDamagedByExplosion( const CTakeDamageInfo &info )
{
float lastDamage = info.GetDamage();
float distanceFromPlayer = 9999.0f;
CBaseEntity *inflictor = info.GetInflictor();
if ( inflictor )
{
Vector delta = GetAbsOrigin() - inflictor->GetAbsOrigin();
distanceFromPlayer = delta.Length();
}
bool ear_ringing = distanceFromPlayer < MIN_EAR_RINGING_DISTANCE ? true :
false;
bool shock = lastDamage >= MIN_SHOCK_AND_CONFUSION_DAMAGE;
if ( !shock && !ear_ringing )
return;
//Disable DSP effect
/*int effect = shock ?
random->RandomInt( 35, 37 ) :
random->RandomInt( 32, 34 );
*/
CSingleUserRecipientFilter user( this );
// enginesound->SetPlayerDSP( user, effect, false );
//-----------------------------------------------------------------------------
// Purpose:
// This will splash the player with a good dose of motion blur when an explosive
// Hits within the blast radius as defined in MIN_EAR_RINGING_DISTANCE.
// All this code hooks in over the DSP effect radius, and the motion blur is
// Controlled via engine convar changes, and a small timer.
// Code by Adam 'amckern' McKern
//-----------------------------------------------------------------------------
EmitSound( "Nightfall.BlurEffect" ); //weapons/blur.mp3
cvar->FindVar("pp_motionblur_time")->SetValue(0.01f);
cvar->FindVar("pp_motionblur_addalpha")->SetValue(0.1f);
cvar->FindVar("pp_motionblur_drawalpha")->SetValue(1.0f);
m_flEndBlurTime = gpGlobals->curtime + 1.5; //Blur timeout
m_flEndBlurOverlayTime = gpGlobals->curtime + 1.4; //Overlay timeout
SetThink( &CBasePlayer::BlurDelayThink );
SetNextThink( gpGlobals->curtime );
}
void CBasePlayer::BlurDelayThink()
{
if ( gpGlobals->curtime > m_flEndBlurOverlayTime )
{
cvar->FindVar("pp_motionblur_time")->SetValue(0.005f);
cvar->FindVar("pp_motionblur_addalpha")->SetValue(0.9f);
cvar->FindVar("pp_motionblur_drawalpha")->SetValue(0.3f);
}
if ( gpGlobals->curtime > m_flEndBlurTime )
{
//add something here if needed, it WAS for the expoverlay effect
}
SetNextThink( gpGlobals->curtime + 0.1 );
}
--------
Owner Nigredo Studios http://www.nigredostudios.com
--- On Sun, 29/11/09, nick seavert <[email protected]> wrote:
From: nick seavert <[email protected]>
Subject: [hlcoders] Coding particle effects into explosions using PCF's and
more.
To: [email protected]
Received: Sunday, 29 November, 2009, 2:04 PM
Hello,
I'm Nick/Jangalomph and I'm new to C++ coding for the Source Engine, i have 6
months visual basic experience from school. But down to the nitty gritty.
I have this code taken from grenade_ar2.cpp.
What I've made bold are the changes I've made with the help of a noob coder as
myself.
void CGrenadeAR2::Detonate(void)
{
DispatchParticleEffect( "sb_smg1_explosion_1", GetAbsOrigin(),
GetAbsAngles() );
}
{
if (!m_bIsLive)
{
return;
}
m_bIsLive = false;
m_takedamage = DAMAGE_NO;
if(m_hSmokeTrail)
{
UTIL_Remove(m_hSmokeTrail);
m_hSmokeTrail = NULL;
}
CPASFilter filter( GetAbsOrigin() );
te->Explosion( filter, 0.0,
&GetAbsOrigin(),
g_sModelIndexFireball,
2.0,
15,
TE_EXPLFLAG_NONE,
m_DmgRadius,
m_flDamage );
Vector vecForward = GetAbsVelocity();
VectorNormalize(vecForward);
trace_t tr;
UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + 60*vecForward, MASK_SHOT,
this, COLLISION_GROUP_NONE, &tr);
if ((tr.m_pEnt != GetWorldEntity()) || (tr.hitbox != 0))
{
// non-world needs smaller decals
if( tr.m_pEnt && !tr.m_pEnt->IsNPC() )
{
UTIL_DecalTrace( &tr, "SmallScorch" );
}
}
else
{
UTIL_DecalTrace( &tr, "Scorch" );
}
UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START );
RadiusDamage ( CTakeDamageInfo( this, GetThrower(), m_flDamage, DMG_BLAST
), GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );
UTIL_Remove( this );
}
void CGrenadeAR2::Precache( void )
{
PrecacheParticleSystem( "sb_smg1_explosion_1" );
PrecacheModel("models/Weapons/ar2_grenade.mdl");
}
CGrenadeAR2::CGrenadeAR2(void)
{
m_hSmokeTrail = NULL;
}
I've added 2 - 3 lines of code that preaches a particle effect along with the
normal explosion. The particle dispatched is a PCF file created by me. The
explosion works. And all is well. It looks good with the normal explosion
spawning too. First off why does it spawn it at that certain line in the code?
If i place the line else where it would give me errors. All in all, why does it
work? So if you precache a grenade effect like this in the smg1 grenade. How
could you do it for a Frag grenade?
My second question is. I had an idea to replace the combine ball/orb with an
electric beam. I could either dispatch particle effects "PCF KIND" to go where
the cross-hair is, or go to the nearest NPC and zap them to vaporize them as
the combine ball does. How would this be done?
My third question goes back to particle effects. In Smod you see lots of impact
particle effects, from grenade explosions creating dust clouds in the air, to
new sparks. How could i replace hard coded impacts with PCF impact effects?
My fourth and final question "for now" is how would i parent a blood particle
effect to an NPC. As if i shoot an NPC in the head and the emission starts from
there and he moves and the blood is still squirting. Is there a way to hard
code this? And if the NPC dies/ragdolls how could you make the blood effects
follow that ragdoll?
Thanks,
Nick S.
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders
__________________________________________________________________________________
Last chance to win a Sony entertainment pack thanks to Yahoo!7. Hurry, ends Nov
30. Enter now: http://au.docs.yahoo.com/homepageset/
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders