I'm trying to make an arena type game so in the beginning i need 2 different units spawning for 2 different players however there are a total of 6 players(so 4 are watching). I made this line of code but its not working:
EVENT:
Timer - Elapsed time is 0.1 Game Time seconds
LOCAL VARIABLES:
Random Integer = (Random real between 1.0 and (Real((Number of players in (Active Players))))) <Real>
Random Integer 2 = (Random real between 1.0 and (Real((Number of players in (Active Players))))) <Real>
CONDITIONS:
None.
ACTIONS:
General - While (Conditions) are true, do (Actions)
CONDITIONS:
Random Integer == Random Integer 2
ACTIONS:
Variable - Set Random Integer 2 = (Random real between 1.0 and (Real((Number of players in (Active Players)))))
General - Wait for (Conditions), checking every 0.5 Game Time seconds
CONDITIONS:
Random Integer != Random Integer 2
Unit - Create 1 Changeling for player (Integer(Random Integer)) at Spawn 1 using default facing (No Options)
Unit - Create 1 Changeling for player (Integer(Random Integer 2)) at Spawn 2 using default facing (No Options)
When i tested this i got a variety of results; for some reason when i loaded it with one other computer it spawns 2 changeings at the correct locations however they both belong to me, i reloaded my game 5 times and got the same result but on the fifth time i got an error saying "MeleeInitialization took too long"(MeleeInitialization is the name of the trigger). Then when i tried to do this with 5 other computers it either worked perfectly(Spawned 2 units belonging to 2 different players) or it gave me 2 units belonging to the same player.
To make things short i think the problem is the fact that my while loop is not working for whatever reason, its not setting the "Random Intergers" equal to each other because my problem is the fact that the units spawning belongs to the same players.
I didn't get why you're using a random real function to make unit spawns for differents players. Can you be more specific on what you're trying to do here ?
What you're actually doing is randomizing a number units will spawns totally randomly for first or second player. Is that what you intended ?
Another thing is that the trigger can randomly take too long cuz you're randomizing a number until it equals a specific number. Considering this number is a real value with decimals and not an integer, it might takes long before it finds the exact 1.00 number.
Why are you using Random Real and not Random Integer to get a random player?
rename your variables better, call them randomPlayerA and randomPlayerB for example
randomPlayerA,B should be Integers
use randomPlayerA = Random Integer from 1 to (number of Active Players)
Also you might want to debug active players and see what players it actually includes, Just do a loop and have it output the player number for each one, see if it's what you expected.
I'm trying to make an arena type game so in the beginning i need 2 different units spawning for 2 different players however there are a total of 6 players(so 4 are watching). I made this line of code but its not working:
EVENT:
Timer - Elapsed time is 0.1 Game Time seconds
LOCAL VARIABLES:
Random Integer = (Random real between 1.0 and (Real((Number of players in (Active Players))))) <Real> Random Integer 2 = (Random real between 1.0 and (Real((Number of players in (Active Players))))) <Real>
CONDITIONS: None.
ACTIONS:
General - While (Conditions) are true, do (Actions)
CONDITIONS:
Random Integer == Random Integer 2
ACTIONS:
Variable - Set Random Integer 2 = (Random real between 1.0 and (Real((Number of players in (Active Players)))))
General - Wait for (Conditions), checking every 0.5 Game Time seconds
CONDITIONS:
Random Integer != Random Integer 2
Unit - Create 1 Changeling for player (Integer(Random Integer)) at Spawn 1 using default facing (No Options)
Unit - Create 1 Changeling for player (Integer(Random Integer 2)) at Spawn 2 using default facing (No Options)
When i tested this i got a variety of results; for some reason when i loaded it with one other computer it spawns 2 changeings at the correct locations however they both belong to me, i reloaded my game 5 times and got the same result but on the fifth time i got an error saying "MeleeInitialization took too long"(MeleeInitialization is the name of the trigger). Then when i tried to do this with 5 other computers it either worked perfectly(Spawned 2 units belonging to 2 different players) or it gave me 2 units belonging to the same player.
To make things short i think the problem is the fact that my while loop is not working for whatever reason, its not setting the "Random Intergers" equal to each other because my problem is the fact that the units spawning belongs to the same players.
Thanks for your help.
Why are you using Random Real and not Random Integer to get a random player?
Also you might want to debug active players and see what players it actually includes, Just do a loop and have it output the player number for each one, see if it's what you expected.
Alright, i got it to work thanks, my problem was i was using a random real instead of a random integer.