Mach III Logo by Spliff (spliff@vweb.net.au) Half-Life Development, Tutorials,
Modifications, and more!

Hosted by
PlanetHalfLife

NEWS
PROJECTS

SprView

SprMake

Source

ARTICLES

PainRift

Interview

"The Motion"

WANT ADS
TUTORIAL
LINKS
CREDITS

(c) 1999
Mach III Enterprises

 

Secondary Fire ] [ Gauss Turret ] Hornet Gun Turret ] Laser Spot ]

GAUSS TURRET

This tutorial will somewhat describe how to create a completely new turret. This could technically be used with any type of weaponry, providing you have a global function that actually does the firing of the weapon.


The first thing we need to do is create a function that actually fires a single Gauss round. For the common weapons there already exist such functions (FireBullet, ExplosionCreate, etc...), but not for the Gauss. So I created two functions:

GaussFire: Standard-looking Gauss round.

GaussFireExt: Takes a structure where I could define the color of the beam, brightness and width. For simplicity's sake, I am not providing for secondary fire on the Gauss.

The actual code is somewhat long, and derived from the most part from CGauss::Fire, so you could get the commented code HERE to make your life easier.


Now we need to create the class... All the following needs to be done at the end of the "dlls\func_tank.cpp" file:

First, create the class structure, pretty much like any other...

class CFuncTankGauss : public CFuncTank
{
public:
    virtual void Precache( void );
    void Fire( const Vector &barrelEnd, const Vector &forward,

               entvars_t *pevAttacker );
};


As you can see, it's derived from the CFuncTank class, which does all the work.
We make it available to the map and the engine by linking the entity name to the class..

LINK_ENTITY_TO_CLASS( func_tankgauss, CFuncTankGauss );
We precache the sounds and the sprites...

void CFuncTankGauss::Precache( void )
{
    CFuncTank::Precache();    // Just in case...

    PRECACHE_SOUND( "weapons/gauss2.wav" );
    PRECACHE_MODEL( "sprites/smoke.spr" );
    PRECACHE_MODEL( "sprites/hotglow.spr" );
}

And now the primary firing routine, which calls GaussFire however many times it has to...

void CFuncTankGauss::Fire( const Vector &barrelEnd, const Vector &forward,
                            entvars_t *pevAttacker )
{
    if ( m_fireLast != 0 )
    {
        int dmg;

        if (m_iBulletDamage)
            dmg = m_iBulletDamage;
        else
            dmg = 15;  
// Default damage

        int bulletCount = (gpGlobals->time - m_fireLast) * m_fireRate;
       
        while ( bulletCount > 0 )
        {
            UTIL_MakeAimVectors(pev->angles);
            GaussFire(pevAttacker, edict(), barrelEnd, forward, dmg);

            CFuncTank::Fire( barrelEnd, forward, pevAttacker );   
// Does muzzle flash

            bulletCount--;
        }
    }
    else
        CFuncTank::Fire( barrelEnd, forward, pevAttacker );
}

ADDING THE ENTITY TO WORLDCRAFT

Simple enough... Open up the "halflife.fgd" file, and add this line at the end:

@SolidClass base(BaseTank) = func_tankgauss : "Brush Gauss Turret" []

Do remember to duplicate this line if you ever get a new FGD file...

TUTORIALS

LEGEND

WEAPONS
ITEMS
WORLD
ENTITIES
SPECIAL
EFFECTS
HEADS-UP
DISPLAY
GAME
INTERFACE
TURRETS
OTHER