• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Random Unit

Status
Not open for further replies.
Level 3
Joined
Nov 28, 2010
Messages
42
Hello!

Im trying to create an Item that when you use it spawns 1 out of 5 Units choosen randomly.

But when i use the Item nothing happens.

I created a Real Variable named ItemUnitCreator



I dont know what the problem is. Im a noob in triggering so i hope you can help me.

Thank you for reading my thread!


  • Random Unit Creator
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Unit Creator
    • Actions
      • Set ItemUnitCreator = (Random real number between 1.00 and 5.00)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ItemUnitCreator Equal to 1.00
        • Then - Actions
          • Unit - Create 1 Footman for (Owner of (Hero manipulating item)) at (Center of (Playable map area)) facing Default building facing degrees
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ItemUnitCreator Equal to 2.00
            • Then - Actions
              • Unit - Create 1 Knight for (Owner of (Hero manipulating item)) at (Center of (Playable map area)) facing Default building facing degrees
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ItemUnitCreator Equal to 3.00
                • Then - Actions
                  • Unit - Create 1 Priest for (Owner of (Hero manipulating item)) at (Center of (Playable map area)) facing Default building facing degrees
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ItemUnitCreator Equal to 4.00
                    • Then - Actions
                      • Unit - Create 1 Rifleman for (Owner of (Hero manipulating item)) at (Center of (Playable map area)) facing Default building facing degrees
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ItemUnitCreator Equal to 5.00
                        • Then - Actions
                          • Unit - Create 1 Spell Breaker for (Owner of (Hero manipulating item)) at (Center of (Playable map area)) facing Default building facing degrees
                        • Else - Actions
 
Change your ItemUnitCreator variable's type to integer, because when you are using real you are randomly getting an integer between 1.00 and 5.00, not 1 and 5.So you can get numbers like 2.63, 3.76 etc...You aren't much likely going to get 1,2,3,4,5.
 
You can make your trigger much more effiecient by array usage:
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • UnitTypes[0] = Footman
    • UnitTypes[1] = Knight
    • UnitTypes[2] = Priest
    • UnitTypes[3] = Rifleman
    • UnitTypes[4] = Spellbreaker
Now, the actuall trigger:
  • Events
    • Unit - A unit Uses an item
  • Conditions
    • (Item-type of (Item being manipulated)) Equal to Unit Creator
  • Actions
    • Set tempLoc = (Center of (Playable map area))
    • Unit - Create 1 UnitTypes[(Random integer number between 0 and 4)] for (Triggering player) at tempLoc facing Default building facing degrees
    • Custom script: call RemoveLocation(udg_tempLoc)
I recommend you Things that leak and a visit at Tutorial -> GUI/Triggers section for basic and advanced knowledge related to GUI triggers inside WE.
 
Status
Not open for further replies.
Back
Top