How do you make a trigger that picks a random player from a player group?
I already made a function that tells me the number of players in that player group, however, I need the game to pick one of them. This is what I tried to do:'
It will fail because it counts the number of players in the player group, not the player number. For example: Players 3 5 8 9 are in that player group.
It will bring up a random integer from 1-4 since there are only 4 players in the player group. Lets assume it will pick the number 2, that means that it will do the action (in this case it is creating a civilian) for player 2, even though he is not included in the player group. So how exactly do I tell it to pick from the player group.... and it has to be random. Thanks in advance.
I have a solution, but there may be an easier way. its fairly tedious. ill wait a bit to see if someone has a better solution. if none appears, ill give you mine.
I guess ill give it to ya now, i guess since imam bout to get off.
here ill upload a map i put it on. i only put it up to 3 players, but its easy to add more. im not sure if how it works will fit into your map, but i might as well offer.
Thank you for the map, however, there is a problem with your way of doing it. If we continue on doing this for 15 players, the chance of player 15 being the infestor would be very small (assuming that in the triggers we start off from 1 and continue chronologically). This is because the game would start off by checking player 1 then player 2... etc. And by the time it reaches player 15 it would be probably have assigned the infestor to a player. Is what I am saying right... or wrong? I am not sure myself.
Anyways, I tested it out and the game gave me a bunch of errors "Too many nested trigger threads"
"stack overflow"
Thanks anyways.... I still need some help though :(
luckly for you, your problem has interested me enough to continue trying, and I have now produced a working version of the map.
(change log in comment section of trigger library)
ive had perfect results so-far on my end. try testing it yourself. right now the only problem is that it occationally takes up to 2 seconds for the infestor to finally spawn. however I think it is solvable by quickening the pacing a little (you will see what I mean inside)
Why not just set a local variable to a random integer 1-15 then use a condition that checks if that player number is in the player group you want. If not, have it pick a new integer. You can set this up by putting the set variable action in a loop, and having an if then action that breaks the loop when the condition is true.
doesnt it return a random integer between 1 to 5 (since there are 5 players in the player group), and then it assigns it the player with that random integer?
For example: players 3 6 8 10 12 are in the player group, will it not choose an integer between 1 to 5? It might choose something like 4 and then assign the infestor to player 4, but player 4 is not in the player group.
I know I am wrong, but can someone just explain how that function works. Thanks.
How do you make a trigger that picks a random player from a player group?
I already made a function that tells me the number of players in that player group, however, I need the game to pick one of them. This is what I tried to do:'
http://gyazo.com/c871379499234b224f5cce8935abe7a5
It will fail because it counts the number of players in the player group, not the player number. For example: Players 3 5 8 9 are in that player group. It will bring up a random integer from 1-4 since there are only 4 players in the player group. Lets assume it will pick the number 2, that means that it will do the action (in this case it is creating a civilian) for player 2, even though he is not included in the player group. So how exactly do I tell it to pick from the player group.... and it has to be random. Thanks in advance.
-TerranMaster23
I have a solution, but there may be an easier way. its fairly tedious. ill wait a bit to see if someone has a better solution. if none appears, ill give you mine.
@joey101d: Go
Thanks
I guess ill give it to ya now, i guess since imam bout to get off.
here ill upload a map i put it on. i only put it up to 3 players, but its easy to add more. im not sure if how it works will fit into your map, but i might as well offer.
@joey101d: Go
Thank you for the map, however, there is a problem with your way of doing it. If we continue on doing this for 15 players, the chance of player 15 being the infestor would be very small (assuming that in the triggers we start off from 1 and continue chronologically). This is because the game would start off by checking player 1 then player 2... etc. And by the time it reaches player 15 it would be probably have assigned the infestor to a player. Is what I am saying right... or wrong? I am not sure myself.
Anyways, I tested it out and the game gave me a bunch of errors "Too many nested trigger threads" "stack overflow"
Thanks anyways.... I still need some help though :(
sorry. I had a feeling it wouldn't work. :( hope you find a solution.
luckly for you, your problem has interested me enough to continue trying, and I have now produced a working version of the map. (change log in comment section of trigger library)
ive had perfect results so-far on my end. try testing it yourself. right now the only problem is that it occationally takes up to 2 seconds for the infestor to finally spawn. however I think it is solvable by quickening the pacing a little (you will see what I mean inside)
Why not just set a local variable to a random integer 1-15 then use a condition that checks if that player number is in the player group you want. If not, have it pick a new integer. You can set this up by putting the set variable action in a loop, and having an if then action that breaks the loop when the condition is true.
@TerranMaster23: Go
why is everyone doing it so complicated? Easy, fast and clear (don't even need comments):
@joey101d: Go
Thank you. It works well, but I prefer Funky's since it is more clean. :)
@FunkyUserName: Go
Thank you, works well, but I dont fully understand how it works. This function http://gyazo.com/49d4e71de70ad8de0c3581a1d313fa67
doesnt it return a random integer between 1 to 5 (since there are 5 players in the player group), and then it assigns it the player with that random integer? For example: players 3 6 8 10 12 are in the player group, will it not choose an integer between 1 to 5? It might choose something like 4 and then assign the infestor to player 4, but player 4 is not in the player group.
I know I am wrong, but can someone just explain how that function works. Thanks.
this Is why I think that works. it indexes the players not based on the player number but rather order in the group.
I knew there was an easier way lol
for some reason I knew it could work like that, but I doubted myself when u said it would fail cuz it would be integer 1-5, not player 3 6 etc.
@joey101d: Go
I see :), I really appreciate the help from everyone! Thank you :D