VERC: Adding muzzle flashes that also light up world brushes Last edited 2 years ago2022-09-29 07:54:02 UTC

We all know that guns produce a flash of light when shot (well, not all, but most). Half-Life already has a system similar to this implemented, but it only lights entities. This will show you how to light the world. Now the beauty of the system I have, is that you don't take up any more network traffic for the lighting. Its all done via the weapon's fire event.

First open ev_hldm.h, then at the bottom add:
void EV_HLDM_MuzzleFlash( vec3_t pos, float amount );
Then open ev_hldm.cpp, this is where we will make the function body, above:
// play a strike sound based on the texture that was hit by the attack traceline. VecSrc/VecEnd are the
// original traceline endpoints used by the attacker, iBulletType is the type of bullet that hit the texture.
// returns volume of strike instrument (crowbar) to play
float EV_HLDM_PlayTextureSound( int idx, pmtrace_t *ptr, float *vecSrc, float *vecEnd, int iBulletType )
Add this:
// mazor begin
void EV_HLDM_MuzzleFlash(vec3_t pos, float amount)
{
      dlight_t *dl = gEngfuncs.pEfxAPI->CL_AllocDlight(0);
      dl->origin = pos;
      dl->color.r = 255; // red
      dl->color.g = 255; // green
      dl->color.b = 128; // blue
      dl->radius = amount * 100;
      dl->die = gEngfuncs.GetClientTime() + 0.01;
}
// mazor end
Now find the function:
void EV_FireGlock1( event_args_t *args )
Find in the function where it says:
EV_GetGunPosition( args, vecSrc, origin );
Right after that line add this:
// mazor begin
EV_HLDM_MuzzleFlash( vecSrc, 1.0 + gEngfuncs.pfnRandomFloat( -0.2, 0.2 ) );
// mazor end
Now that creates a call to the muzzle flash function with the proper location, and a varying flash intensity of ~1.0, which when it gets into the function, it is multiplied by 100, so the flash radius is anywhere between 80 and 120 after calculation. This creates a good varying effect because not every muzzle flash always has the same radius and intensity. You can alter the color as much as you like. Good intensities for small weapons (pistols, smg's, etc) is anywhere between 0.8 - 2.0. Which makes the radius somewhere beteween 80 and 200. Larger weapons, like machineguns would have a number from 2.5 - 4.0. That makes the flashes 250-400 units wide, definately enough to light up a room. I used a very similar system in Firearms to create the muzzle flash lighting. Any questions or comments email me: mazor579@hotmail.com
This article was originally published on Valve Editing Resource Collective (VERC).
The archived page is available here.
TWHL only publishes archived articles from defunct websites, or with permission. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.