Adding Headlights to the Buggy: Difference between revisions
Jump to navigation
Jump to search
GamerDude27 (talk | contribs) (Initial article) |
GamerDude27 (talk | contribs) mNo edit summary |
||
Line 33: | Line 33: | ||
</source> | </source> | ||
Then in <code>void CPropJeep::DriveVehicle( ... )</code> uncomment the following code | Then in <code>void CPropJeep::DriveVehicle( ... )</code> uncomment the following block of code: | ||
<source lang=cpp | <source lang=cpp> | ||
/* | /*if ( ucmd->impulse == 100 ) | ||
{ | { | ||
if ( HeadlightIsOn() ) | if ( HeadlightIsOn() ) | ||
Line 46: | Line 45: | ||
HeadlightTurnOn(); | HeadlightTurnOn(); | ||
} | } | ||
} | }*/ | ||
*/ | |||
</source> | </source> | ||
Revision as of 15:46, 9 March 2021
The Tutorial
This tutorial explains how to add headlights to the Buggy.
It requires a basic understanding of C++ but the actual code is very simple.
The Code
vehicle_jeep.h
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 );
vehicle_jeep.cpp
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 the following block of code:
/*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();
}
Conclusion
And we're done! All we needed to do was uncomment some code and add a sound to play.