Fog for Half life 2 map.

Anthemjack

Active Member
Joined
Sep 28, 2008
Messages
408
Hey guys!

I'm trying to make fog for my map, but i'm having difficulty making it....
 
fog is a visual effect, controlled by a point entity (an env_fog) which you can insert into your level. It can be toggled on or off as required. It can be any color you choose, and its apparent density is controlled by setting the start and end distances over which the effect is applied.

Here's the Code for fog which I'm guessing you don't really care about nor do you want.

Server-side: The ClientFog Class

First we need to create support for the env_fog entity. This is done server-side (in the dlls directory, and the associated Project/Workspace.)

Open the dlls/effects.cpp file in your favourite editor and add the following code at the end of the file:

//=======================
// ClientFog
//=======================
extern int gmsgSetFog;

// This is the flag defined by the env_fog entity
#define SF_FOG_STARTOFF 0x0001
LINK_ENTITY_TO_CLASS( env_fog, CClientFog );

/*
// While a CClientFog constructor is not actually necessary for
// this code, you might find use for one down the track,
// in which case it may look like this:
CClientFog *CClientFog::FogCreate( void )
{
CClientFog *pFog = GetClassPtr( (CClientFog *)NULL );
pFog->pev->classname = MAKE_STRING("env_fog");
pFog->Spawn();
return pFog;
}
/*

// Spawns our env_fog entity and sets the m_active flag.
void CClientFog :: Spawn ( void )
{
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_NONE;
pev->effects = 0;
if ( pev->spawnflags & SF_FOG_STARTOFF )
m_active = 0;
else
{
SetThink( FogThink );
pev->nextthink = gpGlobals->time + 0.01;
m_active = 1;
}
}

// Reads salient values from the env_fog entity
void CClientFog :: KeyValue( KeyValueData *pkvd )
{
if (FStrEq(pkvd->szKeyName, "startdist"))
{
m_iStartDist = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if (FStrEq(pkvd->szKeyName, "enddist"))
{
m_iEndDist = atoi(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
CBaseEntity::KeyValue( pkvd );
}

// Essentially turns our fog effect on/off by sending a message to the client.
// Anything which changes m_active should force a FogThink.
void CClientFog :: FogThink ( void )
{
if ( m_active )
{
MESSAGE_BEGIN( MSG_ALL, gmsgSetFog, NULL );
WRITE_SHORT ( pev->rendercolor.x );
WRITE_SHORT ( pev->rendercolor.y );
WRITE_SHORT ( pev->rendercolor.z );
WRITE_SHORT ( m_iStartDist );
WRITE_SHORT ( m_iEndDist );
MESSAGE_END();
}
else
{
MESSAGE_BEGIN( MSG_ALL, gmsgSetFog, NULL );
WRITE_SHORT ( 0 );
WRITE_SHORT ( 0 );
WRITE_SHORT ( 0 );
WRITE_SHORT ( 0 );
WRITE_SHORT ( 0 );
MESSAGE_END();
}
}

// Called when the entity is triggered.
void CClientFog::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
if ( ShouldToggle( useType, m_active ) )
m_active = !m_active;
SetThink( FogThink );
pev->nextthink = gpGlobals->time + 0.01;
}

// These macros set up the save/restore code for the CClientFog object
TYPEDESCRIPTION CClientFog::m_SaveData[] =
{
DEFINE_FIELD( CClientFog, m_active, FIELD_BOOLEAN ),
DEFINE_FIELD( CClientFog, m_iStartDist, FIELD_INTEGER ),
DEFINE_FIELD( CClientFog, m_iEndDist,FIELD_INTEGER ),
};
 
fog is a visual effect, controlled by a point entity (an env_fog) which you can insert into your level. It can be toggled on or off as required. It can be any color you choose, and its apparent density is controlled by setting the start and end distances over which the effect is applied.

Here's the Code for fog which I'm guessing you don't really care about nor do you want.

Con, I care about anything that is related to mapping even if it is hard, I'd go for it.:D
 

Latest posts

Back
Top