The Place to Start

Stealthsuit

BigGuy

Easy


Copy and Paste Series

First off I would like to thank EvilClone for his Cloaking tutorial for which served as a base for this.
By adjusting the renderamounts of the player we can make him invisible. The next section should be fairly easy just to copy and paste, but please give me some credit.

1. Open mp workspace-> goto New.
2. C/C++ source file name it, stealthsuit.cpp.
3. Copy and Paste!

Stealthsuit.cpp


/*
* This is the invisible pack
* they must have this equipped in order to be cloaked
* Thought that would be best to prevent invisible frags
* As they move with this equipped they are visible
* But when they stop they are entirely invisible!
*/


#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"//Ooooh make the screen turn colors when invisible.


class CStealth : public CBasePlayerWeapon
{
public:
void Spawn( void );
void Precache( void );
int iItemSlot( void ) { return 1; }
int GetItemInfo(ItemInfo *p);
int AddToPlayer( CBasePlayer *pPlayer );
void PrimaryAttack( void );
void SecondaryAttack(void);
void Cloak(void);
void UnCloak(void);
BOOL Deploy( void );
void Holster( void );
void WeaponIdle( void );
int cloak; //cloak amount
int cloaked; //cloak flag
float flSpeed; //Speed of player



};

LINK_ENTITY_TO_CLASS( weapon_stealthsuit, CStealth ); //remember to define this in weapons.cpp and weapons.h


//need a model for this? Perhaps just hands
enum stealth_e {
SATCHEL_RADIO_IDLE1 = 0,
SATCHEL_RADIO_FIDGET1,
SATCHEL_RADIO_DRAW,
SATCHEL_RADIO_FIRE,
SATCHEL_RADIO_HOLSTER
};
int CStealth::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 CStealth::Spawn( )
{
Precache( );
m_iId = WEAPON_STEALTHSUIT;
SET_MODEL(ENT(pev), "models/w_longjump.mdl");
m_iClip = -1; //no ammo for this, but...

FallInit();// get ready to fall down.
}


void CStealth::Precache( void )
{
PRECACHE_MODEL("models/v_satchel_radio.mdl");
PRECACHE_MODEL ("models/w_longjump.mdl");
PRECACHE_MODEL("models/p_satchel_radio.mdl");

}
int CStealth::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;
p->iPosition = 1;
p->iId = WEAPON_STEALTHSUIT;
p->iWeight = CROWBAR_WEIGHT;
return 1;
} //im lazy just use some other weapons code the crowbar wont miss it



BOOL CStealth::Deploy( )
{
cloaked=0;
return DefaultDeploy( "models/v_satchel_radio.mdl", "models/p_satchel_radio.mdl", SATCHEL_RADIO_DRAW, "satchel" );

}

void CStealth::Holster( )
{
m_pPlayer->m_flNextAttack = gpGlobals->time + 0.5;
if (cloaked)
{
cloak= 255;
UnCloak();
}

SendWeaponAnim( SATCHEL_RADIO_HOLSTER );
}

void CStealth::PrimaryAttack()
{
m_flNextPrimaryAttack = gpGlobals->time + 2;
if (!(cloaked))
{
cloak=18;
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "Cloaking...");
Cloak();
UTIL_ScreenFade( m_pPlayer, Vector(15,15,255), 1, 0.5, 128, FFADE_OUT |
FFADE_STAYOUT);
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "You are now invisible!");
}
else
{
flSpeed = m_pPlayer->pev->velocity.Length(); //get players speed
cloak = (flSpeed + 6) * 3;
m_pPlayer->pev->renderamt = cloak;
}

/*if (cloaked & m_pPlayer->pev->button & (IN_ATTACK))
{
m_pPlayer->pev->renderamt = 255;
}*/
SendWeaponAnim( SATCHEL_RADIO_FIRE );

}

void CStealth::SecondaryAttack()
{
m_flNextSecondaryAttack = gpGlobals->time + 2;
if (!(cloaked))
{
return;
}
else
{
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "Uncloaking...");
cloak=255;
UnCloak();
UTIL_ScreenFade( m_pPlayer, Vector(15,15,255), 0.01, 0.5, 128, FFADE_IN);
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "You are now visible!");
}
SendWeaponAnim( SATCHEL_RADIO_FIRE );

}

void CStealth::Cloak()
{
//Put the cloaking stuff here
m_pPlayer->pev->renderamt = cloak;
m_pPlayer->pev->rendermode = kRenderTransAlpha;
//This lets you see thought them
cloaked=1;
return;
}

void CStealth::UnCloak()
{
//Uncloaking here
m_pPlayer->pev->renderamt = cloak; //Return them to normal values
m_pPlayer->pev->renderfx = kRenderFxNone;
m_pPlayer->pev->rendermode = kRenderNormal;
cloaked=0;
return;
}

void CStealth::WeaponIdle()
{
flSpeed = m_pPlayer->pev->velocity.Length(); //get players speed
if (cloaked)
{
if(!(m_pPlayer->pev->button & (IN_MOVELEFT|IN_MOVERIGHT|IN_FORWARD|IN_BACK|IN_JUMP)))
{ //test to see if you are moving left/right/forward/back/jump
cloak=18;
m_pPlayer->pev->renderamt = cloak;
}
else
{
cloak = (flSpeed + 6)*3;
m_pPlayer->pev->renderamt = cloak;
//this is so you gain visibility while moving
}
}
else
{
cloak=255;
m_pPlayer->pev->renderamt = cloak;
}

}


Remember to define the weapon in weapons.h and weapons.cpp. See the NVGoggles tutorial for how to do it.

Download the sprite file.
*Extra Credit*

Make the stealthsuit take battery power.
Old in BLUE.
New in RED.

Lets add a new line in Cloak()

//Put the cloaking stuff here
if (m_pPlayer->pev->armorvalue <= 3)
{
ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "You cannot cloak due\n to battery power\n");
return;
}
else
{
m_pPlayer->pev->armorvalue -= 2; //takes more battery power to turn on than off
}

m_pPlayer->pev->renderamt = cloak;

Then in UnCloak()

//Uncloaking here
m_pPlayer->pev->armorvalue -= 1;
m_pPlayer->pev->renderamt = cloak;

Finally in WeaponIdle()

if (m_pPlayer->pev->armorvalue <= 2)
{

ClientPrint(m_pPlayer->pev, HUD_PRINTCENTER, "You battery power too\n low to remain cloaked!");

Uncloak()
}