Wavelength Logo
tl.jpg (2351 bytes) blank.gif (837 bytes) tr.jpg (2446 bytes)
blank.gif (837 bytes)
BigGuy's NVGoggles by BigGuy
blank.gif (837 bytes)
COPY AND PASTE SERIES

(This assumes you have MS VC++ 5.0 or better without it I cannot help.)

I know most of you have seen EvilClone's tutorial on making night vision goggles. You most likely have seen that it is rated to be 'hard.' So I fired up my MSVC++ and started creating my own night vision goggles that will, I hope, be easier to make. Statements in
CYAN are new. Statements in GREEN are original statements in the source code.

NOTE: NV Goggles are a nice effect but do little in providing additional lighting.

First off open the mp workspace.

Then Add to Project-> new C/C++ source file. Name it NightVision.

The Code

////Beginning of nightvision.cpp
/*
Make sure you give some detail of what this file is:
night vision goggles
you can cut and paste this directly into nightvision.cpp
*/
//Basic includes for weapons


#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "gamerules.h"
#include "shake.h" //This is required for the screen fade

//these are for the animations

enum nightvision_e {
TRIPMINE_IDLE1 = 0,
TRIPMINE_IDLE2,
TRIPMINE_ARM1,
TRIPMINE_ARM2,
TRIPMINE_FIDGET,
TRIPMINE_HOLSTER,
TRIPMINE_DRAW,
TRIPMINE_WORLD,
TRIPMINE_GROUND,
};
//I use the tripmine model because it looks like goggles

class CNightVision : public CBasePlayerWeapon
{
public:
void Spawn( void );
void Precache( void );
int iItemSlot( ) { return 3; }
int GetItemInfo(ItemInfo *p);
void PrimaryAttack( void );
void SecondaryAttack( void );
int AddToPlayer( CBasePlayer *pPlayer );
BOOL Deploy( );
void Holster( );
void WeaponIdle( void );

int m_fInZoom; // don't save this
int m_flNextAttack;

}; //Some more basic weapon stuff

LINK_ENTITY_TO_CLASS( weapon_goggles, CNightVision );
//Links this weapon

void CNightVision::Spawn( )
{
Precache( );
m_iId = WEAPON_NIGHTVISION;
SET_MODEL(ENT(pev), "models/w_crossbow.mdl");
//doesnt matter what model if in multiplayer
m_iClip = -1; // weapon doesnt need ammo
FallInit();// get ready to fall down.
}

int CNightVision::AddToPlayer( CBasePlayer *pPlayer )
{
if ( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}


void CNightVision::Precache( void )
{
PRECACHE_MODEL("models/w_crossbow.mdl");
PRECACHE_MODEL("models/v_tripmine.mdl");
PRECACHE_MODEL("models/p_tripmine.mdl");

PRECACHE_SOUND("player/geiger1.wav");
} //Precache stuff, important


int CNightVision::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = NULL;
p->iMaxAmmo1 = -1;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 0; //first slot
p->iPosition = 1; //right after crowbar
p->iId = WEAPON_NIGHTVISION;
p->iFlags = 0;
p->iWeight = CROWBAR_WEIGHT;
/*
dont need new weight
this makes it easier to code!
*/
return 1;
}

BOOL CNightVision::Deploy( )
{
return DefaultDeploy( "models/v_tripmine.mdl", "models/p_tripmine.mdl", TRIPMINE_DRAW, "crowbar" );

}
void CNightVision::Holster( )
{
if ( m_fInZoom ) //if zoomed
{
UTIL_ScreenFade( m_pPlayer, Vector(0,255,0), 1, 0.5, 128, FFADE_IN);
m_fInZoom = 0;
m_pPlayer->m_iFOV = 0;
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "player/geiger1.wav",
0.8, ATTN_NORM);
}

m_pPlayer->m_flNextAttack = gpGlobals->time + 0.5;

SendWeaponAnim( TRIPMINE_HOLSTER );//put that away!
}

void CNightVision::PrimaryAttack( void ) //Zoom in
{
m_pPlayer->m_iFOV = 20; //Zoom factor 0 is normal
m_fInZoom = 1; //Sets flag
UTIL_ScreenFade( m_pPlayer, Vector(0,255,0), 1, 0.5, 128, FFADE_OUT |
FFADE_STAYOUT); //fades to green
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "player/geiger1.wav",
0.8, ATTN_NORM); //plays a little sound
pev->nextthink = gpGlobals->time + 0.1;
m_flNextAttack = gpGlobals->time + 1.0; //not sure,works?
}

void CNightVision::SecondaryAttack( void ) //Zoom out
{
if (m_fInZoom)
{
m_pPlayer->m_iFOV= 0; //Reset to normal
m_fInZoom=0; //reset flag
UTIL_ScreenFade( m_pPlayer, Vector(0,255,0), 0.01, 0.5, 128, FFADE_IN); //fade out from green
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "player/geiger1.wav",
0.8, ATTN_NORM); //play sound
pev->nextthink = gpGlobals->time + 0.1;
m_flNextSecondaryAttack = gpGlobals->time + 1.0;//waits
}
}


