RandomCreatureFactory
New features:
-It can be turned on and off by triggers. Make it "bstoppable = true" if you want to turn it off with a trigger;
-Total classes allowed has been lowered from 32 to 16, as nobody will need to spawn that many classes with just one factory. (It's impossible to control how many monsters of each class it'll spawn, however you can use one class more than once to raise its chance of being spawned);
-It has now the ability to call an event after all spawns are over, eliminating the need of trigger counters.
You must attach this factory to the RandomSpawnPoint to get it work properly. If you attach it to regular spawnpoints, all monsters will spawn in "pacifist" state.
//============================================================================= // RandomCreatureFactory. (Originally created by Salty_Pepper. Unsucessfully fixed by Naked_Monster. // Sucessfully fixed by Timmypowergammer later on.) // Spawns random creatures from a list. Also added ability to be switched off // by a trigger (if bStoppable is set True). When finished it will trigger the // FinishedEvent (if specified). Must be used with RandomSpawnPoint. //============================================================================= class RandomCreatureFactory extends CreatureFactory; var() name FinishedEvent; var() class<ScriptedPawn> RandomMonster[16]; var class<ScriptedPawn> MonsterList[16]; var int NumMonsters; function PostBeginPlay() { local int i; local RandomSpawnpoint newspot; Super(keypoint).PostBeginPlay(); numspots = 0; numitems = 0; numMonsters = -1; foreach AllActors( class 'RandomSpawnPoint', newspot, tag ) { if (numspots < 16) { spawnspot[numspots] = newspot; newspot.factory = self; numspots += 1; } } if (itemtag == '') itemtag = 'PlanetMonsterHunt'; //shameless self-promotion ;) for( i=0; i<16; i++ ) If (RandomMonster[i] != None){ //creates new array NumMonsters++; //(avoids accessed Nones) Monsterlist[NumMonsters] = RandomMonster[i]; } NumMonsters++; If (NumMonsters == 0) Log("RandomCreatureFactory has no prototype set"); } State Spawning { function Trigger(actor Other, pawn EventInstigator) { //only if Other is from this factory If (Other.owner == Self) { numitems--; if (numitems < maxitems) StartBuilding(); } else if(Other.owner != self){ if (bStoppable) //if not from this factory, and bStoppable is true. GotoState('Off'); else return; } } function Timer() { local int start; if (numitems < maxitems) { prototype = MonsterList[Rand(NumMonsters)]; //Set New prototype if (prototype == (None)) // return; // //pick a spawn point start = Rand(numspots); if ( !trySpawn(start, numspots) ) trySpawn(0, start); } if (numitems < maxitems) StartBuilding(); } Begin: Disable('UnTouch'); Timer(); } State Off { function Trigger( actor Other, pawn EventInstigator ) { local Actor A; If (Other.owner == Self){ numitems--; return; } Else if(Other.owner != Self) //if not from this factory GotoState('Spawning'); } } State Finished { function Trigger(actor Other, pawn EventInstigator ) { local actor A; local pawn p; local int i; For (p=level.pawnlist;p!=none;p=p.nextpawn) //checks number of monsters left If (p.owner == Self) i++; If (Other.owner == Self) i--; if (i == 0) //triggers FinishedEvent if ( FinishedEvent != '' ) ForEach AllActors( class 'Actor', A, FinishedEvent) A.Trigger(self, EventInstigator); } }
Naked_Monster: For people interested in this script, be warned, there may be unknown flaws in this script.