• 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.

[Trigger] Spawn unit in random region

Status
Not open for further replies.
Level 2
Joined
Apr 5, 2008
Messages
10
READ THE WHOLE POST. THIS IS NOT AS SIMPLE AS SPAWNING A UNIT IN RANDOM REGION.

I would like to make a trigger that spawns a Unit A in a random region every X seconds (The unit is unable to move). I would like units to stop spawning in the region when the amount of Unit A's in it = 1. When number of Unit A's in region = 0, I want units to start spawning in the region.

This is what I've done - which doesn't work
  • Events
  • Time - Every X seconds of game time
  • Conditions
  • Actions
  • Set ItemChances = (Random Real number between 0.00 and 4.00)
  • If (All Conditions are True) then do (Then Actions) Else do (Else Actions)
  • If - Conditions
  • (Number of units in (Units in ItemSpawn1 <gen>)) Equal to 0
  • ItemChances Less that or equal to 1.00
  • Then - Actions
  • Unit - Create 1 Unit A for Player 9 (Gray) at (Center of ItemSpawn1 <gen>) facing Default building facing degrees
  • Else - Actions
  • If (All Conditions are True) then do (Then Actions) Else do (Else Actions)
  • If - Conditions
  • (Number of units in (Units in ItemSpawn2 <gen>)) Equal to 0
  • ItemChances Less that or equal to 2.00
  • Then - Actions
  • Unit - Create 1 Unit A for Player 9 (Gray) at (Center of ItemSpawn2 <gen>) facing Default building facing degrees
  • Else - Actions
This trigger continues for every region I want a Unit A to spawn.

Problem: When the game starts, every X seconds a Unit A is spawned in a random region until all regions have one Unit A. Unit B (which is controlled by player) moves around the map killing Unit A's. After Unit A is killed, another Unit A will never re-spawn in it's place even though (Number of units in (Units in ItemSpawn <gen>)) Equal to 0.
 
Last edited:
Level 4
Joined
Mar 19, 2008
Messages
89
Well, this is not the best way, it is not the most efficient way, but it works really well and no one else has replied so here is my answer:
first create 5 regions

second create a variable called random

third create a variable called region

fourth create a trigger called set region with the following functions
  • Set region
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Set Random = (Random integer number between 1 and 5)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random Equal to 1
        • Then - Actions
          • Set Region = 1 <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random Equal to 2
        • Then - Actions
          • Set Region = 2 <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random Equal to 3
        • Then - Actions
          • Set Region = 3 <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random Equal to 4
        • Then - Actions
          • Set Region = 4 <gen>
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random Equal to 5
        • Then - Actions
          • Set Region = 5 <gen>
        • Else - Actions
fifth create a trigger called make units with the following functions
  • units random create
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of Region) facing Default building facing degrees
sixth make a trigger with a visibility modifier for the whole map, that way you can see if it works(which it does, I tested it.

  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Visibility across (Playable map area)
Hope this helps, If I wanted to create a random unit spawning region type thing mo bober this is what I would use!
 
Level 20
Joined
Oct 21, 2006
Messages
3,230
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Region[1] = Region 000 <gen>
      • Set Region[2] = Region 001 <gen>
      • Set Region[3] = Region 002 <gen>
  • Untitled Trigger 002
    • Events
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of Region[(Random integer number between 1 and 3)]) facing Default building facing degrees
 
Level 2
Joined
Apr 5, 2008
Messages
10
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Region[1] = Region 000 <gen>
      • Set Region[2] = Region 001 <gen>
      • Set Region[3] = Region 002 <gen>
  • Untitled Trigger 002
    • Events
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of Region[(Random integer number between 1 and 3)]) facing Default building facing degrees

Getting a unit to spawn in a random region is the easy part. I want the trigger to check if there's a Unit A (unit spawned by trigger) in the region and if there is, the trigger wont spawn anymore units in that region until the unit in region is killed.

Hope that makes sense.
 
Level 4
Joined
Feb 2, 2009
Messages
71
  • Set Variables
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Region[0] = Region 000 <gen>
      • Set Region[1] = Region 001 <gen>
      • Set Region[2] = Region 002 <gen>
      • Set Region[3] = Region 003 <gen>
  • Random Region
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
      • (Number of units in (Units in Region[RandomInteger])) Equal to 0
    • Actions
      • Set RandomInteger = (Random integer number between 0 and 3)
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of Region[RandomInteger]) facing Default building facing degrees
I think this will do what you're looking for. It first checks if the last random region is still "inhabited". If it's not, it spawns a unit in random region.
Should work like the runes currently does in DotA.
 
Last edited:
Status
Not open for further replies.
Top