Problem with coding particle muzzle flash

Grab your favourite IDE and tinker with the innards of game engines

Problem with coding particle muzzle flash

Postby Welsh Mullet on Sun Jan 30, 2011 2:05 am

Right, i'm on the 2007 template base and i'm trying to add particle muzzle flash.
So for the code i have is:
Code: Select all
void C_BaseAnimating::ProcessMuzzleFlashEvent()
{
   // If we have an attachment, then stick a light on it.
   if ( muzzleflash_light.GetBool() )
   {
      //FIXME: We should really use a named attachment for this
      if ( m_Attachments.Count() > 0 )
      {
#if defined (SDK_DYNAMIC_FLASH )
         {
         Vector vAttachment, vAng;
         QAngle angles;
         GetAttachment( "muzzle" , vAttachment, angles  );
 
         AngleVectors( angles, &vAng );
         vAttachment += vAng * 2;
 
         dlight_t *dl = effects->CL_AllocDlight ( index );
         dl->origin = vAttachment;
         dl->color.r = 231;
         dl->color.g = 219;
         dl->color.b = 14;
         dl->die = gpGlobals->curtime + 0.05f;
         dl->radius = random->RandomFloat( 245.0f, 256.0f );
         dl->decay = 512.0f;

         PrecacheParticleSystem( "muzzle_smg1" );
         
         DispatchParticleEffect( "muzzle_smg1", vAttachment, angles );
         }
#else
         {
         Vector vAttachment;
         QAngle dummyAngles;
         GetAttachment(  LookupAttachment( "muzzle" ), vAttachment, dummyAngles );

         // Make an elight
         dlight_t *el = effects->CL_AllocElight( LIGHT_INDEX_MUZZLEFLASH + index );
         el->origin = vAttachment;
         el->radius = random->RandomInt( 32, 64 );
         el->decay = el->radius / 0.05f;
         el->die = gpGlobals->curtime + 0.05f;
         el->color.r = 255;
         el->color.g = 192;
         el->color.b = 64;
         el->color.exponent = 5;
         }
#endif
      }
   }
}


However, the muzzle flashes (Both the dlights and the particles) are being created twice, once at the eyes and once at the models crotch, instead of the gun model's muzzle.
That's what she said.
User avatar
Welsh Mullet
Regular
Regular
 
Joined: Mon Jul 12, 2010 10:37 am
Location: Reading... Or sometimes Wales for the weekend.

Re: Problem with coding particle muzzle flash

Postby Jangalomph on Sun Jan 30, 2011 3:39 am

Here is how i was told to do it.

First one, Edit you .QC file of you model.

EXAMPLE USING AR2 WEAPON MODEL :
Code: Select all
/*
==============================================================================

IRifle

==============================================================================
*/

$modelname weapons/v_IRifle.mdl
$cdmaterials models\Weapons\V_hand models\Weapons\V_irifle

// whole body
$body studio "IRifle_reference.smd"

$origin 0 0 67

//Muzzle flash
$attachment "muzzle" "Base" 0 0 20 rotate -90

$poseparameter "VentPoses" 0 1


// OLD MUZZLES - CONTROLLED BY ENGINE PARTICLES - DELETE ( COMMENT )

$sequence IR_idle "Idle" loop fps 30 activity ACT_VM_IDLE 1 node Ready
//$sequence IR_fire "Fire01" fps 30 snap activity ACT_VM_PRIMARYATTACK 1 { event AE_MUZZLEFLASH 0 "COMBINE MUZZLE" } node Fire
//$sequence fire2 "Fire02" snap fps 30 activity ACT_VM_RECOIL1 1 { event AE_MUZZLEFLASH 0 "COMBINE MUZZLE" } node Fire
//$sequence fire3 "Fire03" snap fps 30 activity ACT_VM_RECOIL2 1 { event AE_MUZZLEFLASH 0 "COMBINE MUZZLE" } node Fire
//$sequence fire4 "Fire04" snap fps 30 activity ACT_VM_RECOIL3 1 { event AE_MUZZLEFLASH 0 "COMBINE MUZZLE" } node Fire
//$sequence IR_fire2 "Alt_fire" fps 30 snap activity ACT_VM_SECONDARYATTACK 1 { event AE_MUZZLEFLASH 0 "COMBINE MUZZLE" }


// NEW MUZZLES USING OB PARTICLE SYSTEM


// How it works? - We changing old "event AE_MUZZLEFLASH" to new OB Thing "event AE_CL_CREATE_PARTICLE_EFFECT"
// "muzzle_ar2" - The Name Of Muzzle ( NOT .pcf file! the name of particle inside .pcf file )
// "follow_attachment" - moving to bone
// "muzzle" - bone name, where particle dispatching


