• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Random trigger explained

Level 4
Joined
Oct 9, 2024
Messages
63
Hello everyone, I'm a new map creator and I'm having a problem with the editor. My goal is to create a skill that randomly summons an elemental for my shaman hero. It's a command with 1d4 options, randomly summoning a fire, water, air or earth elemental. I already have the models and all the balancing done, but I'm having problems making the trigger. I just don't understand how I should use the option so that when my shaman uses magic he randomly summons one of the elementals. I humbly ask for help with the trigger.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Hello Teldrin, so what you want to accomplish is pretty simple and a good project for someone just starting out. You just have to remember that Warcraft 3 has a ton of different mechanics, so the solution to any given problem will depend based on your specific needs. Also, there's many solutions to a problem, all with their own pros and cons.

With that in mind, let's look at some of the different types of summoning skills so that you can decide how you want your skill to function:

- Summon Water Elemental: Instant ability (no targeting), Summons 1 unit (I think you can modify this), and new summons do NOT replace old summons.
- Summon Serpent Ward: Target point ability, Summons 1 unit (I know you can modify this), and new summons do NOT replace old summons.
- Feral Spirit: Instant ability, Summons 2 units, and new summons replace old summons.

So the key mechanics are: Targeting, Summon Count, and most importantly the Replace mechanic which can add some extra complexity to your trigger(s). Using those examples as a reference, please explain to us exactly what you want to accomplish and how everything should work.


In the meantime, here's how I would design this custom "Summon Random Elemental" skill, assuming that it's like the Summon Water Elemental skill:

1) In the Object Editor, under Units, copy and paste the Archmage's Water Elemental (Level 1). Rename it to "Random Elemental".
2) In the Object Editor, under Units, copy and paste the Archmage's Water Elemental and create a Fire/Water/Air/Earth version for each Level.
3) In the Object Editor, under Abilities, copy and paste the Summon Water Elemental ability and change it's Summoned Unit-Type to our "Random Elemental" for ALL Levels.
4) In the Trigger Editor, create 6 new Variables. These should be their names and (variable types):
Random_Elemental_RNG (Integer)
Random_Elemental_LVL (Integer)
Random_Elemental_Fire (Unit-Type, Array)
Random_Elemental_Water (Unit-Type, Array)
Random_Elemental_Air (Unit-Type, Array)
Random_Elemental_Earth (Unit-Type, Array)

5) In the Trigger Editor, create two new triggers. The first will look like this:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Set Variable Random_Elemental_Fire[1] = Fire Elemental (Level 1)
    • Set Variable Random_Elemental_Fire[2] = Fire Elemental (Level 2)
    • Set Variable Random_Elemental_Fire[3] = Fire Elemental (Level 3)
    • Set Variable Random_Elemental_Water[1] = Water Elemental (Level 1)
    • Set Variable Random_Elemental_Water[2] = Water Elemental (Level 2)
    • Set Variable Random_Elemental_Water[3] = Water Elemental (Level 3)
    • Set Variable Random_Elemental_Air[1] = Air Elemental (Level 1)
    • Set Variable Random_Elemental_Air[2] = Air Elemental (Level 2)
    • Set Variable Random_Elemental_Air[3] = Air Elemental (Level 3)
    • Set Variable Random_Elemental_Earth[1] = Earth Elemental (Level 1)
    • Set Variable Random_Elemental_Earth[2] = Earth Elemental (Level 2)
    • Set Variable Random_Elemental_Earth[3] = Earth Elemental (Level 3)
^ This is our setup trigger, it handles tracking the data for our custom skill. This should happen before anyone has actually had the chance to use the skill which is why the Event occurs at the 0 second mark. In this case, I am tracking the different types of Units we can summon at the different skill [levels].
[1] = Level 1, [2] = Level 2, [3] = Level 3, etc.

