Check out Half-Life Re-imagined competition results!
Check out Skewing textures in Hammer, our newest tutorial!
Say hello to kesizewi, our newest member!


Site Stuff






Feeling Blue

What's your favourite shade of blue?














6 mins

Dr. Orange

17 mins

Xx maha xx

20 mins


21 mins

ninja defuse

45 mins


51 mins

The Mad Carrot

57 mins



A gaming and technology blog by TWHL admins Penguinboy and Ant. A music blog by TWHL users Ant and Hugh.

Adding muzzle flashes that also light up world brushes

By Cale 'Mazor' Dunlap

Untitled Document

Function names are in RED

File names are in ORANGE

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: