Gordon Freeman is back! Half-Life 2 picks up some time after the original Half-Life left off, with Gordon Freeman working for the G-Man. Along with scientist Eli Vance and his daughter Alyx, your mission is to... well, that would be telling.

Report this article Adding headlights to the buggy

Because some sections of Highway 17 are just too dark!

Posted by razvan252 on Jul 21st, 2007 digg this super bookmark
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:

  1. code:
  1. bool HeadlightIsOn( void ) { return m_bHeadlightIsOn; }
  2. void HeadlightTurnOn( void ) { m_bHeadlightIsOn = true; }
  3. void HeadlightTurnOff( void ) { m_bHeadlightIsOn = false; }
  4.  

and replace them with

  1. code:
  1. bool HeadlightIsOn( void ) { return m_bHeadlightIsOn; }
  2. void HeadlightTurnOn( void );
  3. void HeadlightTurnOff( void );
  4.  

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

  1. code:
  1. PrecachescriptSound( "Airboat_headlight_on" );
  2. PrecachescriptSound( "Airboat_headlight_off" );
  3.  

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

  1. code:
  1. /* if ( ucmd->impulse == 100 )
  2.  {
  3.   if (HeadlightIsOn())
  4.   {
  5.    HeadlightTurnOff();
  6.   }
  7.         else
  8.   {
  9.    HeadlightTurnOn();
  10.   }
  11.  }*/
  12.  

At the end of the file add:

  1. code:
  1. //-----------------------------------------------------------------------------
  2. // Purpose:
  3. //-----------------------------------------------------------------------------
  4. void CPropJeep::HeadlightTurnOn( void )
  5. {
  6.  EmitSound( "Airboat_headlight_on" );
  7.  m_bHeadlightIsOn = true;
  8. }
  9.  
  10. //-----------------------------------------------------------------------------
  11. // Purpose:
  12. //-----------------------------------------------------------------------------
  13. void CPropJeep::HeadlightTurnOff( void )
  14. {
  15.  EmitSound( "Airboat_headlight_off" );
  16.  m_bHeadlightIsOn = false;
  17. }
  18.  

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

  1. code:
  1. HeadlightTurnOff();
  2.  

with

  1. code:
  1. if (HeadlightIsOn())
  2.   {
  3.    HeadlightTurnOff();
  4.   }
  5.  

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

Comments
mo2k7
mo2k7 Sep 9 2007, 2:28pm says:

or is that the airboat?

0 votes     reply to comment
Czerberus
Czerberus Oct 8 2007, 4:26pm says:

i think that was the airboat !

0 votes     reply to comment
game64
game64 Apr 1 2008, 12:25am says:

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

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

+1 vote     reply to comment
Post a Comment

Only registered members can share their thoughts. So come on! Join the Mod DB community today (totally free) and do things you never thought possible.

Icon
Half-Life 2
Platforms
PC, X360, PS3, XBOX
Developer & Publisher
Valve
Engine
Source
Contact
Send Message
Official Page
Valvesoftware.com
Release Date
Released Nov 10, 2004
Game Watch
Track this game
Bookmark
Digg Super bookmark
Tutorial
Browse
Tutorials
Views
1,166 (1 today)
Report Abuse
Report this article
Bookmark
Digg Super bookmark
Related Games
Half-Life 2
Half-Life 2
Single & Multiplayer First Person Shooter