The second trigger will look like this:
  • Events
    • Unit - A unit Spawns a summoned unit
  • Conditions
    • (Unit-type of (Summoned unit)) Equal to Random Elemental
  • Actions
    • Set Variable Random_Elemental_RNG = (Random integer number between 1 and 4)
    • Set Variable Random_Elemental_LVL = (Level of (Summon Random Elemental) for (Summoning unit))
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Random_Elemental_RNG Equal to 1
      • Then - Actions
        • Unit - Replace (Summoned unit) with a Random_Elemental_Fire[Random_Elemental_LVL] using The new unit's default life and mana
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Random_Elemental_RNG Equal to 2
      • Then - Actions
        • Unit - Replace (Summoned unit) with a Random_Elemental_Water[Random_Elemental_LVL] using The new unit's default life and mana
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Random_Elemental_RNG Equal to 3
      • Then - Actions
        • Unit - Replace (Summoned unit) with a Random_Elemental_Air[Random_Elemental_LVL] using The new unit's default life and mana
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Random_Elemental_RNG Equal to 4
      • Then - Actions
        • Unit - Replace (Summoned unit) with a Random_Elemental_Earth[Random_Elemental_LVL] using The new unit's default life and mana
      • Else - Actions
    • Unit - Add a 60.00 second Generic expiration timer to (Last replaced unit)
    • Unit - Add classification of Summoned to (Last replaced unit)
^ This is our summon trigger, it handles the logic for creating the random elemental.

In this case, I am detecting when a Random Elemental is summoned and immediately replacing it with one of the four types of elementals. The outcome is based on the random number that was rolled and stored in the RNG variable as well as the ability LVL variable that was set prior. These variables help determine if it should summon a Level 1 Fire elemental or a Level 3 Air elemental. Since this all happens immediately the user will never be able to see or interact with the "base" Random Elemental that gets replaced. To clarify, Replacing removes the original unit from the game and creates a new unit in it's place.

I also add a 60 second expiration timer as well as the Summoned classification to the new elemental, which means it'll die after 60 seconds and will be treated like a Summon (weak to dispel, etc). These are optional of course but are the same settings that the standard Summon Water Elemental ability uses.


Notes:
  • Ability and Skill are the same thing. A Skill just implies that it's learned from the Hero Skill Menu but it's technically still an Ability.
  • Variables have a checkbox called "Array" which you need to check on for the Fire/Water/Air/Earth variables. The Array option is very useful since it allows a single variable to track multiple values at once. You should be using this feature often!
  • If you can't find an Action then try using the Search For Text option, but be careful with your syntax, it's extremely picky.
  • Almost everything in the Trigger Editor is organized alphabetically and categorically. Try to use word association to find what you're looking for, IE: Looking at my above trigger, the "Replace" Action has the prefix Unit which tells us that you can find it under the Unit category. The Condition "Random_Elemental_RNG Equal to 1" is checking if a value is equal to 1, and we know that both the variable and the value 1 are Integers therefore it can be found under the Integer category.
  • Another tip, if something is wrapped in (parenthesis) then we know that it can be found under the Functions dropdown menu.
  • You can change the names of the Units/Abilities/Variables if you'd like, this is just what I decided to call things.
 
Last edited:
Level 4
Joined
Oct 9, 2024
Messages
63
I appreciate the answer, I'm a newbie so I don't understand some basic concepts, my goal is to create a Shaman hero capable of summoning totems and elementals in addition to placing elements on his weapons, I started with the concept of the random elemental to learn a few things, but in the future what I'm looking to do is an ability similar to what the peasant has with his buildings, a button called summon elemental that when clicked takes you to an options screen to summon elementals, similar to what the peasant does with the button to create buildings, I still have a long way to go and I would appreciate it if you could send me the link to a more complete video or tutorial on how to make triggers.
That said, I have a few questions about your last explanation, the checkbox called "Array" has a number right next to it, what does that mean? and the other number right below it says the initial value.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I appreciate the answer, I'm a newbie so I don't understand some basic concepts, my goal is to create a Shaman hero capable of summoning totems and elementals in addition to placing elements on his weapons, I started with the concept of the random elemental to learn a few things, but in the future what I'm looking to do is an ability similar to what the peasant has with his buildings, a button called summon elemental that when clicked takes you to an options screen to summon elementals, similar to what the peasant does with the button to create buildings, I still have a long way to go and I would appreciate it if you could send me the link to a more complete video or tutorial on how to make triggers.
Here's a tutorial I suggest to people. Though, I've never actually read through it all.
There's some other useful links in my signature as well.

You can use the Spellbook ability for the multi-elemental menu. This ability acts like a folder that opens up to a list of other abilities.

Anyway, before I answer your two questions, first you need to understand how Arrays work. Arrays allow a variable to store multiple values by taking advantage of what's known as an [index]. The index is the number contained within the [brackets] and must be an Integer value ranging from 0 to 32768. What this allows you to do is essentially transform your normal variable into a sort of list, you can think of it like a grocery list, in which you can number and store each different item:
  • Actions
    • Set Variable MyArrayVariable[1] = Grunt
    • Set Variable MyArrayVariable[2] = Footman
    • Set Variable MyArrayVariable[500] = Knight