void CNightVision::WeaponIdle( void ) //just sit there
{

float flRand2 = RANDOM_FLOAT(0, 1); //just passing the time
if (m_flTimeWeaponIdle < gpGlobals->time)
{
float flRand = RANDOM_FLOAT(0, 1);

if (flRand <= 0.75)
{
if (flRand2 <= 0.50)
{
SendWeaponAnim( TRIPMINE_IDLE1 );
}
else
{
SendWeaponAnim( TRIPMINE_IDLE2 );
}
m_flTimeWeaponIdle = gpGlobals->time + RANDOM_FLOAT ( 10, 15 );
}
else
{
SendWeaponAnim( TRIPMINE_FIDGET );
m_flTimeWeaponIdle = gpGlobals->time + 80.0 / 30.0;

}
}
}
///end of nightvision.cpp

Ok thats enough of the hard stuff.
Open weapons.cpp and go to line 386 or there abouts. You should see:

#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
// hornetgun
UTIL_PrecacheOtherWeapon( "weapon_hornetgun" );
#endif

Right after that put:

//NVGoggles
UTIL_PrecacheOtherWeapon( "weapon_goggles");
//BigGuy

One last coding part:

Open weapons.h and go to line 79 right after the
#define WEAPON_SNARK 15

type this:

//NVG define
#define WEAPON_NIGHTVISION 16
//BigGuy

You now have a working pair of Night Vision goggles. But you want a pretty sprite dont you so heres something to get it going. Open Notepad and type this:

6
weapon 320 320hud2 0 36 80 20
weapon_s 320 320hud2 0 104 80 20
ammo 320 320hud2 90 52 18 18
weapon 640 640hud6 0 200 170 45
weapon_s 640 640hud6 0 200 170 45
ammo 640 640hud7 144 96 24 24

This will get you a '???' sprite in the weapon selection.
Save it in your Mods->Sprite folder and name it weapon_goggles.txt
Now start a game, press '~' and type '/give weapon_goggles'. This will give you the NV goggles. You can find it right after the crowbar.

I am not going into creating the components for Worldcraft, you can read Psychodude's tutorial on that.


*Extra Credit*
Progressive Zooming

Lets add progressive zooming to our goggles. This will allow you to zoom in slowly on a target.

First in your

class CNightVision : public CBasePlayerWeapon
{
public:
//add this
int zoom;

Replace your PrimaryAttack() with this:

if (m_fInZoom)
{
pev->nextthink = gpGlobals->time + 0.1;
m_flNextPrimaryAttack = gpGlobals->time + 0.1;
}
else
{
UTIL_ScreenFade( m_pPlayer, Vector(0,255,0), 1, 0.5, 128, FFADE_OUT |
FFADE_STAYOUT);
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "player/geiger1.wav",
0.8, ATTN_NORM);

m_fInZoom = 1;
zoom=90;
}

if (m_pPlayer->m_iFOV==10)
{
ClientPrint(m_pPlayer->pev, HUD_PRINTNOTIFY, "Max Zoom.\n");
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "player/geiger1.wav",
0.8, ATTN_NORM);
return;
}
else
{
zoom--;
zoom--;
m_pPlayer->m_iFOV = zoom;
}


Replace your SecondaryAttack() with this:

if (m_fInZoom)
{
pev->nextthink = gpGlobals->time + 0.1;
m_flNextPrimaryAttack = gpGlobals->time + 0.1;
}
else
{
UTIL_ScreenFade( m_pPlayer, Vector(0,255,0), 1, 0.5, 128, FFADE_IN);
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "player/geiger1.wav",
0.8, ATTN_NORM);

m_fInZoom = 0;
zoom=0;
}
if (m_pPlayer->m_iFOV==0 || m_pPlayer->m_iFOV>87)
{
UTIL_ScreenFade( m_pPlayer, Vector(0,255,0), 0.01, 0.5, 128, FFADE_IN);
//CLIENT_COMMAND((edict_t *)pev, "gl_overbright 0\n");
zoom = 0;
m_fInZoom = 0;
m_pPlayer->m_iFOV = zoom;
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "player/geiger1.wav",
0.8, ATTN_NORM);
return;
}
else
{
zoom++;
zoom++;
m_pPlayer->m_iFOV = zoom;
}

If any one figures out a way to brighten areas without using the gl mode, please tell me and I will incorporate it in this tutorial.

*Extra Extra Credit*
Creating Infrared Vision

Again this has the same problems as with the NVGoggles.

Simply replace the
Vector(0,255,0) with Vector(255,0,0). Thats it!.


Any questions or suggestions should be sent to me:
venturis52@hotmail.com

 

blank.gif (837 bytes)
bl.jpg (2471 bytes) blank.gif (837 bytes) br.jpg (2132 bytes)