As seen in DM-Rifts by 'bigpilague'
//=============================================================================
// Will spawn 'prototype' actors. Set Advanced/bDirectional to true and rotate to
// aim them.
//=============================================================================
class Spawner extends Triggers;
var() int MaxSpawns; // this many, -1 for infinite
var() int SpawnsPerTrigger; // how many to spawn each time triggered, -1 for inifinite
var() class<actor> prototype; // the template class
var() enum _SpawnerType
{
Spawner_Once, // one time, no more, no retrigger
Spawner_Triggered, // fire 'SpawnsPerTrigger' items off at 'interval'
Spawner_WhileTriggered // same as Triggered, but stops when untriggered
} SpawnerType;
var () float interval; // if more than one to spawn, # seconds between them
var bool bSpawnedAlready;
var int TotalSpawnsToGo;
var int SpawnsToGoThisTime;
var actor theOther;
var pawn theEventInstigator;
function BeginPlay()
{
bSpawnedAlready = false;
TotalSpawnsToGo = MaxSpawns;
SpawnsToGoThisTime = SpawnsPerTrigger;
if (interval < 0.1)interval = 0.1; // don't flood it
Super.BeginPlay();
}
function Timer ()
{
// would be nice to disable this routine when untriggered or empty
if (TotalSpawnsToGo != 0 && SpawnsToGoThisTime != 0)
{SpawnMeOne();
}
}
function Trigger( actor Other, pawn EventInstigator )
{
local Actor m;
// if there are more left, and if we aren't a one-time thing that's already played..
if (TotalSpawnsToGo != 0 && !(bSpawnedAlready && SpawnerType == Spawner_Once))
{bSpawnedAlready = true;
SpawnsToGoThisTime = SpawnsPerTrigger;
if (SpawnsToGoThisTime > TotalSpawnsToGo)
SpawnsToGoThisTime = TotalSpawnsToGo;
// Fire one off now, set a timer if we need to do more
theOther = Other;
theEventInstigator = EventInstigator;
SpawnMeOne();
if (TotalSpawnsToGo != 0)
{SetTimer(interval, true);
}
}
}
function Untrigger( actor Other, pawn EventInstigator )
{
// would be nice to disable Timer
if (SpawnerType == Spawner_WhileTriggered)SpawnsToGoThisTime = 0;
}
function SpawnMeOne()
{
local Actor m;
if (TotalSpawnsToGo != 0)
{TotalSpawnsToGo--;
SpawnsToGoThisTime--;
m = Spawn (prototype, theEventInstigator, Tag , Location, DesiredRotation);
if (theEventInstigator != None)m.Instigator = theEventInstigator;
else
m.Instigator = Pawn(theOther);
if (Event != '')
m.Tag = Event;
}
}
defaultproperties
{
MaxSpawns =-1;
SpawnsPerTrigger = -1;
SpawnerType = Spawner_WhileTriggered;
interval = 1.0;
}