^ In this example I've stored the Grunt at index [1], the Footman at index [2], and the Knight at index [500]. The pattern in which you store things is entirely up to you, and there's often many creative ways of taking advantage of an [index] since it can really represent just about anything.


That said, I have a few questions about your last explanation, the checkbox called "Array" has a number right next to it, what does that mean? and the other number right below it says the initial value.
1) The Array Size limits the maximum number of values that you can store in that variable. You can keep it at the default Size of 1 for almost all of the variable types because most variables are designed to adjust their Size as needed. Arrays have a Size limit of 32,768 that you cannot go beyond no matter what.

In other words, this would work fine:
  • Unit - Create 1 Footman...
  • Set Variable SomeUnitArray[32768] = (Last created unit)
But this would NOT work since our [index] has gone beyond the maximum Size limit:
  • Unit - Create 1 Footman...
  • Set Variable SomeUnitArray[999999] = (Last created unit)
The only variable types that require Size adjustments are: Unit Groups, Player Groups, Timers, and one or two that I cannot remember. There's some special techniques you can use to avoid having to adjust the Size but I wouldn't worry about that just yet. Oh and there's a bug that prevents you from adjusting the Size outside of the Variable Editor. I recommend only modifying your variables inside of that menu to avoid issues.


2) Initial value is the starting value that the variable will have by default. I hardly ever need to use this but it can come in handy in some situations. For example, if I were to create an Integer variable called StartingAmount and set it's Initial value to 12345, this trigger would give me 12345 Gold at the start of the game:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Player - Add StartingAmount to Player 1 (Red) Current gold
If the variable is an Array then each [index] will have that starting value.
 
Last edited:
Level 4
Joined
Oct 9, 2024
Messages
63
Simply incredible, with a lot of difficulty and testing I managed to make the trigger work well, now I would like to make another one for the hero, an ability that is like a buff, whether in the area or on a target that increases attributes, I thought of something like Mark of the Wild from WOW, it seems perfect to me, I don't know if I should ask this here or open a new topic.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Simply incredible, with a lot of difficulty and testing I managed to make the trigger work well, now I would like to make another one for the hero, an ability that is like a buff, whether in the area or on a target that increases attributes, I thought of something like Mark of the Wild from WOW, it seems perfect to me, I don't know if I should ask this here or open a new topic.
You should make a new thread, it would help garner attention from other people.

Now I'm being nitpicky here, but I would suggest making it more clear on how the Mark ability-targeting works, because no native ability in Warcraft can target an Area OR a Unit. Or maybe you meant that you want to learn how to create both. Also, I wouldn't use the word "target" to describe a Unit since it's a bit vague. You either target a Point or a Unit, and when targeting a Point you can have an Area of Effect (the ring that appears when aiming an ability like Blizzard or Flame Strike) which represents the radius in which it'll affect multiple Units.

Of course, just about anything is possible with triggers so I'm not saying that this can't be done. I'm just suggesting that you explain things in Warcraft 3 terms that are easy to understand. "I want to create an ability like Bloodlust, but it can only target Heroes and increases their Attributes during the buff. Also, I want another version of the ability that can target an Area and apply the buff to all allied Heroes inside."
 
Last edited:
Level 4
Joined
Oct 9, 2024
Messages
63
Archimonde portal actually calls random units, it's a fun spell I must say, but I didn't find in its data a way to set a time limit for the summoned units, they are called and last forever with me being able to summon more.Attach files
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
  • Events
    • Unit - A unit spawns a summoned unit
  • Conditions
    • Or - Any condition is true
      • Conditions
        • (Unit-type of (Summoned Unit)) equal to Earth Elemental
        • (Unit-type of (Summoned Unit)) equal to Air Elemental
        • (Unit-type of (Summoned Unit)) equal to Fire Elemental
        • (Unit-type of (Summoned Unit)) equal to Water Elemental
  • Actions
    • Unit - Add a (15.00 + (15.00 x (Level of YOURABILITY for (Triggering Unit)))) second Generic expiration timer to (Summoned Unit) //15s + 15s per level duration for example
I guess it's possible that that spell doesn't count as an actual summon since they have no duration so maybe it doesn't even fire that event. You could do it with a Unit Enters (Playable Map Area) event instead but that wouldn't allow you to scale with the spell level. At this point it's not much different that simply spawning the correct elemental with triggers as Uncle showed. But it almost saves time and effort.
 
Top