I search for solutions in this order: Past Code, Unreal Source, Wiki, BUF, groups.yahoo, google, screaming at monitor. – RegularX

Legacy:Vehicles Pre2004/TakeDamage

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

Don't kill the driver!

The TakeDamage can be changed so that if the vehicle is destroyed, the driver doesn't die, but takes a lot of damage. This is useful for smaller vehicles like bikes.

function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, 
						Vector momentum, class<DamageType> damageType)
{
	Local Pawn OldDriver; //The driver that just exited
 
	// Avoid damage healing the car!
	if(Damage < 0)
		return;
 
	if(damageType == class'DamTypeSuperShockBeam')
		Health -= 100; // Instagib doesn't work on vehicles
	else
		Health -= 0.5 * Damage; // Weapons do less damage
 
	// The vehicle is dead!
	if(Health <= 0)
	{
		if ( Controller != None )
		{
			OldDriver = Driver;
			KDriverLeave(True); // Get the player out (forced)
			//Let the driver take a lot of damage
			OldDriver.TakeDamage(120, instigatedBy, hitlocation, momentum, damageType);
		}
		Destroy(); // Destroy the vehicle itself (see Destroyed)
	}
	KAddImpulse(momentum, hitlocation);
}