Pick up the crowbar of research scientist Gordon Freeman, who finds himself on an alien-infested Earth being picked to the bone, its resources depleted, its populace dwindling. Freeman is thrust into the unenviable role of rescuing the world from the wrong he unleashed back at Black Mesa. And a lot of people, people he cares about, are counting on him.

Post tutorial Report RSS Adding headlights to the buggy

Because some sections of Highway 17 are just too dark!

Posted by on - Basic Server Side Coding

[page=The Tutorial]
This tutorial explains how to add headlights to the Jeep. It requires basic understanding of C++
The actual code is very simple

First open vehicle_jeep.h. Find:

bool HeadlightIsOn( void ) { return m_bHeadlightIsOn; }
void HeadlightTurnOn( void ) { m_bHeadlightIsOn = true; }
void HeadlightTurnOff( void ) { m_bHeadlightIsOn = false; }

and replace them with

bool HeadlightIsOn( void ) { return m_bHeadlightIsOn; }
void HeadlightTurnOn( void );
void HeadlightTurnOff( void );

Now for vehicle_jeep.cpp. Go to void CPropJeep::Precache( void ) and add these

PrecachescriptSound( "Airboat_headlight_on" );
PrecachescriptSound( "Airboat_headlight_off" );

Then in void CPropJeep::DriveVehicle( ... ) uncomment

/* if ( ucmd->impulse == 100 )
 {
  if (HeadlightIsOn())
  {
   HeadlightTurnOff();
  }
        else 
  {
   HeadlightTurnOn();
  }
 }*/

At the end of the file add:

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPropJeep::HeadlightTurnOn( void )
{
 EmitSound( "Airboat_headlight_on" );
 m_bHeadlightIsOn = true;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CPropJeep::HeadlightTurnOff( void )
{
 EmitSound( "Airboat_headlight_off" );
 m_bHeadlightIsOn = false;
}

Next in void CPropJeep::ExitVehicle( int nRole ) replace

HeadlightTurnOff();

with

if (HeadlightIsOn())
  {
   HeadlightTurnOff();
  }

And we're done! All we needed to do was uncomment some code and add a sound to play.

Post comment Comments
mo2k7
mo2k7 - - 16 comments

or is that the airboat?

Reply Good karma Bad karma0 votes
Czerberus
Czerberus - - 2 comments

i think that was the airboat !

Reply Good karma Bad karma0 votes
game64
game64 - - 3 comments

the
PrecachescriptSound( "Airboat_headlight_on" );
PrecachescriptSound( "Airboat_headlight_off" );

should be notice the capitals.
PrecacheScriptSound( "Airboat_headlight_on" );
PrecacheScriptSound( "Airboat_headlight_off" );

Reply Good karma Bad karma+1 vote
nosfer4tu
nosfer4tu - - 1,378 comments

ughh i dont undestand where should i find that vehicle_jeep.h. ?? 0.o

Reply Good karma Bad karma+2 votes
GamerDude27
GamerDude27 - - 946 comments

For anyone passing by and seeing scrambled code, here you go (in order of appearance):

bool HeadlightIsOn( void ) { return m_bHeadlightIsOn; }
void HeadlightTurnOn( void ) { m_bHeadlightIsOn = true; }
void HeadlightTurnOff( void ) { m_bHeadlightIsOn = false; }

-----

bool HeadlightIsOn( void ) { return m_bHeadlightIsOn; }
void HeadlightTurnOn( void );
void HeadlightTurnOff( void );

-----

PrecacheScriptSound( "Airboat_headlight_on" );
PrecacheScriptSound( "Airboat_headlight_off" );

-----

/*if ( ucmd->impulse == 100 )
{
    if ( HeadlightIsOn() )
    {
        HeadlightTurnOff();
    }
    else
    {
        HeadlightTurnOn();
    }
}*/

-----

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropJeep::HeadlightTurnOn( void )
{
    EmitSound( "Airboat_headlight_on" );
    m_bHeadlightIsOn = true;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropJeep::HeadlightTurnOff( void )
{
    EmitSound( "Airboat_headlight_off" );
    m_bHeadlightIsOn = false;
}

-----

HeadlightTurnOff();

-----

if ( HeadlightIsOn() )
{
    ‎‎‎‎HeadlightTurnOff();
}

Reply Good karma Bad karma+1 vote
Guest
Guest - - 689,527 comments

This comment is currently awaiting admin approval, join now to view.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: