Now we will need to declare the variable as a global, as we will need to read it from another part of the DLL for the next part. We could make our own .h, but it's easier to just use cbase.h as it's already included where we need the variable. Open dlls\cbase.h and add the bold code in the very beginning:

extern int g_darklevel;

The Actual Check

Open dlls\player.cpp, and as the first thing in the CBasePlayer::Classify, around line 1603, add the bold code:

This just compares the variable to the current illumination. If this checks out, it returns CLASS_NONE which monsters ignore; if the illumination is higher, it returns CLASS_PLAYER and monsters will attack. The illumination is a function that is already in the player.cpp. It simply takes the brightness of the light map under the player and adds a virtual muzzle flash light value to it (if the player fires a gun).

The brightness of the muzzle flashes can be changed accordingly in dlls\weapons.h (Note that this doesn't change the actual muzzle flash). Also note that any values above 255 will simply add to the time of the effect.

The Gauss and Egon should also have an effect on the illumination, correct? Note that we can add any of the 3 muzzle flash definitions to the weapons, but for this article we will be using BRIGHT_GUN_FLASH. Now for the Egon, open dlls\egon.cpp and go to line 289. Add the bold code after case FIRE_WIDE: but outside the #ifndef CLIENT_DLL, as the light check happens on the server side.

case FIRE_WIDE:

m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;

#ifndef CLIENT_DLL

Then for the Gauss, open dlls\gauss.cpp and add the muzzle flash next to the fire animation, like so.

// player "shoot" animationm_pPlayer->SetAnimation( PLAYER_ATTACK1 );

m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;

}

Say, for example, we also need it to illuminate when the Gauss overcharges. Here we want the player to glow for the same amount of time that the effect lasts, so we use a fixed value for the muzzle flash. Add the bold code where that happens.

However, the illumination doesn't include dynamic lights like the flashlight, so we will have to add this ourselves. Back in dlls\player.cpp find CBasePlayer :: Illumination, which should be around line 4130. Add the bold code:

Assuming you will want to debug maps that use this feature, you would probably want to add a developer command to test illumination levels around the map. To do this, we will have to add a CVAR. This is basically done the same way we added the global variable. Open dlls\game.cpp and add the bold code right after the #include's:

I use PreThink because it updates every frame, so we will get the light value real-time. To activate the light tester in-game, you have to be in developer mode, which you can activate by bringing down the console and type dev_light 1.

The FGD

Finally, we need to edit the FGD to include this new option. Open a Half-Life FGD in Wordpad, and search for worldspawn, then add the bold code in between the other options. Make sure the proper game configuration and FGD are selected when loading Valve Hammer Editor.

Then, to set the needed light level in a map within Valve Hammer Editor, go to Map Properties and edit the value in the Hide shadow field. ("Map Properties" essentially accesses the worldspawn entity, in case you haven't noticed.)

Lastly, I would like to thank Teh_Freak for helping me with some of the functions.