home *** CD-ROM | disk | FTP | other *** search
- //=================================================================
- // CommandMessageTrigger
- // See CommandMessageTrigger.txt
- //=================================================================
- class CommandMessageTrigger extends Trigger placeable;
- //#1
- // data members for messages and random numbers
- var private string FirstMessage;
- const NUMOFMESSAGES = 6;
- enum PState{
- UP,
- DOWN
- };
-
- function PostBeginPlay()
- {
- FirstMessage = "Go!";
- Super.PostBeginPlay();
- Message = FirstMessage;
- }// end PostBeginPlay()
-
- function Touch( actor Other )
- {
- if (IsRelevant( Other ) )
- {
- // #2
- if (Pawn(Other).bIsCrouched){ // down state
- Message= MakeMessage(PState.DOWN);
- }//end if
- else{ // up state
- Message= MakeMessage(PState.UP);
- }//end else
-
- Super.Touch(Other);
- }//end outer if
- }// end Touch()
-
- private function string MakeMessage(PState state){
- // #3
- local int RandomNumber;
- local string ActionMessage;
- RandomNumber = Rand(NUMOFMESSAGES);
-
- // #4
- //Build messages on the basis of up or down state
-
- if( state == PState.UP ){
- ActionMessage @= "Get down!";
- ActionMessage @= GetMessageText(RandomNumber);
- }
- else if( state == PState.DOWN ){
- ActionMessage @= "Get up!";
- ActionMessage @= GetMessageText(RandomNumber);
- }
- else {
- ActionMessage = "Okay.";
- }
-
- return ActionMessage;
- }
-
- private function string GetMessageText(int index){
-
- // #5
- //Define a static array of the string type
- local string PawnMessages[NUMOFMESSAGES];
- local string TMessage;
-
- // #6
- //Assign text values to elements
- PawnMessages[0]= "Watch out behind you!";
- PawnMessages[1]= "Turn to your left!";
- PawnMessages[2]= "Get ready to go!";
- PawnMessages[3]= "Did you see the danger?";
- PawnMessages[4]= "Can we move again?";
- PawnMessages[5]= "How many did you see?";
-
- //Retrieve an element from the array
- if(index < NUMOFMESSAGES && index >= 0){
- TMessage = PawnMessages[index];
- }
- return TMessage;
- }
-
- defaultproperties
- {
- }
-