- Joined
- Feb 25, 2005
- Messages
- 230
I have used arrays for a long time now, and it works perect. But now i have a problem. Im making a simple "choose random hero for player" trigger.
It works, and ive used a unit type array variable to create the random hero. But how do i make sure that the choosen hero does not get created again so 2 players gets the same hero? It's a bit of math for me to realize how to do it...
If it helps the trigger simply looks like this:
Event - A unit sells a unit
Conditions - (Unit-type of (Sold unit)) Equal to Random Hero
Actions
-------- Set variables --------
Set randomhero[1] = Hero1
Set randomhero[2] = Hero2
Set randomhero[3] = Hero3
Set randomhero[4] = Hero4
Set randomhero[5] = Hero5
Set randomhero[6] = Hero6
Set randomhero[7] = Hero7
Set randomhero[8] = Hero8
Set randomhero[9] = Hero9
Set randomhero[10] = Hero10
Set randomhero[11] = Hero11
Set randomhero[12] = Hero12
Set randomhero[13] = Hero13
Set randomhero[14] = Hero14
Set randomhero[15] = Hero15
Set randomhero[16] = Hero16
Set randomhero[17] = Hero17
Set randomhero[18] = Hero18
Set randomhero[19] = Hero19
Set randomhero[20] = Hero20
Set randomhero[21] = Hero21
Set randomhero[22] = Hero22
Set Numberofheroes = 22
-------- Give Hero --------
If (((Owner of (Sold unit)) is an ally of Player 1 (Red)) Equal to True) then do (Unit - Create 1 randomhero[(Random integer number between 1 and Numberofheroes)] for (Owner of (Sold unit)) at (Center of Southern Shop Spot <gen>) facing Default building facing degrees) else do (Do nothing)
If (((Owner of (Sold unit)) is an ally of Player 7 (Green)) Equal to True) then do (Unit - Create 1 randomhero[(Random integer number between 1 and Numberofheroes)] for (Owner of (Sold unit)) at (Center of Northern Shop Spot <gen>) facing Default building facing degrees) else do (Do nothing)
Unit - Remove (Sold unit) from the game
It works, and ive used a unit type array variable to create the random hero. But how do i make sure that the choosen hero does not get created again so 2 players gets the same hero? It's a bit of math for me to realize how to do it...
If it helps the trigger simply looks like this:
Event - A unit sells a unit
Conditions - (Unit-type of (Sold unit)) Equal to Random Hero
Actions
-------- Set variables --------
Set randomhero[1] = Hero1
Set randomhero[2] = Hero2
Set randomhero[3] = Hero3
Set randomhero[4] = Hero4
Set randomhero[5] = Hero5
Set randomhero[6] = Hero6
Set randomhero[7] = Hero7
Set randomhero[8] = Hero8
Set randomhero[9] = Hero9
Set randomhero[10] = Hero10
Set randomhero[11] = Hero11
Set randomhero[12] = Hero12
Set randomhero[13] = Hero13
Set randomhero[14] = Hero14
Set randomhero[15] = Hero15
Set randomhero[16] = Hero16
Set randomhero[17] = Hero17
Set randomhero[18] = Hero18
Set randomhero[19] = Hero19
Set randomhero[20] = Hero20
Set randomhero[21] = Hero21
Set randomhero[22] = Hero22
Set Numberofheroes = 22
-------- Give Hero --------
If (((Owner of (Sold unit)) is an ally of Player 1 (Red)) Equal to True) then do (Unit - Create 1 randomhero[(Random integer number between 1 and Numberofheroes)] for (Owner of (Sold unit)) at (Center of Southern Shop Spot <gen>) facing Default building facing degrees) else do (Do nothing)
If (((Owner of (Sold unit)) is an ally of Player 7 (Green)) Equal to True) then do (Unit - Create 1 randomhero[(Random integer number between 1 and Numberofheroes)] for (Owner of (Sold unit)) at (Center of Northern Shop Spot <gen>) facing Default building facing degrees) else do (Do nothing)
Unit - Remove (Sold unit) from the game