| Home Page | Recent Changes

VitalOverdose/Ejection Trigger

UT2004 :: Actor >> Trigger >> Ejection Trigger(Package: custom)

OverView

This custom Trigger actor is designed quite simply to detect any vehicles that come within a cetain distance and if a driver is present ..eject the driver.//

Basic Concept

This is the basic concept for the full script;-

Function Touch()

(Custom).

  • is it a vehicle? & does it have a driver?
    • (true) Use the valid ref gained through touch() to set its property bejectdriver to true.
 
 
Class Ejection_Trigger extends Trigger
Placeable;

function Touch( Actor Other)
{
if ((other.isa('vehicle')) && (Vehicle(other).driver != None)) 
   Vehicle(other).bEjectDriver = True; a start and 
}
 

While this will work fine its not very practical for placement in a map as there is no way to see it for a start and definatley no control over it. So in this script were going to add some 'cosmetic' effects to make someone actually want to use it in a map.

This features;-

  • Random AmbiantFx as a visual marker.
  • Random ContactFX for this actor as a result of a valid contact from a vac.
  • EjectScale Muliplyer.
  • Random tagfx for the ejected driver.
  • Vehicle can be damaged as a result of coming in contact with this actor
  • The driver can be dealt pain as well as the vehicle

Global Variables

 VecDamag              = Optional How Much Damage the vehicle should recive on contact.
 DriverDamage          = OptionalHow Much Diver the vehicle should recive on contact.
 EjectSpeedmultiplyer  = Optional Multiplyer to apply to the vehicles ejectspeed on contact.
 EjectSoundFx          = Optional eject fx for The Vehicle that causes the contact.
 ValidContactSoundFx   = Optional sound fx for The Vehicle that causes the contact.
 DriverDamageType      = The damage type to apply to the driver when giveing him damage.
 VecDamageType         = The damage type to apply to the vehicle when causing it damage.
 DriverTagFxPool       = Optional Dynamic array for holding random fx for Tagging the driver on eject.
 AmbiantFxPool;        = Optional Dynamic array for holding random fx for ambiantFX for this actor 
 ValidContactFxPool;   = Optional Dynamic array for holding random fx for when a valid contact is caused
Var () Int                            VecDamage;             // Mapper can set in unrealEd.
Var () Int                            DriverDamage;          // Mapper can set in unrealEd.
Var () Float                          EjectSpeedmultiplyer;  // Mapper can set in unrealEd.
Var () Sound                          EjectSoundFx;          // Mapper can set in unrealEd.
Var () Sound                          ValidContactSoundFx;   // Mapper can set in unrealEd.
Var () Class< Damagetype >            DriverDamageType;      // Mapper can set in unrealEd.
Var () Class< DamageType >            VecDamageType;         // Mapper can set in unrealEd.
Var () Array< Class< Emitter > >      DriverTagFxPool;       // Mapper can set in unrealEd.
Var () Array< Class< Emitter > >      AmbiantFxPool;         // Mapper can set in unrealEd.
Var () Array< Class< Emitter > >      ValidContactFxPool;    // Mapper can set in unrealEd.

Function PostBeginPlay()

(Generic:called by system)

Here the postbeginplay() function is overwritten to include a single argument that checks to see if there are any emitters stored in the dynamic array AmbiantFxPool by asking if its length (how many used slots/elements) != 0.

Function PostBeginPlay()
{
if (AmbiantFxPool.length !=0 )
    SpawnFx(self,AmbiantFxPool);
}

Function Touch()

(generic:called when touched)

The touch function is over written so that when this actor is touched by another actor is fir checked to see if it is a vehicle...if it is a vehicle then we can get access to the properties preasent in in the vehicle class by typecasting other (which we know is a onsvec) to ONSVehicle. Using this new Typecasted ref to the ons vehicle check to see if there is a driver present to eject. If there isnt then this actor goes back to sleep and waits to be touched again. If there is a driver that can be ejected then the function EjectandTag is called and a vehcile typecasted ref to what touched us.

