I'm a doctor, not a mechanic

Difference between revisions of "UE2:TeamVehicleFactory"

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
m
m (reset function is unnecessary (modified by author))
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Infobox class
+
__TOC__
| class  = TeamVehicleFactory
+
| custom  = yes
+
| parent1 = Actor
+
| parent2 = SVehicleFactory
+
}}
+
 
+
 
+
 
This custom actor really duplicates much of the functionality of the ONSVehicleFactory subclasses, but the big feature is that nearly any vehicle class can be spawned.  Although this actor cannot display the selected vehicle class in the editor, it does offer added controls that mappers for VCTF or other vehicle gametypes might want.
 
This custom actor really duplicates much of the functionality of the ONSVehicleFactory subclasses, but the big feature is that nearly any vehicle class can be spawned.  Although this actor cannot display the selected vehicle class in the editor, it does offer added controls that mappers for VCTF or other vehicle gametypes might want.
  
Line 49: Line 42:
  
 
==Code==
 
==Code==
 
+
{{Infobox class
<div class="hidden-block"><span class="hint"><uscript></span><div class="hidden">//==================================================================================
+
| class   = TeamVehicleFactory
 +
| custom  = yes
 +
| parent1 = SVehicleFactory
 +
| parent2 = Actor
 +
}}
 +
<uscript>
 +
//==================================================================================
 
// TeamVehicleFactory.
 
// TeamVehicleFactory.
 
// Spawn any Vehicle or Turret, set Team, pre & post spawn Events, timing, and more.
 
// Spawn any Vehicle or Turret, set Team, pre & post spawn Events, timing, and more.
Line 56: Line 55:
 
//==================================================================================
 
//==================================================================================
 
class TeamVehicleFactory extends SVehicleFactory
 
class TeamVehicleFactory extends SVehicleFactory
placeable;
+
        placeable;
 
+
var() int TeamNum ; // 0= red, 1= blue, 255= neutral / none
+
var()     int       TeamNum;           // 0= red, 1= blue, 255= neutral / none
var() bool bPlayerControl ; // Only player instigators can trigger
+
var()     bool     bPlayerControl;     // Only player instigators can trigger
 
+
var() bool bAutoSpawn ; // Will spawn at regular intervals
+
var()     bool     bAutoSpawn;         // Will spawn at regular intervals
var() int RespawnTime ; // Interval to wait before AutoSpawning
+
var()     int       RespawnTime;       // Interval to wait before AutoSpawning
 
+
var bool bWaiting ; // About to spawn
+
var       bool     bWaiting;           // About to spawn
var int FactoryTime ; // Time last spawn
+
var       int       FactoryTime;       // Time last spawn
 
+
var() name PreSpawnEvent ; // Event to trigger before spawn
+
var()     name     PreSpawnEvent;     // Event to trigger before spawn
var() int PreSpawnTime ; // Time before spawn to trigger event
+
var()     int       PreSpawnTime;       // Time before spawn to trigger event
var bool bPreSpawn ; // Should trigger PreSpawnEvent next
+
var       bool     bPreSpawn;                       // Should trigger PreSpawnEvent next
var() name SpawnEvent ; // Event to trigger after spawn
+
var()     name     SpawnEvent;         // Event to trigger after spawn
 
+
var() bool bCrushable ; // Allow spawning over colliding actors
+
var()     bool     bCrushable;         // Allow spawning over colliding actors
var() int RetrySpawnTime ; // Interval to wait if bBlocked
+
var()     int       RetrySpawnTime;     // Interval to wait if bBlocked
 
+
var() bool bRandomFlip ; // Neutral vehicles may face backwards
+
var()     bool     bRandomFlip;       // Neutral vehicles may face backwards
 +
 +
var()    bool      bRandomSpawn;      // Spawn random vehicle class
  
var() bool bRandomSpawn ; // Spawn random vehicle class
 
 
struct SpawnedVehicle
 
struct SpawnedVehicle
 
{
 
{
var() class<Vehicle> SpawnVehicle; // Selected random vehicle class
+
    var() class<Vehicle> SpawnVehicle; // Selected random vehicle class
 
};
 
};
var() array<SpawnedVehicle> RandomVehicles ; // List for random vehicle spawn
+
var()     array<SpawnedVehicle>     RandomVehicles;   // List for random vehicle spawn
 
+
 
+
 
simulated function PostBeginPlay()
 
simulated function PostBeginPlay()
 
