Airstrike

From Oldunreal-Wiki
Jump to navigation Jump to search
Airstrike Trigger
Topic Coding
Series Chimeric

In this tutorial we're going to see how to create an Airstrike Trigger.

Overview

The goal here is to create a trigger that a player can run up and touch to cause an airstrike, which is basically the creation of a volley of missiles pointed at a specified target. I made a subclass of Trigger and overrode the Touch() function so as to create the missiles, and use the Event/Tag variables to determine our target. This way a level editor could put this trigger in his/her level and set a desired target somewhere else, adding a cool nifty feature specific to that level.

Code

// ===========================================
//  AirstrikeTrigger
// ===========================================

class AirstrikeTrigger expands Trigger;

// Here are some variables to make the trigger easier to
// configure.  MissileType is the class of missile that
// will get spawned, NumOfMissiles is the amount to create,
// Height is how high above we should create them, and offsetDist
// will determine the range of the target they should be
// created in.
var() class MissileType;
var() int NumOfMissiles, Height, OffsetDist;

// Touch() is where all the fun stuff happens.  First we check'''
'''// to see if we have a specified target, otherwise we just default'''
'''// to ourselves.  Then we go about the process of spawning the'''
'''// missile(s).'''
function Touch( actor Other )
{
	local Projectile Missile;
	local vector StartLocation, Offset;
	local rotator AimDirection;
	local int i;
	local Actor a, StrikeTarget;
	
	'''// Just use a foreach to go through all the Actors in the game'''
	'''// to see if one has the matching tag...'''
	foreach AllActors(class'Actor', a)
	{
		if (a.Tag == Event)
        StrikeTarget = a;
	}
	
    // If we didn't find a target, we become the target
    if (StrikeTarget == NONE)
	StrikeTarget = self;
	
    // IsRelevant() is a function in Trigger that will determine
    // if the actor that touched us meets the criteria to trigger
    // us.  So if a level editor configured this trigger to be
    // only triggered by only the blue team or whatever, IsRelevant()
    // would make sure that happens.
    if( IsRelevant( Other ) )
    {
        // We've been successfully touched by the right person (kinky)
        // so lets go about spawning our missiles.
        for (i = 0; i <= NumOfMissiles; i++)
        {
            // Offset is a random vector generated to keep all the missiles
            // from starting in the same place.  VRand() generates a vector
            // in a random direction, and we just multiply this times a
            // random distance determined using the RandRange() function.
            // RandRange() simply generates a random number between a Min
            // and Max.
            Offset = VRand() * RandRange(OffsetDist * 0.5, OffsetDist * 1.5);
			
            // Our start location is simply the target's location plus the
            // desired height and the Offset vector we just generated.
            StartLocation = StrikeTarget.Location + (vect(0,0,1) * Height) + Offset;
			
            // AimDirection is found by subtracting out destination from our
            // starting point, with the destination being the Target's location
            // plus the offset.
            AimDirection = rotator( ((StrikeTarget.Location + Offset) - StartLocation) * 10000);
			
            // Now that we know everything, go ahead an spawn the desired
            // missile.  Note that we set the owner to Other, which is the
            // actor that touched us, so anybody who dies from an airstrike
            // will count as a frag for Other.
            Missile = Spawn(MissileType,Other,,StartLocation, AimDirection);
		}
	}
	
	// Make sure to call the normal trigger code so that we don't break the
	// previous functionality of the trigger.
    Super.Touch(Other);
}

defaultproperties
{
    NumOfMissiles=15
    Height=450
    OffsetDist=500
}

External links

<references />

See also

Chimeric tutorials