function Touch( Actor Other)
{
 if ( (Other.IsA('onsVehicle')) && (onsVehicle(Other).Driver != None) )
    {
     if (ValidContactFxPool != None) 
        spawnFX(self,ValidContactFxPool);
     
     EjectAndTag( OnsVehicle(Other));
     if (ValidContactSoundFx!=None)
         Playsound(ValidContactSoundFx);
    }
 Super.touch(other)
}

Function EjectAndTag()

(custom:called from touch()).

in this function the new ejection speed for the driver is calculated and then passed back to the vehicle. Then a copy of the Drivers Valid Ref is taken (as once ejected hes no longer the driver and we would lose and valid to it) brfore the driver is finally ejected. All the 'cosmetic' fx such as the sound and the tagging of the driver are done in PostEject(), as this provides a convienient place for someone to add code at a later date.

Function EjectAndTag( OnsVehicle Vec )
{
 Local Actor       EjectedDriver;
 
 Vec.EjectMomentum  *= Ejectmultiplyer;
 EjectedDriver       = Vec.Driver;
 Vec.EjectDriver();
 If ( EjectedDriver != None )
      PostEject(onsvehicle TheVec,pawn EjectedDriver,emitter SpawnedTag)
}

Function SpawnFx()

(Custom:called from EjectAndTag()).

There are 3 spawn functions in this actor;-

  • ambiant fx ;- Is really nothing more than a visual marker to where the Trigger eject is when playing.
  • Contact fx ;- Optional fx to spawn as a visual indication of a valid contact whith a vec.
  • Tag FX ;- Optional emitter that gets hard attached to the driver when being ejected to make a trail effect.

So for the sake of efficiancy the if a SpawnFx function that is designed to do the job of all 3. To run this function you have to pass it a dynamic array of emitters and an actor to attach it to. It then randomly selects an emitter from the 'spawnPool' spawns, then hard attches it to whatever is in the property ActorPos. As the ambiant aand contact get attached to the Trigger Eject but for the tagFX its the driver that wants tagging.

Note: The is no qulifying of the length of the array at this point because its more efficiant to check each individual spawnpool before the actual call to spawn as then we dont have to pass an entire array of emitters to another function to find out.

Function SpawnFx (actor ActorPos,array< class< emiktter> > SpawnPool)
{
 Local Emitter           SpawnedTagFX;
 Local int               PickedNumb;
 Local Class< Emitter >  PickedTagFxClass;

 PickedNumb       = Rand(SpawnPool.Length-1)+1;
 PickedTagFxClass = SpawnPool[PickedNumb];
 SpawnedTagFX     = Spawn(PickedTagFxClass,ActorPos,,ActorPos.Location ,ActorPos.Rotation );
 if ( SpawnedTag != none )
      SpawnedTagFX.setbase(ActorPos);
}

Function PostEject()

(Custom:Called by EjectAndTag())

Here all of the cosmetic fx for this actor take place after the driver has finally been ejected from the vehicle.

The logic;

  • (Does the DriverTagFxPool array contain some emitters?)
    • (True): Call function SpawnFx and pass to it the ValidRef of the ejecteddriver & the contents of the DriverTagFxPool.
  • (is there something in the property EjectSoundFx?)
    • (true): get the vehicle to play the 'EjectSoundFx'
  • (is the property DriverDamage greater than 0?)
    • (True): Damage The ejected driver, Cause DriverDamage of damage.
  • (is the property VecDamage greater than 0?)
    • (True): Damage ValidVehicle and Cause VecDamage worth of damage.
Simulated function PostEject(onsvehicle TheVec,pawn EjectedDriver,emitter SpawnedTag)
{
 if ( DriverTagFxPool.length != 0)
      spawnfx(EjectedDriver,DriverTagFxPool)
 
 If ( EjectSoundFx != none )
      TheVec.PlaySound( EjectSoundFx );
 
 if ( DriverDamage > 1)
      EjectedDriver.TakeDamage(DriverDamage , Instigator , EjectedDriver.Location , vect(0,0,10000),DriverDamagetype ) ;
 
 if ( VecDamage > 1 )
      TheVec.TakeDamage(VecDamage , Instigator , Thevec.Location , vect(0,0,10000),VecDamagetype ) ;
}

