So I'm doing a map where every unit for each player is moved to a point every X minute, but I want the points to which the units are moved to be picked randomly i.e. without a pattern. How would I go about picking 1 random point to move to for each player without having two+ players moving to the same point?
I need a little more info to be precise. Points in all the map? Predefined points?
You have a Random Point in Region for example. You can always check if there are enemy units near before asigning that point, but really depends on the exact purpose you follow.
Well, the map consist of 9 zones, each zone has 1 point. I want the players to be split among the 9 points in each of the zones, with the point selected for each player being random (and no point must be selected for two+ players). And a random point in a region sadly isn't going to work :(
Probably putting on your map 9 starting positions, the game will already make a random choose for every player, but you can always do something like this:
Create an array with all points, like:
Start_Point[0], Start_Point[1], Start_Point[2], and so on.
Create a boolean array, that will have true if the point is already taken: Start_Point_Taken[0], Start_Point_Taken[1], Start_Point_Taken[2]...
Create another variable called Chosen_Point for example, an integer.
Make sure both arrays start correctly (all points in the first one, and all false in the second one). Then do something like this:
Select each integer (Min player number to Max player number)
Chosen_Point= random integer (1-9)
while
Start_Point_Taken[Chosen_Point]==true
do actions
Chosen_Point= random integer (1-9)
(*end while*)
set Start_Point_Taken[Chosen_Point]==true
(*Do whatever you wanna do to define the player starting point, the point is in the variable Start_Point[Chosen_Point] and the player is the Selected Integer, for example if you have another variable for starting points[number of player] do a Set Your_Varible[Selected Integer]=Start_Point[Chosen_Point]*)
(*end select each integer*)
That will for each player keep doing random points until gets one free (defined by the variable Start_Point_Taken).
It works, however, the effect is not as I intended, what I wanted to do is change the Chosen_Point every x minutes, making it possible for me to move units around to completely random locations.
So what I'm asking is basically: How do I make Chosen_Point generate random integers every x minute?
thx a ton for this though :D
edit: and I guess I need to reset the boolean array aswell.
I don't know why but I see all variables as "No value" so I can't check much. All the variables are named as "No value" lol.
But I can see that there is extrange stuff in there. You aren't checking the variable that show if a point is avaliable before doing stuff. And you seems to put it to true before checking, so it will be always be true.
Can you please paste me at least all the code of a player here? I don't know why I can't see the variables name. What language do you use in the editor?
Maybe is because my editor is in Spanish, but didn't happened before. As you can see I see all the variables in blank, and in the triggers, as Sin Valor (no value). Hard to understand the code. It works tought.
Edit: If you right click the code and do Copy as Text you can paste it here.
You pick a new random value inside the Pick Unit, so you randomize each unit of the army. You wanna move all the player army together, no? The while isnt correctly used, the while is only to find the free point, you need to take the move unit code outside of the while.
From the start, something like this:
Variable - Set Chosen Point = (Random integer between 1 and 8 )
General - While
Conditions
Start Point Taken [Chosen Point] == true
Actions
Variable - Set Chosen Point = (Random integer between 1 and 8 )
This is the while before you do anything, keeps choosing random points, until the Start Point Taken [ Chosen Point] returns false, so is a free point.
Then, outside the while, you use that point, and set the chosen point to taken, so other player can't teleport there.
Variable - Set Start Point Taken[Chosen Point] = true
Unit Group - Pick each unit (same as yours)
Camera (same)
Then you start again with another player. You can use a loop for this too, but try first for each player so you understand the code. Remember that the only thing inside the While is an action choosing another random point if is taken.
It seems to work now, except when I have more than 4 players with units and try to port them around I get a teleport func error, saying my execution took too long. What might be the reason for this?
So I'm doing a map where every unit for each player is moved to a point every X minute, but I want the points to which the units are moved to be picked randomly i.e. without a pattern. How would I go about picking 1 random point to move to for each player without having two+ players moving to the same point?
Maybe I need scripting?
@piepgras: Go
I need a little more info to be precise. Points in all the map? Predefined points?
You have a Random Point in Region for example. You can always check if there are enemy units near before asigning that point, but really depends on the exact purpose you follow.
@fr0d0b0ls0n: Go
Well, the map consist of 9 zones, each zone has 1 point. I want the players to be split among the 9 points in each of the zones, with the point selected for each player being random (and no point must be selected for two+ players). And a random point in a region sadly isn't going to work :(
Hope you can help :p
@piepgras: Go
Probably putting on your map 9 starting positions, the game will already make a random choose for every player, but you can always do something like this:
Create an array with all points, like:
Start_Point[0], Start_Point[1], Start_Point[2], and so on.
Create a boolean array, that will have true if the point is already taken: Start_Point_Taken[0], Start_Point_Taken[1], Start_Point_Taken[2]...
Create another variable called Chosen_Point for example, an integer.
Make sure both arrays start correctly (all points in the first one, and all false in the second one). Then do something like this:
Select each integer (Min player number to Max player number)
Chosen_Point= random integer (1-9)
while
Start_Point_Taken[Chosen_Point]==true
do actions
Chosen_Point= random integer (1-9)
(*end while*)
set Start_Point_Taken[Chosen_Point]==true
(*Do whatever you wanna do to define the player starting point, the point is in the variable Start_Point[Chosen_Point] and the player is the Selected Integer, for example if you have another variable for starting points[number of player] do a Set Your_Varible[Selected Integer]=Start_Point[Chosen_Point]*)
(*end select each integer*)
That will for each player keep doing random points until gets one free (defined by the variable Start_Point_Taken).
@fr0d0b0ls0n: Go
Thanks a bunch, time to start tinkering! I'll report back when I get it to work.
@piepgras: Go
It works, however, the effect is not as I intended, what I wanted to do is change the Chosen_Point every x minutes, making it possible for me to move units around to completely random locations.
So what I'm asking is basically: How do I make Chosen_Point generate random integers every x minute?
thx a ton for this though :D
edit: and I guess I need to reset the boolean array aswell.
@piepgras: Go
Set point = random point in region (region being the zone)
and that for every point/zone.
you were looking for something like that?
@piepgras: Go
Probably isn't hard, but I don't know all the details.
For example, if you reset the boolean array at the start, you can put all that code inside a While
While
(put a condition if you wanna it to stop... leave it alone if will last all the game)
ALL THE CODE HERE WITH A RESET OF THE BOOLEAN TO FALSE
General - Wait 60 seconds of real/game time.
(End while)
That will repeat that code each minute.
Thanks for all the answers, I need to be more thorough with my trigger and stuff right now, I'll probably figure it out somehow :D
Have a look xD
@piepgras: Go
I don't know why but I see all variables as "No value" so I can't check much. All the variables are named as "No value" lol.
But I can see that there is extrange stuff in there. You aren't checking the variable that show if a point is avaliable before doing stuff. And you seems to put it to true before checking, so it will be always be true.
Can you please paste me at least all the code of a player here? I don't know why I can't see the variables name. What language do you use in the editor?
I use the default english editor, my os (w7) is english aswell.
How do I paste my code? Do you mean a screenshot?
@piepgras: Go
A screenshot is okay.
Maybe is because my editor is in Spanish, but didn't happened before. As you can see I see all the variables in blank, and in the triggers, as Sin Valor (no value). Hard to understand the code. It works tought.
Edit: If you right click the code and do Copy as Text you can paste it here.
@fr0d0b0ls0n: Go
You pick a new random value inside the Pick Unit, so you randomize each unit of the army. You wanna move all the player army together, no? The while isnt correctly used, the while is only to find the free point, you need to take the move unit code outside of the while.
From the start, something like this:
Variable - Set Chosen Point = (Random integer between 1 and 8 )
General - While
Conditions
Start Point Taken [Chosen Point] == true
Actions
Variable - Set Chosen Point = (Random integer between 1 and 8 )
This is the while before you do anything, keeps choosing random points, until the Start Point Taken [ Chosen Point] returns false, so is a free point.
Then, outside the while, you use that point, and set the chosen point to taken, so other player can't teleport there.
Variable - Set Start Point Taken[Chosen Point] = true
Unit Group - Pick each unit (same as yours)
Camera (same)
Then you start again with another player. You can use a loop for this too, but try first for each player so you understand the code. Remember that the only thing inside the While is an action choosing another random point if is taken.
@piepgras: Go
It seems to work now, except when I have more than 4 players with units and try to port them around I get a teleport func error, saying my execution took too long. What might be the reason for this?
Is it simply too long?
What should I do then? xD
@piepgras: Go
The while can't find a free point, so it takes "infinite time". Probably because considers all points taken.
At the start of the timer, put all Start Point Taken[X] = false again. For 0, 1, 2, 3, and so on.
@fr0d0b0ls0n: Go
Wow, everything works. Can't thank you enough :D Time to start making the actual gameplay!