HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Random Heroes (AoS) - Without duplicates?

06-05-2006, 11:35 AM#1
Fulla
Ok I made a random hero option which was easy enough.

I simply set each hero to an array
Player_Heroes[1] - Hero A
Player_Heroes[2] - Hero B
Player_Heroes[3] - Hero C
etc. etc.

Then just Random Number between X and X.
Create 1 Player_Heroes[RandomNumber] for Player X

I can copy the triggers across if needed, but its seems very simple.

----

I then realised that this wont stop players being able to have the same heroes.

How could I setup an efficient "All random", giving each player a random hero but preventing Players from having the same hero.

thx
06-05-2006, 11:39 AM#2
Whitehorn
Stick them in a unit group, pick from group randomly, then remove picked hero from group.
06-05-2006, 11:51 AM#3
Fulla
Would that not require the Heroes to be placed on map initially thou?
06-05-2006, 11:58 AM#4
emjlr3
check the dota template
http://world-editor-tutorials.thehel...s.php?view=137
it has a good one
06-05-2006, 12:02 PM#5
Blade.dk
You can set the value in the array that you have already used to nothing, and then check if it is nothing before using it. If it is nothing, then get a new random value from the array, check again and so on.
06-05-2006, 12:12 PM#6
Fulla
Thx Emjir3, been looking at it, seems complicated Im trying to figure out how it works :-)

@ Blade, ah so if a hero is used clear that Array. Then have a loop to check if its nothing.
Ill give it a try
06-05-2006, 01:50 PM#7
Anitarf
Either that, or when a hero is picked, remove it from the array, then move all heroes that come after it one slot back with a loop. This way, you don't have to loop when picking a random hero, because you won't have any empty slots in the array.
06-05-2006, 02:11 PM#8
Vexorian
I cannot believe the quantity of times this has been asked
Collapse pseudo code:
    set n=15
    set Hero[1]=Hero Type 1
    set Hero[2]=Hero Type 2
    ...
    set Hero[n]=Hero Type n

// When you want to get a hero type:
    if (n<0)
    {
          //there are no more heroes, you can re initialize the array or call ExecuteFunc("Crash") to end the game if you want
    }
    set i=Random Integer From 1 to n
    set RandomHero=Hero[i]
    set Hero[i]=Hero[n]
    set n=n-1
    // The RandomHero variable now holds a new hero type