0 registered members (),
1,094
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
random number generator
#464624
03/01/17 20:57
03/01/17 20:57
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
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:
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.
|
|
|
Re: random number generator
[Re: Ruben]
#464625
03/01/17 21:57
03/01/17 21:57
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
The random number generator is generating a number, and the dragon moves to that number vector location, but the number never changes I will probably come across as a massive dick, but... You do realize that that's due to you never changing the variable ever? Where you assign the `dragonRetreatFromPlayer` state, you can simply generate a new random number.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: random number generator
[Re: WretchedSid]
#464626
03/02/17 01:06
03/02/17 01:06
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
The random number generator is generating a number, and the dragon moves to that number vector location, but the number never changes I will probably come across as a massive dick, but... You do realize that that's due to you never changing the variable ever? Where you assign the `dragonRetreatFromPlayer` state, you can simply generate a new random number. I tried that before. However, when I call the random number in the "dragonRetreatFromPlayer" state, and the player gets to within 200 units of the dragon, the dragon keeps continually trying to move to the different vector locations, just as if the random number is constantly being called and changed in real time, and the dragon is trying to follow the direction of the random number that keeps changing. The dragon never actually gets to a location. It just keeps wiggling here and there in the middle of the room without going anywhere.
Last edited by Ruben; 03/02/17 01:07.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|