home *** CD-ROM | disk | FTP | other *** search
/ Unreal Tournament Game Programming for Teens / UnrealTournamentGameProgrammingForTeens.iso / Chapter Files / Chapter07 / CommandMessageTrigger.txt next >
Encoding:
Text File  |  2006-11-01  |  2.2 KB  |  87 lines

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