Guest User

Untitled

a guest
Jan 24th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. an example of how i would like to see a bird that maybe runs away from people for example
  2.  
  3. function __get__helper()
  4. {
  5.    retval = {
  6.       "_friendlyname":"Pigeon",
  7.       "Object Name":this.Name,
  8.    };
  9. }
  10.  
  11. function OnCreated()
  12. {
  13.    this.NextMove = Game.GetTicks()+2000+(random(0,2000)%2000);
  14.    this.OriginalPosition = this.Position;
  15.    this.SetAnimation("pidgeon","idle");
  16.    this.TriggerEvent("Think",1);
  17. }
  18.  
  19. function Think()
  20. {
  21.     near_players = Game.GetNearbyPlayers(this,10);
  22.     if (near_players.size() > 0)
  23.     {
  24.         for ( i in near_players )
  25.         {
  26.            Player player_i = i;
  27.            if ( player_i.CurrentMoveSpeed() > 10 )
  28.            {
  29.                this.Flee();
  30.            }
  31.         }
  32.     } else
  33.     {
  34.         if ( this.NextMove < Game.GetTicks() )
  35.         {
  36.             this.SetAnimation("pidgeon","walk");
  37.             Position new_pos = new Position(
  38.                         random(this.OriginalPosition.x-20,this.OriginalPosition.x+20),
  39.                         random(this.OriginalPosition.y-20,this.OriginalPosition.y+20) );
  40.             this.MoveTowards(new_pos,3,1);
  41.             // move towards new_pos at 3 tiles a second for 1 second
  42.         }
  43.     }
  44.  
  45.     this.TriggerAction("Think",1);
  46. }
  47.  
  48. function Flee()
  49. {
  50.     // play one of 4 of the premade fly away animations
  51.     this.SetAnimation("pigeon","fly_away_"+(random()%4));
  52.     this.Sleep(10); // wait 10 seconds
  53.     // set animation and block execution till it finishes
  54.     this.SetAnimation("pigeon","return",true);
  55.     this.TriggerAction("Think",1); // go back to Think loop
  56. }
Add Comment
Please, Sign In to add comment