$sequence IR_fire "Fire01" fps 30 snap activity ACT_VM_PRIMARYATTACK 1 node Fire { event AE_CL_CREATE_PARTICLE_EFFECT 0 "muzzle_ar2 follow_attachment muzzle" }
$sequence fire2 "Fire02" snap fps 30 activity ACT_VM_RECOIL1 1 node Fire { event AE_CL_CREATE_PARTICLE_EFFECT 0 "muzzle_ar2 follow_attachment muzzle" }
$sequence fire3 "Fire03" snap fps 30 activity ACT_VM_RECOIL2 1 node Fire { event AE_CL_CREATE_PARTICLE_EFFECT 0 "muzzle_ar2 follow_attachment muzzle" }
$sequence fire4 "Fire04" snap fps 30 activity ACT_VM_RECOIL3 1 node Fire { event AE_CL_CREATE_PARTICLE_EFFECT 0 "muzzle_ar2 follow_attachment muzzle" }
$sequence IR_fire2 "Alt_fire" fps 30 snap activity ACT_VM_SECONDARYATTACK 1 node Fire { event AE_CL_CREATE_PARTICLE_EFFECT 0 "muzzle_ar2 follow_attachment muzzle" }

// TEH END OF NEW CODE

$sequence IR_reload "Reload" fps 30 activity ACT_VM_RELOAD 1 node Ready {
{ event AE_CL_PLAYSOUND 1 "Weapon_AR2.Reload_Rotate" }
{ event AE_CL_PLAYSOUND 19 "Weapon_AR2.Reload_Push" }
}

$sequence IR_draw "Draw" fps 30 snap activity ACT_VM_DRAW 1 node Ready
$sequence IR_holster "Holster" fps 30 activity ACT_VM_HOLSTER 1 node Ready
$sequence idletolow "idle_to_low" fps 30 activity ACT_VM_LOWERED_TO_IDLE 1  transition Ready Low
$sequence lowtoidle "Low_to_idle" fps 30 activity ACT_VM_IDLE_TO_LOWERED 1 transition Low Ready
$sequence lowidle "Low_idle" fps 30 loop activity ACT_VM_IDLE_LOWERED 1 node Low
$sequence shake "Shake" fps 30 loop activity ACT_VM_FIDGET 1 node Fire

$animation a_vent_neutral "Vent_Poses" frame 0 0
$animation a_vent_open "Vent_Poses" frame 0 0 subtract a_vent_neutral 0
$animation a_vent_closed "Vent_Poses" frame 1 1 subtract a_vent_neutral 0
$sequence VentPoses a_vent_open a_vent_closed blend "VentPoses" 1 0 delta autoplay



And Second way is coding ( in your weapon .cpp file )

Here is the example :
Code: Select all
cpp code:
CBaseViewModel *vm = pPlayer->GetViewModel();
        DispatchParticleEffect("weapon_muzzle_flash_shotgun", PATTACH_POINT_FOLLOW, vm, vm->LookupAttachment( "muzzle" ),true);



But your still need to edit you .QC file, or old muzzle effect will dispatching too.

So, i recommend to you use first way.

Quoted from a message some one pm'd me once about it!
http://www.nomoreroominhell.com
I don’t know whether I was right or wrong, I guess I’ll never know… But I made it. And I guess I should be thankful for that. - Strelok
Has anyone really been far even as decided to use even go want to do look more like?
User avatar
Jangalomph
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Wed Jun 25, 2008 3:19 pm
Location: Sumter, SC

Re: Problem with coding particle muzzle flash

Postby Welsh Mullet on Sun Jan 30, 2011 4:15 am

I have it mostly fixed. The flash now works properly, but only in thirdperson and server side. Client side has no flash.
That's what she said.
User avatar
Welsh Mullet
Regular
Regular
 
Joined: Mon Jul 12, 2010 10:37 am
Location: Reading... Or sometimes Wales for the weekend.

Re: Problem with coding particle muzzle flash

Postby Jangalomph on Sun Jan 30, 2011 5:08 am

Cant you dispatch it in QC only? Eliminating the need for cpp
http://www.nomoreroominhell.com
I don’t know whether I was right or wrong, I guess I’ll never know… But I made it. And I guess I should be thankful for that. - Strelok
Has anyone really been far even as decided to use even go want to do look more like?
User avatar
Jangalomph
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Wed Jun 25, 2008 3:19 pm
Location: Sumter, SC

Re: Problem with coding particle muzzle flash

Postby Welsh Mullet on Sun Jan 30, 2011 5:16 pm

Well, i was doing it in code because i know more about code than models, and the fact that i wanted to create a dlight flash as well as the particles (So it lights up the area).
The models are already compiled, so how would i go about editing the QC file?
That's what she said.
User avatar
Welsh Mullet
Regular
Regular
 
Joined: Mon Jul 12, 2010 10:37 am
Location: Reading... Or sometimes Wales for the weekend.

Re: Problem with coding particle muzzle flash

Postby Jangalomph on Sun Jan 30, 2011 6:10 pm

I'm no pro on models either. But i think you can just decompile the model, then it'll generate a QC. Then you recompile it when you've made the flash changes. :P

smurftyours, or jman may know what to do.. they are pretty good at weapons etc.
http://www.nomoreroominhell.com
I don’t know whether I was right or wrong, I guess I’ll never know… But I made it. And I guess I should be thankful for that. - Strelok
Has anyone really been far even as decided to use even go want to do look more like?
User avatar
Jangalomph
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Wed Jun 25, 2008 3:19 pm
Location: Sumter, SC

Return to Programming

Who is online

Users browsing this forum: No registered users