Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ZombiesBot extends UTBot;
- var Actor Destination;
- var float AttackDistance;
- var float SightDistance;
- var float farAway;
- protected event ExecuteWhatToDoNext()
- {
- //Go to the roaming state
- GotoState('Roaming');
- }
- state Roaming
- {
- //This function just returns the first player it finds
- function ZO_PAWN_Base FindEnemy()
- {
- local ZO_PAWN_Base P;
- ForEach AllActors(class'ZO_PAWN_Base', P)
- {
- if (ZombiesPlayerController(P.Controller) != None)
- return P;
- }
- Return None;
- }
- Begin:
- if(Enemy == None)
- {
- //If the bot has no enemy, find one
- Enemy = FindEnemy();
- farAway = vsize(Pawn.Location - Enemy.Location);
- if (farAway > SightDistance)
- {
- Enemy = None;
- }
- }
- if(Enemy != None)
- {
- farAway = vsize(Pawn.Location - Enemy.Location);
- if (farAway > SightDistance)
- {
- Enemy = None;
- WorldInfo.Game.Broadcast(self, 'Roaming Ends - Returning to Roaming');
- goto('Begin');
- }
- //If the bot has an Enemy, look to see if we're within attack distance.
- if(farAway > AttackDistance)
- {
- //search for a path using pathnodes to it
- if(FindBestPathToward(Enemy, false, false))
- {
- //Move along the path that was just calculated
- MoveToward(MoveTarget,,,False);
- }
- else
- {
- //Move directly towards Enemy if no path was found
- MoveToward(Enemy, , ,False);
- }
- }
- else
- {
- WorldInfo.Game.Broadcast(self, 'Roaming Ends - Returning to Attack');
- GotoState('Attack');
- }
- }
- else
- {
- //Find a random pathnode and go to it
- MoveTo(FindRandomDest().Location);
- }
- //Sleep for one second
- Sleep(1);
- //Go back to the Begin label
- WorldInfo.Game.Broadcast(self, 'Roaming Ends - Returning to Roaming');
- goto('Begin');
- }
- state Attack
- {
- Begin:
- WorldInfo.Game.Broadcast(self, 'Attack Begins');
- //Swing those fists at the player.
- FireWeaponAt(Focus);
- WorldInfo.Game.Broadcast(self, 'Attack Ends - Returning to Roaming');
- GotoState('Roaming');
- }
- defaultproperties
- {
- SightDistance=1200
- AttackDistance=100
- }
Add Comment
Please, Sign In to add comment