HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Random Hero not so random.

07-18-2009, 06:11 PM#1
Super.gnome
A hero selection trigger:

Trigger:
Random Light
Collapse Events
Player - Player 1 (Red) types a chat message containing -random as An exact match
Player - Player 2 (Blue) types a chat message containing -random as An exact match
Player - Player 5 (Yellow) types a chat message containing -random as An exact match
Player - Player 8 (Pink) types a chat message containing -random as An exact match
Player - Player 9 (Gray) types a chat message containing -random as An exact match
Collapse Conditions
((Triggering player) is an ally of Player 10 (Light Blue)) Equal to True
Picked[(Player number of (Triggering player))] Equal to 0
Collapse Actions
Set HeroLight = (Random integer number between 1 and HeroTotalLight)
Set Random_heroA[HeroLight] = Random_heroA[HeroTotalLight]
Set HeroTotalLight = (HeroTotalLight - 1)
Unit - Create 1 Random_heroA[HeroLight] for (Triggering player) at (Center of Base Spawn Light <gen>) facing Default building facing degrees
Set PlayerMainHeros[(Player number of (Triggering player))] = (Last created unit)
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Player - Make (Unit-type of (Last created unit)) Unavailable for training/construction by (Picked player)
Quest - Display to (All enemies of (Triggering player)) the Hint message: (A player has randomed + (Name of (Last created unit)))
Player - Add 250 to (Triggering player) Current gold
Set Picked[(Player number of (Triggering player))] = 1
Camera - Pan camera for (Triggering player) to (Center of Base Spawn Light <gen>) over 3.00 seconds



I made this trigger to make it so people could choose a random here. and I used this part to limit it to one of each hero:

Trigger:
Actions
Set HeroLight = (Random integer number between 1 and HeroTotalLight)
Set Random_heroA[HeroLight] = Random_heroA[HeroTotalLight]
Set HeroTotalLight = (HeroTotalLight - 1)

But that's not working. Its always giving me the last hero in my array to the first who randoms, and just counts backwards down the array as people random. So the first to random would get hero #35, the second would get hero #34, and so on. I think it has to do with the part of the trigger directly above. How do I fix it so that it removes a hero from the array when you random, but it doesnt give you the same hero everytime?
07-18-2009, 09:39 PM#2
0zyx0
Pick a random number between 0 and X, where X is the number of hero types (minus one). Then, get Random_heroA[random number], and set Random_heroA[same number as before] to Random_heroA[X]. Then subtract one from X.
07-18-2009, 10:01 PM#3
Sophismata
Trigger:
Actions
Set HeroLight = (Random integer number between 1 and HeroTotalLight)
Set Random_heroA[HeroLight] = Random_heroA[HeroTotalLight]
Set HeroTotalLight = (HeroTotalLight - 1)
Unit - Create 1 Random_heroA[HeroLight] for (Triggering player) at (Center of Base Spawn Light <gen>) facing Default building facing degrees


You're currently setting Random_heroA[HeroLight] to the last unit in the array, and then giving that unit to the triggering player.

Clean up the array after you create the hero:

Trigger:
Actions
Set HeroLight = (Random integer number between 1 and HeroTotalLight)
Unit - Create 1 Random_heroA[HeroLight] for (Triggering player) at (Center of Base Spawn Light <gen>) facing Default building facing degrees
Set Random_heroA[HeroLight] = Random_heroA[HeroTotalLight]
Set HeroTotalLight = (HeroTotalLight - 1)
07-19-2009, 10:27 AM#4
Darkt3mpl3r
You could also use unitpools. Pyrogasm has made a proper tutorial about it a while ago. http://www.wc3c.net/showthread.php?t=97706
07-21-2009, 02:26 AM#5
Pyrogasm
Aha! Here I was about to link to my unitpools tutorial, and you've already done it.

Another thing that might be the issue is that you have "Fixed random seed" on. Go to your editor preferences and uncheck that box, then try.