CWorld :: KeyValue
, around line line 674.
int g_darklevel; // new code
//
// Just to ignore the "wad" field.
//
void CWorld :: KeyValue( KeyValueData *pkvd )
Then, just before the last else
, add the bold code:
else if ( FStrEq(pkvd->szKeyName, "defaultteam") )
{
if ( atoi(pkvd->szValue) )
{
pev->spawnflags |= SF_WORLD_FORCETEAM;
}
pkvd->fHandled = TRUE;
}
// start new code
else if ( FStrEq(pkvd->szKeyName, "darklevel") )
{
g_darklevel = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
// end new code
else
{
CBaseEntity::KeyValue( pkvd );
}
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;
CBasePlayer::Classify
, around line 1603, add the bold code:
//
// ID's player as such.
//
int CBasePlayer::Classify ( void )
{
// start new code
if (Illumination() <= g_darklevel)
return CLASS_NONE;
// end new code
return CLASS_PLAYER;
}
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).#define BRIGHT_GUN_FLASH 512
#define NORMAL_GUN_FLASH 256
#define DIM_GUN_FLASH 128
Muzzle flash definitions for various weapons:
mp5grenade BRIGHT_GUN_FLASH
python BRIGHT_GUN_FLASH
rpg BRIGHT_GUN_FLASH
mp5 NORMAL_GUN_FLASH
shotgun NORMAL_GUN_FLASH
glock NORMAL_GUN_FLASH
hornetgun DIM_GUN_FLASH
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; // new code
#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" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH; // new code
}
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.
if ( m_pPlayer->m_flStartCharge < gpGlobals->time - 10 )
{
// Player charged up too long. Zap him.
m_pPlayer->m_iWeaponFlash = 768; // new code
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:
int CBasePlayer :: Illumination( void )
{
int iIllum = CBaseEntity::Illumination( );
// start new code
if (!FlashlightIsOn() == false) iIllum += 200;
// end new code
iIllum += m_iWeaponFlash;
if (iIllum > 255) return 255;
return iIllum;
You could also add other conditions (such as crouching) in this way.
#include's
:
#include "extdll.h"
#include "eiface.h"
#include "util.h"
#include "game.h"
cvar_t devlight = { "dev_light", "0" }; // new code
Then move down to the GameDLLInit
and add the bold code
void GameDLLInit( void )
{
// Register cvars here:
CVAR_REGISTER (&devlight); // new code
Now open dlls game.h and right after extern void GameDLLInit(
add the bold code.
extern void GameDLLInit( void );
extern cvar_t devlight; // new code
extern cvar_t displaysoundlist;
Then open player.cpp and find PreThink
, around line line 1769. Add the bold code to the beginning of the function:
void CBasePlayer::PreThink(void)
{
// start new code
if (devlight.value != 0)
ALERT ( at_console, "You are standing in %d light!\n",Illumination() );
// end new code
int buttonsChanged = (m_afButtonLast ^ pev->button); // These buttons have changed this frame
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
.
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.
@SolidClass = worldspawn : "World entity"
[
message(string) : "Map Description / Title"
skyname(string) : "environment map (cl_skyname)"
darklevel(integer) : "Hide shadow 0-255 (0=black)" : 15" // new line
sounds(integer) : "CD track to play" : 1
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.)You must log in to post a comment. You can login or register a new account.