UnrealShare
Class StochasticTrigger

source: e:\games\UnrealTournament\UnrealShare\Classes\StochasticTrigger.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Triggers
         |
         +--UnrealShare.StochasticTrigger
Direct Known Subclasses:None

class StochasticTrigger
extends Engine.Triggers

//============================================================================= // StochasticTrigger. //=============================================================================
Variables
 name Events[6]
           What events to call (must be at least one event)
 bool bIsActive
           This trigger dispacher is activated/deactivated
 float maxReCheckTime
           Try to re-trigger the event after (max amount)
 float minReCheckTime
           Try to re-trigger the event after (min amount)
 int numEvents
           The number of events available
 float reTriggerTime
           This trigger dispacher is activated/deactivated
 Actor triggerInstigator
           Who enabled this actor to dispach?
 float triggerProbability
           The chance of the event occuring effect playing


Function Summary
 void BeginPlay()
 void Timer()
 void Trigger(Actor Other, Pawn EventInstigator)
 void UnTrigger(Actor Other, Pawn EventInstigator)



Source Code


00001	//=============================================================================
00002	// StochasticTrigger.
00003	//=============================================================================
00004	class StochasticTrigger extends Triggers;
00005	
00006	// Works like a DynamicAmbientSound, only events are called instead of
00007	// sounds. M
00008	
00009	var() name   Events[6];      		// What events to call (must be at least one event)
00010	var() float  triggerProbability;	// The chance of the event occuring effect playing
00011	var() float  minReCheckTime;   	// Try to re-trigger the event after (min amount)
00012	var() float  	maxReCheckTime;   	// Try to re-trigger the event after (max amount)
00013	var   bool	bIsActive;			// This trigger dispacher is activated/deactivated
00014	var   float  	reTriggerTime;
00015	var   int    	numEvents;			// The number of events available
00016	var   actor  triggerInstigator;   	// Who enabled this actor to dispach?
00017	
00018	function BeginPlay () 
00019	{
00020		local int i;
00021		
00022		// Calculate how many events the user specified
00023		numEvents=6;
00024		for (i=0; i<6; i++) {
00025			if (Events[i] == '') {
00026				numEvents=i;
00027				break;
00028			}
00029		}
00030	
00031		reTriggerTime = (maxReCheckTime-minReCheckTime)*FRand() + minReCheckTime;
00032		SetTimer(reTriggerTime, False);
00033	}
00034	
00035	state() TriggeredActive
00036	{
00037		function Trigger( actor Other, pawn EventInstigator )
00038		{
00039			// StochasticTrigger is active
00040			if ( triggerInstigator == None )
00041				triggerInstigator = EventInstigator;
00042			else
00043				triggerInstigator = Other;
00044			Instigator = EventInstigator;
00045			bIsActive = true;
00046		}
00047	
00048		function UnTrigger( actor Other, pawn EventInstigator )
00049		{
00050			// StochasticTrigger is inactive
00051			if ( triggerInstigator == None )
00052				triggerInstigator = EventInstigator;
00053			else
00054				triggerInstigator = Other;
00055			Instigator = EventInstigator;
00056			bIsActive = false;
00057		}
00058	Begin:
00059		bIsActive = false; 		// initially the trigger dispacher is inactive
00060	}
00061	
00062	state() AlwaysActive
00063	{
00064	Begin:
00065		bIsActive = true;
00066	}
00067	
00068	function Timer () 
00069	{
00070		local int 	i;
00071		local actor 	A;
00072	
00073		if (FRand() <= triggerProbability && bIsActive == true) 
00074		{
00075			// Trigger an event
00076			// Which event should be initiated?
00077			i = Rand(numEvents);
00078	
00079			// Broadcast the Trigger message to all matching actors.
00080			if( Events[i] != '' )
00081				foreach AllActors( class 'Actor', A, Events[i] )
00082					A.Trigger( triggerInstigator, Instigator );
00083		}
00084	
00085		reTriggerTime = (maxReCheckTime-minReCheckTime)*FRand() + minReCheckTime;
00086		SetTimer(reTriggerTime, False);
00087	}
00088	
00089	defaultproperties
00090	{
00091	}

End Source Code