home *** CD-ROM | disk | FTP | other *** search
/ Unreal Tournament Game Programming for Teens / UnrealTournamentGameProgrammingForTeens.iso / Chapter Files / Chapter05 / Ch04Area / Classes / CommandMessageTrigger.uc < prev    next >
Encoding:
Text File  |  2006-10-23  |  2.2 KB  |  88 lines

  1. //=================================================================
  2. // CommandMessageTrigger 
  3. // See CommandMessageTrigger.txt
  4. //=================================================================
  5. class CommandMessageTrigger extends Trigger placeable;
  6.     //#1
  7.     // data members for messages and random numbers
  8.     var private string FirstMessage;
  9.     const NUMOFMESSAGES = 6;
  10.     enum PState{
  11.            UP,
  12.            DOWN
  13.     };  
  14.  
  15. function PostBeginPlay()
  16. {
  17.     FirstMessage = "Go!";
  18.     Super.PostBeginPlay();
  19.     Message = FirstMessage;
  20. }// end PostBeginPlay()
  21.  
  22. function Touch( actor Other )
  23. {
  24.     if (IsRelevant( Other ) )
  25.     {
  26.         // #2
  27.         if (Pawn(Other).bIsCrouched){ // down state
  28.             Message= MakeMessage(PState.DOWN);
  29.         }//end if
  30.         else{ // up state
  31.             Message= MakeMessage(PState.UP);
  32.         }//end else
  33.  
  34.         Super.Touch(Other);
  35.     }//end outer if
  36. }// end Touch()
  37.  
  38. private function string MakeMessage(PState state){
  39.     // #3
  40.     local int RandomNumber;
  41.     local string ActionMessage; 
  42.     RandomNumber = Rand(NUMOFMESSAGES);
  43.  
  44.     // #4 
  45.     //Build messages on the basis of up or down state  
  46.     
  47.     if( state == PState.UP ){
  48.        ActionMessage @= "Get down!";
  49.        ActionMessage @= GetMessageText(RandomNumber); 
  50.     }
  51.     else if( state == PState.DOWN ){
  52.        ActionMessage @= "Get up!";
  53.        ActionMessage @= GetMessageText(RandomNumber); 
  54.     }
  55.     else {
  56.        ActionMessage = "Okay.";
  57.     }
  58.     
  59.     return ActionMessage; 
  60. }
  61.  
  62. private function string GetMessageText(int index){
  63.  
  64.    // #5
  65.    //Define a static array of the string type
  66.    local string PawnMessages[NUMOFMESSAGES]; 
  67.    local string TMessage;
  68.  
  69.    // #6
  70.    //Assign text values to elements 
  71.    PawnMessages[0]= "Watch out behind you!";
  72.    PawnMessages[1]= "Turn to your left!";
  73.    PawnMessages[2]= "Get ready to go!";
  74.    PawnMessages[3]= "Did you see the danger?";
  75.    PawnMessages[4]= "Can we move again?";
  76.    PawnMessages[5]= "How many did your see?";
  77.  
  78.    //Retrieve an element from the array
  79.    if(index < NUMOFMESSAGES && index >= 0){
  80.       TMessage = PawnMessages[index];
  81.    }
  82.    return TMessage;
  83. }
  84.  
  85. defaultproperties
  86. {
  87. }
  88.