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

Request: Trigger to Randomly spawn Unit

Status
Not open for further replies.
Level 4
Joined
Jul 14, 2012
Messages
100
Okay so in my map I want the game to start where everyone gets a Settler but at a randomly spawned location(the reason why I ask now is because I had it really low priority, but apparently some people have informed me that it shouldnt be).

I still want the locations to be preset regions, like there are a number of potential spawning regions. Yet each player spawns in a random one, but never in the same one.
 
Level 5
Joined
Aug 8, 2012
Messages
154
Hey

I have something very similar to that in my zombie map currently. The basics of it are: You have a region variable, and have a periodic trigger set that sets an integer variable as a different number every second or 0.1 seconds of gametime. Then you can set a different region for every different number of that integer variable, so the region that is chosen changes every set amount of time.

For example:

- Every (0.1) second of time

- Set (IntegerVariable) as a random number between 1 and 5

- If (all conditions) are true, then do (actions):
- If (Integer Varialbe) is equal to 1, set (Regionvariable) as <Yourpresetregion1>.

- If (all conditions) are true, then do (actions):
- If (Integer Varialbe) is equal to 2, set (Regionvariable) as <Yourpresetregion2>.

etc...

And then have a seperate spawn trigger that goes something like this:

-Map initialization

-Spawn 1 (Settler) for Player 1 Red at (Regionvariable)
-Wait 0.1 seconds
-Spawn 1 (Settler) for Player 2 Blue at (Regionvariable)
-Wait 0.1 seconds
-Spawn 1 (Settler) for Player 3 Blue at (Regionvariable)

etc, for all the other players. The wait time has to be the same as the periodic timer in the first trigger. This way, the settlers will spawn 0.1 seconds apart (if that's alright), and they will spawn in a random region from a selection chosen by you in the first trigger.

The only problem with these triggers is that it is possible for two settlers to spawn in the same region, though I will try and mess around with some conditions to see if I can stop that from happening.

Hope that helped!
 
Level 4
Joined
Jul 14, 2012
Messages
100
Ah, I was considering something like that except combined within the same trigger. Like instead of having the wait, have the Set random integer following the last spawn before spawning the next unit. But i had the same problem with spawning in the same location :/

Anyone else got any ideas?
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Ok so you'll need 2 triggers (for neatness), both that run at map init.

First:
Set spawnRegion[1] = one of your spawn regions
Set spawnRegion[2] = the next spawn region
etc
Keep note of the last number you used, maybe set it to a variable, let's call it spawnId.

Then:
Pick every player in all players
{ Set pickedRegion (integer) = random integer between 1 and spawnId
Spawn player at spawnRegion[spawnId]
//now here's the tricky part, we are going to rearrange the spawn triggers.
For each integer A from (pickedRegion) to (spawnId - 1)
{ set spawnRegion[integer A] = spawnRegion[integer A + 1] }
Set spawnId = spawnId - 1 //since we have 1 less spawn region
}

So what this trigger will do:
spawn player 1 at a random region
remove the region player 1 spawned at from the list by moving all the spawn regions after it in the list down
spawn player 2 at a new random region
etc

Let me know if I need to explain it better. The trigger would be easy enough to make, but I think for your own sake you should understand it :)
 
Level 4
Joined
Jul 14, 2012
Messages
100
Ok so you'll need 2 triggers (for neatness), both that run at map init.

First:
Set spawnRegion[1] = one of your spawn regions
Set spawnRegion[2] = the next spawn region
etc
Keep note of the last number you used, maybe set it to a variable, let's call it spawnId.

Then:
Pick every player in all players
{ Set pickedRegion (integer) = random integer between 1 and spawnId
Spawn player at spawnRegion[spawnId]
//now here's the tricky part, we are going to rearrange the spawn triggers.
For each integer A from (pickedRegion) to (spawnId - 1)
{ set spawnRegion[integer A] = spawnRegion[integer A + 1] }
Set spawnId = spawnId - 1 //since we have 1 less spawn region
}

So what this trigger will do:
spawn player 1 at a random region
remove the region player 1 spawned at from the list by moving all the spawn regions after it in the list down
spawn player 2 at a new random region
etc

Let me know if I need to explain it better. The trigger would be easy enough to make, but I think for your own sake you should understand it :)

I understood up to here:

{ set spawnRegion[integer A] = spawnRegion[integer A + 1] }

It sounds like spawn region[1]=spawn region[2]=spawn region[3]..

So in every game, the spawn location for each player is still the same???
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Ok so you have
spawnRegion[1]
spawnRegion[2]
spawnRegion[3]
spawnRegion[4]
spawnRegion[5]
spawnRegion[6]

Player 1 gets a random spawn region (using a number between 1 and 6), say spawnRegion[3]. He spawns, and then spawnRegion[4] takes spawnRegion[3]'s variable, 5 takes 4, and so on.

So now you have:
spawnRegion[1]
spawnRegion[2]
spawnRegion[4], which is now called spawnRegion[3]
spawnRegion[5], which is now called spawnRegion[4]
spawnRegion[6], which is now called spawnRegion[5]

Now player 2 gets a random spawn region (using a number between 1 and 5), and the rest happens as with player 1.
 
Level 4
Joined
Jul 14, 2012
Messages
100
Ohhh okay okay. Let me try to construct the trigger then, using your idea. May take me some time. I'm a bit slow working around this sort of thing. I'll try to come up with something by tomorrow and let you know! ^^ Thanks a bunch!
 
Status
Not open for further replies.
Top