Gah - a solution with more questions. – EntropicLqd

Legacy:Vehicles Pre2004/TakeDamage

From Unreal Wiki, The Unreal Engine Documentation Site
< Legacy:Vehicles Pre2004
Revision as of 06:49, 17 November 2007 by Dyn-62-56-58-176.dslaccess.co.uk (Talk) (Moved)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Don't kill the driver![edit]

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);
}