The Full Script

Here is the complete Script wi all the cosmetic fx added to it;-

 /////////////////////////////////////////////////////////////////////
// SFX_Ejecting by VitalOverdose
// Feb 2006.
// Http://www.vitaloverdose.com
///////////////////////////////////////////////////////////////////////
class SFX_Ejecting extends Trigger
Placeable;

Var () Int                            VecDamage;             // Mapper can set in unrealEd.
Var () Int                            DriverDamage;          // Mapper can set in unrealEd.
Var () Float                          EjectSpeedmultiplyer;  // Mapper can set in unrealEd.
Var () Sound                          EjectSoundFx;          // Mapper can set in unrealEd.
Var () Sound                          ValidContactSoundFx;   // Mapper can set in unrealEd.
Var () Class< Damagetype >            DriverDamageType;      // Mapper can set in unrealEd.
Var () Class< DamageType >            VecDamageType;         // Mapper can set in unrealEd.
Var () Array< Class< Emitter > >      DriverTagFxPool;       // Mapper can set in unrealEd.
Var () Array< Class< Emitter > >      AmbiantFxPool;         // Mapper can set in unrealEd.
Var () Array< Class< Emitter > >      ValidContactFxPool;    // Mapper can set in unrealEd.

Function PostBeginPlay()
{
if (AmbiantFxPool.length !=0 )
    SpawnFx(self,AmbiantFxPool);
}

Function Touch( Actor Other)
{
 if ( (Other.IsA('onsVehicle')) && (onsVehicle(Other).Driver != None) )
    {
     if (ValidContactFxPool != None)
         spawnFX(self,ValidContactFxPool);
     EjectAndTag( OnsVehicle(Other));

     If (ValidContactSoundFx!=None)
         Playsound(ValidContactSoundFx);
    }
 Super.touch(other)
}

Function EjectAndTag( OnsVehicle Vec )
{
 Local Actor       EjectedDriver;

 Vec.EjectMomentum *= Ejectmultiplyer;
 EjectedDriver      = Vec.Driver;
 Vec.EjectDriver();
 if ( EjectedDriver != None )
      PostEject(onsvehicle TheVec,pawn EjectedDriver,emitter SpawnedTag)
}

Function SpawnFx (actor ActorPos,array< class< emiktter> > SpawnPool)
{
 Local Emitter           SpawnedTagFX;
 Local int               PickedNumb;
 Local Class< Emitter >  PickedTagFxClass;

 PickedNumb       = Rand(SpawnPool.Length-1)+1;
 PickedTagFxClass = SpawnPool[PickedNumb];
 SpawnedTagFX     = Spawn(PickedTagFxClass,ActorPos,,ActorPos.Location ,ActorPos.Rotation );
 if ( SpawnedTag != none )
      SpawnedTagFX.setbase(ActorPos);
}

Simulated function PostEject(onsvehicle TheVec,pawn EjectedDriver,emitter SpawnedTag)
{
 if ( DriverTagFxPool.length != 0)
      spawnfx(EjectedDriver,DriverTagFxPool)

 If ( EjectSoundFx != none )
      TheVec.PlaySound( EjectSoundFx );

 if ( DriverDamage > 1)
      EjectedDriver.TakeDamage(DriverDamage , Instigator , EjectedDriver.Location , vect(0,0,10000),DriverDamagetype ) ;

 if ( VecDamage > 1 )
      TheVec.TakeDamage(VecDamage , Instigator , Thevec.Location , vect(0,0,10000),VecDamagetype ) ;
}
 

Related

VitalOverdose/VecBooster

VitalOverdose/VehicleTeleporter

VitalOverdose/RandomRelocator

discusion


Category Custom Class

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In