- Joined
- Mar 13, 2013
- Messages
- 299
I recently tried (and succeeded) in making a random hero system for otherwise standard melee games. This is my first attempt at any kind of trigger - indeed my first time even opening the trigger editor in the world editor - so I don't know if this is "tutorial-worthy." Also, I realize that this is a very specific function, and a bit obscure. But, since I couldn't find someone else giving the answer when I was looking for it, I figured I may as well.
First of all the rules:
1) All heroes are removed from all altars and taverns. Instead the option to "train random hero" is available.
2) Upon training, a random hero shows up instead. It could be any hero from any race.
3) You can have a max of two of the same heroes (I felt three blademasters would be a bit much, but two was manageable...)
Keep in mind these rules are specific to this tutorial. It's fairly straightforward to alter them i.e. only allowing specific heroes or not allowing repeats at all..
The overall layout of this tutorial is as follows:
Step 1) Sound. This is merely getting the sounds each hero makes upon being trained ready for the game.
Step 2) Object modification. Creating dummy random hero units and then setting up the altars and taverns to only train random heroes.
Step 3a) Trigger initialization. The Heroes and sounds from Step (1) need to be loaded into variables and the units to be built by the altars need to have limits so players can only build one per tier.
Step 3b) random hero trigger. This part is actually very short, considering it is the main function. Basically, the event is going to be "whenever a unit trains a random hero," since this can only happen due to a modified altar in step (2). Once finished, we are going to remove the trained random hero, set the number of random heros the training player can build to zero, and add a hero as prescribed from Step (3a). Of course it is 'nice' to also play the appropriate sound.
Step 4) This is the easiest of them. Once you've added the custom objects the map for some reason reverts back to some other default game values. You have to go to Scenario->Map Options... Here you must change "Game Data Set" to "Melee (Latest Patch)."
And that's it. Done!
In detail, the steps look like this:
Step 1 Sound:
Before a sound can be used with the triggers, it must be set to "use as sound." This is done in the Sound Editor. There is very little to describe here. Basically hunt for the appropriate sound, right click, and click "use as sound."
This is a lot of work, and you can use an .mpq editor to export/import these sound settings in one step, if you'd prefer. I can send the file to you if desired..
Step 2 Objects:
There are two things you must do: First, remove all of the heroes from all of the altars, and the neutral tavern (if they are used on your map - or even if you would like to set this up for generic purpose, it's a good idea).
Second, you need to create dummy units. It doesn't matter what you copy to use, but you need three total. Once you have the three units you want, you must make the following modifications:
1) Change the tooltip, name, extended tooltip, et cetera of all of these structures to reflect what they are (i.e. "A random hero")
2) at least temporarily (you can undo this once you are otherwise finished - but you need it now so that you can "see what you are doing") you need to include in the name:
-First random hero
-Second random hero
-Third random hero
At this point these should be the new names of your three newly created units.
Now, to modify the stats of each. The "first random hero" should be modified to use 5 food and 55 build time. In fact, all of these building should require 5 food and 55 build time, but this is the only one that requires "only" these modifications.
Your "Second random hero" must also require 425 gold and 100 lumber. But additionally, add a tech requirement of a "any tier 2 hall". This can be adding the tech tree requirement, click on the drop-down that says "units" and select "equivalents". Then go to the drop-down that says "any altar" and select "any tier 2 hall".
Similarly, your "Third random hero" must require 425 gold, 100 lumber, and a tech requirement of "any tier 3 hall"...
Once these are set, go back to each race's altar and add "First Random Hero" to all of them. Then add "Second random hero", as well as "Third Random hero."
And you are done with the objects!
Step 3 Triggers:
I think they are pretty straightforward, so rather than explain what to do, I'll just post my script. But before that you must first set the variables:
Heros - Unit-Type Array (24) - Full array of heroes.
Sounds - Sound Array (24) - sounds to go with heroes as ordered above.
HeroIndex - Integer Array (36) - Index of heroes as they are assigned to each player
i - integer
x - integer
Note that an integer size of 24 is only really necessary for the HeroIndex, but in case it becomes useful to store the third heroes in some future version of this, it doesn't really take up much memory to keep it at 36..
And the scripts:
Don't forget step 4!
example map
First of all the rules:
1) All heroes are removed from all altars and taverns. Instead the option to "train random hero" is available.
2) Upon training, a random hero shows up instead. It could be any hero from any race.
3) You can have a max of two of the same heroes (I felt three blademasters would be a bit much, but two was manageable...)
Keep in mind these rules are specific to this tutorial. It's fairly straightforward to alter them i.e. only allowing specific heroes or not allowing repeats at all..
The overall layout of this tutorial is as follows:
Step 1) Sound. This is merely getting the sounds each hero makes upon being trained ready for the game.
Step 2) Object modification. Creating dummy random hero units and then setting up the altars and taverns to only train random heroes.
Step 3a) Trigger initialization. The Heroes and sounds from Step (1) need to be loaded into variables and the units to be built by the altars need to have limits so players can only build one per tier.
Step 3b) random hero trigger. This part is actually very short, considering it is the main function. Basically, the event is going to be "whenever a unit trains a random hero," since this can only happen due to a modified altar in step (2). Once finished, we are going to remove the trained random hero, set the number of random heros the training player can build to zero, and add a hero as prescribed from Step (3a). Of course it is 'nice' to also play the appropriate sound.
Step 4) This is the easiest of them. Once you've added the custom objects the map for some reason reverts back to some other default game values. You have to go to Scenario->Map Options... Here you must change "Game Data Set" to "Melee (Latest Patch)."
And that's it. Done!
In detail, the steps look like this:
Step 1 Sound:
Before a sound can be used with the triggers, it must be set to "use as sound." This is done in the Sound Editor. There is very little to describe here. Basically hunt for the appropriate sound, right click, and click "use as sound."
This is a lot of work, and you can use an .mpq editor to export/import these sound settings in one step, if you'd prefer. I can send the file to you if desired..
Step 2 Objects:
There are two things you must do: First, remove all of the heroes from all of the altars, and the neutral tavern (if they are used on your map - or even if you would like to set this up for generic purpose, it's a good idea).
Second, you need to create dummy units. It doesn't matter what you copy to use, but you need three total. Once you have the three units you want, you must make the following modifications:
1) Change the tooltip, name, extended tooltip, et cetera of all of these structures to reflect what they are (i.e. "A random hero")
2) at least temporarily (you can undo this once you are otherwise finished - but you need it now so that you can "see what you are doing") you need to include in the name:
-First random hero
-Second random hero
-Third random hero
At this point these should be the new names of your three newly created units.
Now, to modify the stats of each. The "first random hero" should be modified to use 5 food and 55 build time. In fact, all of these building should require 5 food and 55 build time, but this is the only one that requires "only" these modifications.
Your "Second random hero" must also require 425 gold and 100 lumber. But additionally, add a tech requirement of a "any tier 2 hall". This can be adding the tech tree requirement, click on the drop-down that says "units" and select "equivalents". Then go to the drop-down that says "any altar" and select "any tier 2 hall".
Similarly, your "Third random hero" must require 425 gold, 100 lumber, and a tech requirement of "any tier 3 hall"...
Once these are set, go back to each race's altar and add "First Random Hero" to all of them. Then add "Second random hero", as well as "Third Random hero."
And you are done with the objects!
Step 3 Triggers:
I think they are pretty straightforward, so rather than explain what to do, I'll just post my script. But before that you must first set the variables:
Heros - Unit-Type Array (24) - Full array of heroes.
Sounds - Sound Array (24) - sounds to go with heroes as ordered above.
HeroIndex - Integer Array (36) - Index of heroes as they are assigned to each player
i - integer
x - integer
Note that an integer size of 24 is only really necessary for the HeroIndex, but in case it becomes useful to store the third heroes in some future version of this, it doesn't really take up much memory to keep it at 36..
And the scripts:
-
Melee Initialization
-
Events
- Map initialization
- Conditions
-
Actions
- Melee Game - Use melee time of day (for all players)
- Melee Game - Limit Heroes to 1 per Hero-type (for all players)
- Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
- Melee Game - Set starting resources (for all players)
- Melee Game - Remove creeps and critters from used start locations (for all players)
- Melee Game - Create starting units (for all players)
- Melee Game - Run melee AI scripts (for computer players)
- Melee Game - Enforce victory/defeat conditions (for all players)
-
For each (Integer x) from 1 to 12, do (Actions)
-
Loop - Actions
- Player - Limit training of First Random Hero to 1 for (Player(x))
- Player - Limit training of Second Random Hero to 1 for (Player(x))
- Player - Limit training of Third Random Hero to 1 for (Player(x))
-
Loop - Actions
- Set Heros[1] = Paladin
- Set Sounds[1] = HeroPaladinReady1 <gen>
- Set Heros[2] = Mountain King
- Set Sounds[2] = HeroMountainKingReady1 <gen>
- Set Heros[3] = Blademaster
- Set Sounds[3] = HeroBladeMasterReady1 <gen>
- Set Heros[4] = Tauren Chieftain
- Set Sounds[4] = HeroTaurenChieftainReady1 <gen>
- Set Heros[5] = Death Knight
- Set Sounds[5] = DeathKnightReady1 <gen>
- Set Heros[6] = Dreadlord
- Set Sounds[6] = HeroDreadlordReady1 <gen>
- Set Heros[7] = Crypt Lord
- Set Sounds[7] = NerubianCryptLordReady1 <gen>
- Set Heros[8] = Demon Hunter
- Set Sounds[8] = HeroDemonHunterReady1 <gen>
- Set Heros[9] = Warden
- Set Sounds[9] = HeroWardenReady1 <gen>
- Set Heros[10] = Tinker
- Set Sounds[10] = HeroTinkerReady1 <gen>
- Set Heros[11] = Beastmaster
- Set Sounds[11] = OgreBeastMasterReady1 <gen>
- Set Heros[12] = Pandaren Brewmaster
- Set Sounds[12] = PandarenBrewmasterReady1 <gen>
- Set Heros[13] = Pit Lord
- Set Sounds[13] = HPitLordReady1 <gen>
- Set Heros[14] = Alchemist
- Set Sounds[14] = HeroAlchemistReady1 <gen>
- Set Heros[15] = Naga Sea Witch
- Set Sounds[15] = LadyVashjReady1 <gen>
- Set Heros[16] = Dark Ranger
- Set Sounds[16] = DarkRangerReady1 <gen>
- Set Heros[17] = Firelord
- Set Sounds[17] = HeroFirelordReady1 <gen>
- Set Heros[18] = Keeper of the Grove
- Set Sounds[18] = KeeperOfTheGroveReady1 <gen>
- Set Heros[19] = Priestess of the Moon
- Set Sounds[19] = HeroMoonPriestessReady1 <gen>
- Set Heros[20] = Lich
- Set Sounds[20] = HeroLichReady1 <gen>
- Set Heros[21] = Far Seer
- Set Sounds[21] = HeroFarseerReady1 <gen>
- Set Heros[22] = Shadow Hunter
- Set Sounds[22] = ShadowHunterReady1 <gen>
- Set Heros[23] = Archmage
- Set Sounds[23] = HeroArchMageReady1 <gen>
- Set Heros[24] = Blood Mage
- Set Sounds[24] = BloodElfMageReady1 <gen>
-
Events
-
Train 1
-
Events
- Unit - A unit Finishes training a unit
-
Conditions
- (Trained unit-type) Equal to First Random Hero
-
Actions
- Set x = (Random integer number between 1 and 24)
- Set i = ((3 x ((Player number of (Triggering player)) - 1)) + 1)
- Unit - Replace (Trained unit) with a Heros[x] using The new unit's max life and mana
- Player - Limit training of First Random Hero to 0 for (Triggering player)
- Hero - Create Scroll of Town Portal and give it to (Last replaced unit)
- Unit - Order (Last replaced unit) to Move To (Rally-Point of (Triggering unit) as a point)
- Set HeroIndex[i] = x
- Sound - Play Sounds[x] at 100.00% volume, attached to (Last replaced unit)
-
Events
-
Train 2
-
Events
- Unit - A unit Finishes training a unit
-
Conditions
- (Trained unit-type) Equal to Second Random Hero
-
Actions
- Set x = (Random integer number between 1 and 24)
- Set i = ((3 x ((Player number of (Triggering player)) - 1)) + 2)
- Unit - Replace (Trained unit) with a Heros[x] using The new unit's max life and mana
- Player - Limit training of Second Random Hero to 0 for (Triggering player)
- Unit - Order (Last replaced unit) to Move To (Rally-Point of (Triggering unit) as a point)
- Set HeroIndex[i] = x
- Sound - Play Sounds[x] at 100.00% volume, attached to (Last replaced unit)
-
Events
-
Train 3
-
Events
- Unit - A unit Finishes training a unit
-
Conditions
- (Trained unit-type) Equal to Third Random Hero
-
Actions
- Set i = ((3 x ((Player number of (Triggering player)) - 1)) + 3)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- HeroIndex[(i - 1)] Equal to HeroIndex[(i - 2)]
-
Then - Actions
- Set x = (HeroIndex[(i - 1)] + (Random integer number between 1 and 23))
- Set x = (x - ((x / 25) x 24))
-
Else - Actions
- Set x = (Random integer number between 1 and 24)
-
If - Conditions
- Unit - Replace (Trained unit) with a Heros[x] using The new unit's max life and mana
- Player - Limit training of Third Random Hero to 0 for (Triggering player)
- Unit - Order (Last replaced unit) to Move To (Rally-Point of (Triggering unit) as a point)
- Set HeroIndex[i] = x
- Sound - Play Sounds[x] at 100.00% volume, attached to (Last replaced unit)
-
Events
Don't forget step 4!
example map
Last edited: