I am trying to create a random number generator that will create a random number every time a dragon needs to decide what direction to run, once the player gets within a certain distance of it. Depending on what the random number that gets generated, the dragon will run to a certain vector location, once the player gets within a certain close distance to the dragon.

Here is the code I have to try and make this happen:

Code:
action dragon_action() 
{  
   ...

   rndmIntGenerator = integer(random(4)); // Generate random
      //    number between 0 to 3, and store it in variable.

   ...

   while (my.status != dead)
   {
      ...

      dragnPlyrDist = vec_dist (hero.x, my.x); // Distance in
         //    units between dragon and player.

      ...

      if(my.status == dragonBiteAttack) // Dragon tries to bite
         //    player.
      {
         ...

         if (dragnPlyrDist <= 200) // (Distance Between Dragon 
                                   //    and Player) <= 200
         {
            my.status = dragonRetreatFromPlayer; // Dragon
               //    retreats from player.
         }

         ...
      }

      if(my.status == dragonRetreatFromPlayer)
      {
         ent_animate(my, "walk", run_percentage, ANM_CYCLE); 
         run_percentage -= 6 * time_step;

         if(rndmIntGenerator == 0)
	 {
	    ent_moveto(me, vector(-3, -592, -103), 30);
               // If random number is 0, dragon moves to this
               //    vector location.
	 }
			
	 if(rndmIntGenerator == 1)
	 {
	    ent_moveto(me, vector(-599, 46, -103), 30);
               // If random number is 1, dragon moves to this
               //    vector location.
	 }
			
	 if(rndmIntGenerator == 2)
	 {
	    ent_moveto(me, vector(-54, 642, -103), 30);
               // If random number is 2, dragon moves to this
               //    vector location.
	 }
			
	 if(rndmIntGenerator == 3)
	 {
	    ent_moveto(me, vector(665, 57, -103), 30);
               // If random number is 3, dragon moves to this
               //    vector location.
	 }
      }
      
      ...
   }
}



The random number generator is generating a number, and the dragon moves to that number vector location, but the number never changes, when I continually move the player to within 200 units of it in the same game. The random number stays the same, and the dragon just keeps moving to the same spot, instead of a different spot every time I get the player to within 200 units of it. If I restart the game, then the random number generator will generate a new number again, but then it stays the same for the remainder of that game.

Does anyone have advice on how I can make it so that a random number gets generated each time the player gets to within 200 units of the dragon, in the same game? In other words, the random number can change each subsequent time the player gets to within 200 units of the dragon, instead of repeating the same value over and over, within the same game?

Any help would be appreciated. Thank you.

Last edited by Ruben; 03/01/17 21:00.