{
 
{
Super.PostBeginPlay();
+
    Super.PostBeginPlay();
 
+
if ( bAutoSpawn )
+
    if ( bAutoSpawn )
bWaiting = true;
+
          bWaiting = true;
bPreSpawn = true;
+
          bPreSpawn = true;
if ( RespawnTime > 0 )
+
          if ( RespawnTime > 0 )
FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
+
              FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
else
+
          else
FactoryTime = Level.TimeSeconds - PreSpawnTime;
+
              FactoryTime = Level.TimeSeconds - PreSpawnTime;
 
}
 
}
 
+
 
simulated event Trigger( Actor Other, Pawn EventInstigator )
 
simulated event Trigger( Actor Other, Pawn EventInstigator )
 
{
 
{
if ( bAutoSpawn )
+
    if ( bAutoSpawn )
// bAutoSpawn overrides Trigger
+
          // bAutoSpawn overrides Trigger
return;
+
          return;
 
+
if ( !EventInstigator.IsA('UnrealPawn') && bPlayerControl )
+
    if ( !EventInstigator.IsA('UnrealPawn') && bPlayerControl )
return;
+
          return;
 
+
if ( VehicleCount >= MaxVehicleCount )
+
    if ( VehicleCount >= MaxVehicleCount )
return;
+
          return;
 
+
 
+
if ( VehicleClass == None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
+
    if ( VehicleClass == None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
{
+
    {
Log("TeamVehicleFactory:"@self@"has no VehicleClass");
+
          Log("TeamVehicleFactory:"@self@"has no VehicleClass");
return;
+
          return;
}
+
    }
 
+
bWaiting = true;
+
    bWaiting = true;
bPreSpawn = true;
+
    bPreSpawn = true;
if ( RespawnTime > 0 )
+
    if ( RespawnTime > 0 )
FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
+
          FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
else
+
    else
FactoryTime = Level.TimeSeconds - PreSpawnTime;
+
          FactoryTime = Level.TimeSeconds - PreSpawnTime;
 
}
 
}
 
+
 
simulated function SpawnItNow()
 
simulated function SpawnItNow()
 
{
 
{
local Vehicle CreatedVehicle;
+
    local Vehicle         CreatedVehicle;
local bool bBlocked;
+
    local bool           bBlocked;
local Pawn P;
+
    local Pawn             P;
local float SV;
+
    local float         SV;
 +
 +
    bBlocked = false;
 +
 +
    if ( VehicleClass != None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
 +
    {
 +
          if ( bRandomSpawn && RandomVehicles.length > 0 )
 +
              VehicleClass = RandomVehicles[ int( FRand() * RandomVehicles.length ) ].SpawnVehicle;
 +
          foreach CollidingActors(class'Pawn', P, VehicleClass.default.CollisionRadius * 1.33)
 +
              bBlocked = true;
 +
    }
 +
    else
 +
    {
 +
          Log("TeamVehicleFactory:"@self@"has no VehicleClass");
 +
          return;
 +
    }
 +
 +
    if ( bBlocked && !bCrushable )
 +
    {
 +
          bWaiting = true;
 +
          bPreSpawn = true;
 +
          if ( RespawnTime > 0 )
 +
              FactoryTime = Level.TimeSeconds - RespawnTime + RetrySpawnTime + PreSpawnTime;
 +
          else
 +
              FactoryTime = Level.TimeSeconds - RetrySpawnTime + PreSpawnTime;
 +
          return;
 +
    }
 +
    else
 +
    {
 +
          if ( TeamNum == 255 )
 +
          {
 +
              if ( bRandomFlip && Rand(2) == 1 )
 +
                    CreatedVehicle = spawn(VehicleClass, , , Location, Rotation + rot(0,32768,0));
 +
              else
 +
              CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
 +
                   
 +
              // Unlock neutral vehicles
 +
              CreatedVehicle.bTeamLocked = false;
 +
          }
 +
          else
 +
          CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
  
bBlocked = false;
+
          if ( CreatedVehicle != None )
 
+
          {
if ( VehicleClass != None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
+
              VehicleCount++;
{
+
              CreatedVehicle.Event = Tag;
if ( bRandomSpawn && RandomVehicles.length > 0 )
+
              CreatedVehicle.ParentFactory = self;
VehicleClass = RandomVehicles[ int( FRand() * RandomVehicles.length ) ].SpawnVehicle;
+
              CreatedVehicle.SetTeamNum(TeamNum);
    foreach CollidingActors(class'Pawn', P, VehicleClass.default.CollisionRadius * 1.33)
+
              TriggerEvent(SpawnEvent, self, None);
bBlocked = true;
+
          }
}
+
    }
else
+
{
+
Log("TeamVehicleFactory:"@self@"has no VehicleClass");
+
return;
+
}
+
 
+
    if ( bBlocked && !bCrushable )
+
{
+
bWaiting = true;
+
bPreSpawn = true;
+
if ( RespawnTime > 0 )
+
FactoryTime = Level.TimeSeconds - RespawnTime + RetrySpawnTime + PreSpawnTime;
+
else
+
FactoryTime = Level.TimeSeconds - RetrySpawnTime + PreSpawnTime;
+
return;
+
}
+
    else
+
{
+
if ( TeamNum == 255 )
+
 
+
{
+
if ( bRandomFlip && Rand(2) == 1 )
+
CreatedVehicle = spawn(VehicleClass, , , Location, Rotation + rot(0,32768,0));
+
else
+
CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
+
// Unlock neutral vehicles
+
CreatedVehicle.bTeamLocked = false;
+
}
+
else
+
CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
+
if ( CreatedVehicle != None )
+
{
+
VehicleCount++;
+
CreatedVehicle.Event = Tag;
+
CreatedVehicle.ParentFactory = self;
+
CreatedVehicle.SetTeamNum(TeamNum);
+
TriggerEvent(SpawnEvent, self, None);
+
}
+
}
+
 
}
 
}
 
+
 
event VehicleDestroyed(Vehicle V)
 
event VehicleDestroyed(Vehicle V)
 
{
 
{
Super.VehicleDestroyed(V);
+
    Super.VehicleDestroyed(V);
 
+
if ( bAutoSpawn )
+
    if ( bAutoSpawn )
{
+
    {
bWaiting = true;
+
          bWaiting = true;
bPreSpawn = true;
+
          bPreSpawn = true;
FactoryTime = Level.TimeSeconds;
+
          FactoryTime = Level.TimeSeconds;
}
+
    }
 
}
 
}
 
+
 
simulated function Tick(float DeltaTime)
 
simulated function Tick(float DeltaTime)
 
{
 
{
if ( bWaiting )
+
    if ( bWaiting )
{
+
    {
if ( Level.TimeSeconds - FactoryTime < RespawnTime - PreSpawnTime )
+
          if ( Level.TimeSeconds - FactoryTime < RespawnTime - PreSpawnTime )
return;
+
              return;
 
+
if ( VehicleCount < MaxVehicleCount )
+
          if ( VehicleCount < MaxVehicleCount )
if ( !bPreSpawn )
+
                    if ( !bPreSpawn )
{
+
                    {
if ( Level.TimeSeconds - FactoryTime >= RespawnTime )
+
                        if ( Level.TimeSeconds - FactoryTime >= RespawnTime )
{
+
                        {
bWaiting = false;
+
                              bWaiting = false;
FactoryTime = Level.TimeSeconds;
+
                              FactoryTime = Level.TimeSeconds;
SpawnItNow();
+
                              SpawnItNow();
}
+
                        }
}
+
                    }
else
+
                    else
{
+
                    {
bPreSpawn = false;
+
                        bPreSpawn = false;
TriggerEvent(PreSpawnEvent, self, None);
+
                        TriggerEvent(PreSpawnEvent, self, None);
}
+
                    }
}
+
    }
}
+
 
+
simulated function Reset()
+
{
+
    local Vehicle V;
+
 
+
    if ( VehicleCount > 0 )
+
        forEach AllActors ( class 'Vehicle', V )
+
            if ( V.ParentFactory == self )
+
                V.Destroy();
+
 
+
    Super.Reset();
+
 
}
 
}
</uscript></div></div>
+
</uscript>
  
 
==External Links==
 
==External Links==
Line 236: Line 225:
  
 
==Related Topics==
 
==Related Topics==
 +
* [[Legacy:Third-Party Components|Third-Party Components]]
 
* [[Legacy:Mapping For AS (UT2004)|Mapping for AS (UT2004)]]
 
* [[Legacy:Mapping For AS (UT2004)|Mapping for AS (UT2004)]]
 
* [[Legacy:Mapping For ONS|Mapping for ONS]]
 
* [[Legacy:Mapping For ONS|Mapping for ONS]]

Latest revision as of 08:34, 10 May 2008

This custom actor really duplicates much of the functionality of the ONSVehicleFactory subclasses, but the big feature is that nearly any vehicle class can be spawned. Although this actor cannot display the selected vehicle class in the editor, it does offer added controls that mappers for VCTF or other vehicle gametypes might want.

Features[edit]

  • The ability to spawn random vehicles from a list of vehicle classes
  • The ability to spawn nearly any vehicle class in gametypes that allow vehicles
  • The ability to trigger PreSpawn and (Post)Spawn events
  • The option to allow the vehicle to spawn over and crush other actors
  • The option to use this as either a triggerable or an automatic (timed) vehicle factory.
  • Greater control over spawn timing

Notes[edit]

  • If you use a TeamVehicleFactory "as is" in your custom map, please credit me in the readme file of the map. (SuperApe)
  • You have to supply spawning effects and sounds, via ScriptedTrigger, Emitter and the like. This is meant to allow flexibilty in the ways you want vehicles to spawn. An example VCTF map posted on this UP Forum thread gives my suggestion for spawning particles and sound. (It appears similar to pickup spawning.)
  • With bAutoSpawn on and without a PreSpawnTime of around 2 seconds, you run the risk of spawning a vehicle before headlights can be properly spawned at map start. Subsequent vehicles after map start will spawn headlights normally.
  • Turrets that are spawned automatically get an AIController. They are auto turrets; firing at enemies, or if set to neutral (team 255), firing at any non-neutral controlled pawn it detects.
  • The AS Spacefighters are spawned with a minimum velocity that makes them impractical to use. However, a custom launcher for these is easy to make with a TryToDrive() function.
  • This has a slightly larger bBlocked check radius than ONSVehicleFactory. ( 1.33 : 1.25 )

Properties[edit]

Main[edit]

int TeamNum 
Team Number to be set on spawn. 0= red, 1= blue, 255= neutral / none
bool bPlayerControl 
Only player instigators can trigger.
bool bAutoSpawn 
Will spawn at regular intervals. The triggering ability is disabled.
int RespawnTime 
Interval to wait before AutoSpawning.
name PreSpawnEvent 
Event to trigger before spawn.
int PreSpawnTime 
Time before spawn to trigger event. Will begin event this many seconds before the factory is set to AutoSpawn.
name SpawnEvent 
Event to trigger after spawn. A post spawn event.
bool bCrushable 
Allow spawning over colliding actors. Note: Turrets will normally spawn in collision with other actors, spawned vehicles will generally move out of the way.
int RetrySpawnTime 
Interval to wait if bBlocked.
bool bRandomFlip 
Neutral vehicles may face backwards.
bool bRandomSpawn 
Will spawn random vehicle class.
struct class<Vehicle> SpawnedVehicle 
Selected random vehicle class.
array<SpawnedVehicle> RandomVehicles 
List for random vehicle spawn.

Hidden[edit]

bool bWaiting 
Waiting to spawn.
int FactoryTime 
Time last spawn. (in Level.TimeSeconds)
bool bPreSpawn 
Should trigger PreSpawnEvent next.

Code[edit]

UE2 Actor >> SVehicleFactory >> TeamVehicleFactory (custom)
//==================================================================================
// TeamVehicleFactory.
// Spawn any Vehicle or Turret, set Team, pre & post spawn Events, timing, and more.
// Glenn 'SuperApe' Storm -- June 2004 -- Updated: July 2005
//==================================================================================
class TeamVehicleFactory extends SVehicleFactory
        placeable;
 
var()     int       TeamNum;            // 0= red, 1= blue, 255= neutral / none
var()     bool      bPlayerControl;     // Only player instigators can trigger
 
var()     bool      bAutoSpawn;         // Will spawn at regular intervals
var()     int       RespawnTime;        // Interval to wait before AutoSpawning
 
var       bool      bWaiting;           // About to spawn
var       int       FactoryTime;        // Time last spawn
 
var()     name      PreSpawnEvent;      // Event to trigger before spawn
var()     int       PreSpawnTime;       // Time before spawn to trigger event
var       bool      bPreSpawn;                        // Should trigger PreSpawnEvent next
var()     name      SpawnEvent;         // Event to trigger after spawn
 
var()     bool      bCrushable;         // Allow spawning over colliding actors
var()     int       RetrySpawnTime;     // Interval to wait if bBlocked
 
var()     bool      bRandomFlip;        // Neutral vehicles may face backwards
 
var()     bool      bRandomSpawn;       // Spawn random vehicle class
 
struct SpawnedVehicle
{
     var() class<Vehicle> SpawnVehicle; // Selected random vehicle class
};
var()     array<SpawnedVehicle>     RandomVehicles;   // List for random vehicle spawn
 
 
simulated function PostBeginPlay()
{
     Super.PostBeginPlay();
 
     if ( bAutoSpawn )
          bWaiting = true;
          bPreSpawn = true;
          if ( RespawnTime > 0 )
               FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
          else
               FactoryTime = Level.TimeSeconds - PreSpawnTime;
}
 
simulated event Trigger( Actor Other, Pawn EventInstigator )
{
     if ( bAutoSpawn )
          // bAutoSpawn overrides Trigger
          return;
 
     if ( !EventInstigator.IsA('UnrealPawn') && bPlayerControl )
          return;
 
     if ( VehicleCount >= MaxVehicleCount )
          return;
 
 
     if ( VehicleClass == None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
     {
          Log("TeamVehicleFactory:"@self@"has no VehicleClass");
          return;
     }
 
     bWaiting = true;
     bPreSpawn = true;
     if ( RespawnTime > 0 )
          FactoryTime = Level.TimeSeconds - RespawnTime + PreSpawnTime;
     else
          FactoryTime = Level.TimeSeconds - PreSpawnTime;
}
 
simulated function SpawnItNow()
{
     local  Vehicle         CreatedVehicle;
     local  bool           bBlocked;
     local  Pawn              P;
     local  float          SV;
 
     bBlocked = false;
 
     if ( VehicleClass != None || ( bRandomSpawn && RandomVehicles.length > 0 ) )
     {
          if ( bRandomSpawn && RandomVehicles.length > 0 )
               VehicleClass = RandomVehicles[ int( FRand() * RandomVehicles.length ) ].SpawnVehicle;
          foreach CollidingActors(class'Pawn', P, VehicleClass.default.CollisionRadius * 1.33)
               bBlocked = true;
     }
     else
     {
          Log("TeamVehicleFactory:"@self@"has no VehicleClass");
          return;
     }
 
     if ( bBlocked && !bCrushable )
     {
          bWaiting = true;
          bPreSpawn = true;
          if ( RespawnTime > 0 )
               FactoryTime = Level.TimeSeconds - RespawnTime + RetrySpawnTime + PreSpawnTime;
          else
               FactoryTime = Level.TimeSeconds - RetrySpawnTime + PreSpawnTime;
          return;
     }
     else
     {
          if ( TeamNum == 255 )
          {
               if ( bRandomFlip && Rand(2) == 1 )
                    CreatedVehicle = spawn(VehicleClass, , , Location, Rotation + rot(0,32768,0));
               else
               CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
 
               // Unlock neutral vehicles
               CreatedVehicle.bTeamLocked = false;
          }
          else
          CreatedVehicle = spawn(VehicleClass, , , Location, Rotation);
 
          if ( CreatedVehicle != None )
          {
               VehicleCount++;
               CreatedVehicle.Event = Tag;
               CreatedVehicle.ParentFactory = self;
               CreatedVehicle.SetTeamNum(TeamNum);
               TriggerEvent(SpawnEvent, self, None);
          }
     }
}
 
event VehicleDestroyed(Vehicle V)
{
     Super.VehicleDestroyed(V);
 
     if ( bAutoSpawn )
     {
          bWaiting = true;
          bPreSpawn = true;
          FactoryTime = Level.TimeSeconds;
     }
}
 
simulated function Tick(float DeltaTime)
{
     if ( bWaiting )
     {
          if ( Level.TimeSeconds - FactoryTime < RespawnTime - PreSpawnTime )
               return;
 
          if ( VehicleCount < MaxVehicleCount )
                    if ( !bPreSpawn )
                    {
                         if ( Level.TimeSeconds - FactoryTime >= RespawnTime )
                         {
                              bWaiting = false;
                              FactoryTime = Level.TimeSeconds;
                              SpawnItNow();
                         }
                    }
                    else
                    {
                         bPreSpawn = false;
                         TriggerEvent(PreSpawnEvent, self, None);
                    }
     }
}

External Links[edit]

  • Mapping for VCTF – A thread on UnrealPlayground that includes a test map using this actor and suggested spawn EFX.

Related Topics[edit]