Guest User

Untitled

a guest
Aug 10th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ZombiesBot extends UTBot;
  2.  
  3. var Actor Destination;
  4. var float AttackDistance;
  5. var float SightDistance;
  6.  
  7. var float farAway;
  8.  
  9. protected event ExecuteWhatToDoNext()
  10. {
  11.    //Go to the roaming state
  12.    GotoState('Roaming');
  13. }
  14.  
  15. state Roaming
  16. {
  17.     //This function just returns the first player it finds
  18.     function ZO_PAWN_Base FindEnemy()
  19.     {
  20.         local ZO_PAWN_Base P;
  21.  
  22.         ForEach AllActors(class'ZO_PAWN_Base', P)
  23.         {
  24.             if (ZombiesPlayerController(P.Controller) != None)
  25.             return P;
  26.         }
  27.         Return None;
  28.     }
  29.  
  30.     Begin:
  31.     if(Enemy == None)
  32.     {
  33.         //If the bot has no enemy, find one
  34.         Enemy = FindEnemy();
  35.         farAway = vsize(Pawn.Location - Enemy.Location);
  36.         if (farAway > SightDistance)
  37.         {
  38.             Enemy = None;
  39.         }
  40.     }
  41.  
  42.     if(Enemy != None)
  43.     {
  44.         farAway = vsize(Pawn.Location - Enemy.Location);
  45.         if (farAway > SightDistance)
  46.         {
  47.             Enemy = None;
  48.             WorldInfo.Game.Broadcast(self, 'Roaming Ends - Returning to Roaming');
  49.             goto('Begin');
  50.         }
  51.  
  52.         //If the bot has an Enemy, look to see if we're within attack distance.
  53.         if(farAway > AttackDistance)
  54.         {
  55.             //search for a path using pathnodes to it
  56.             if(FindBestPathToward(Enemy, false, false))
  57.             {
  58.                 //Move along the path that was just calculated
  59.                 MoveToward(MoveTarget,,,False);
  60.             }
  61.             else
  62.             {
  63.                 //Move directly towards Enemy if no path was found
  64.                 MoveToward(Enemy, , ,False);
  65.             }
  66.         }
  67.         else
  68.         {
  69.             WorldInfo.Game.Broadcast(self, 'Roaming Ends - Returning to Attack');
  70.             GotoState('Attack');
  71.         }
  72.     }
  73.     else
  74.     {
  75.         //Find a random pathnode and go to it
  76.         MoveTo(FindRandomDest().Location);
  77.     }
  78.  
  79.     //Sleep for one second
  80.     Sleep(1);
  81.  
  82.     //Go back to the Begin label
  83.     WorldInfo.Game.Broadcast(self, 'Roaming Ends - Returning to Roaming');
  84.     goto('Begin');
  85. }
  86.  
  87. state Attack
  88. {
  89.     Begin:
  90.     WorldInfo.Game.Broadcast(self, 'Attack Begins');
  91.  
  92.     //Swing those fists at the player.
  93.     FireWeaponAt(Focus);
  94.  
  95.     WorldInfo.Game.Broadcast(self, 'Attack Ends - Returning to Roaming');
  96.     GotoState('Roaming');
  97. }
  98.  
  99. defaultproperties
  100. {
  101.     SightDistance=1200
  102.     AttackDistance=100
  103. }
Add Comment
Please, Sign In to add comment