• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Player Spawning.

Status
Not open for further replies.
Level 7
Joined
Jul 1, 2012
Messages
188
Hello, I got a problem with about spawning unit's for players at semi-random locations. I already know how to spawn units at a set point.

Is it possible to make a player spawn at ONE of the three possible locations, so it is random each time. If so please supply the trigger(s) to do so. And make so two players can't spawn at the same spot.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Make a new Region variable with an array enabled, then;
  • Random Spawn
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set YourRegion[1] = First Region <gen>
      • Set YourRegion[2] = Second Region <gen>
      • Set YourRegion[3] = Third Region <gen>
      • Set TempInt = (Random integer number between 1 and 3)
      • -------- Your Random Region should be used like this: YourRegion[TempInt] --------
      • Unit - Create 1 Peasant for Player 1 (Red) at (Center of YourRegion[TempInt]) facing Default building facing degrees
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
First, you can set the regions at mao initialization, reducing redundant code. You do not need to re-set the regions every time the trigger runs.

  • Map Initialization
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set YourRegion[1] = First Region <gen>
    • Set YourRegion[2] = Second Region <gen>
    • Set YourRegion[3] = Third Region <gen>
Also, I think your trigger leaks.

  • Random Spawn
  • Events
    • Time - Eclasped time is 5 seconds.
  • Conditions
  • Actions
    • Set TempPoint = Centre of YourRegion [Region integer between 1-3]
    • Unit - Create 1 Peasant for Player 1 (Red) at TempPoint facing Default building facing degrees
    • -------- Heres your second player (if you wanted him) to spawn at the same random point as the first --------
    • Unit - Create 1 Peasant for Player 2 (Blue) at TempPoint facing Default building facing degrees
    • Custom script: call RemoveLocation (udg_TempPoint)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
You need some kind of integer variable to see how many spawn points are still available.

Hmh, I'm kinda hoping this works. Sounds all right, but it's getting late and I didn't test it at all.
(I also didn't create this in the editor, just wrote this here on the hive, so sorry if it's a bit confusing).

  • Set RandInt = (Random integer between 1 and SpawnCount)
  • -------- Create the unit --------
  • Set TempLoc = Center of Region[RandInt]
  • Unit - Create 1 Peasant for Player 2 (Blue) at TempLoc facing Default building facing degrees
  • Custom script: call RemoveLocation( udg_TempLoc )
  • -------- Make this spawn-region unavailable --------
  • Set Region[4] = Region[RandInt]
  • Set Region[RandInt] = Region[SpawnCount]
  • Set Region[SpawnCount] = Region[4]
  • Set SpawnCount = SpawnCount - 1
If the unit successfully spawned, you can just increase SpawnCount by 1 and (according to my own logic), it should work. Maybe.
Region[4] is temporary here. If you need, say, 5 different spawn locations, use "Region[6]" instead (no need to create a new variable for this).

You can also switch the unit creation with the set variable-part. The disadvantage of this is that the first spawn will always be the same (it's random after that), the advantage is that you can use waits and whatnot.
 
Last edited:
Level 7
Joined
Jul 1, 2012
Messages
188
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set YourRegionRed[1] = Red 1 <gen>
    • Set YourRegionRed[2] = Red 2 <gen>
    • Set YourRegionRed[3] = Red 3 <gen>
    • Set YourRegionBlue[1] = Blue 1 <gen>
    • Set YourRegionBlue[2] = Blue 2 <gen>
    • Set YourRegionBlue[3] = Blue 3 <gen>
    • Set YourRegionTeal[1] = Teal 1 <gen>
    • Set YourRegionTeal[2] = Teal 2 <gen>
    • Set YourRegionTeal[3] = Teal 3 <gen>
    • Set YourRegionPurple[1] = Purple 1 <gen>
    • Set YourRegionPurple[2] = Purple 2 <gen>
    • Set YourRegionPurple[3] = Purple 3 <gen>
    • Set YourRegionYellow[1] = Yellow 1 <gen>
    • Set YourRegionYellow[2] = Yellow 2 <gen>
    • Set YourRegionYellow[3] = Yellow 3 <gen>
    • Set YourRegionOrange[1] = Orange 1 <gen>
    • Set YourRegionOrange[2] = Orange 2 <gen>
    • Set YourRegionOrange[3] = Orange 3 <gen>
    • Set YourRegionGreen[2] = Green 2 <gen>
    • Set YourRegionGreen[1] = Green 1 <gen>
    • Set YourRegionGreen[3] = Green 3 <gen>
    • Set YourRegionPink[1] = Pink 1 <gen>
    • Set YourRegionPink[2] = Pink 2 <gen>
    • Set YourRegionPink[3] = Pink 3 <gen>
    • Set YourRegionGray[1] = Gray 1 <gen>
    • Set YourRegionGray[2] = Gray 2 <gen>
    • Set YourRegionGray[3] = Gray 3 <gen>
    • Set YourRegionLightBlue[1] = Light Blue 1 <gen>
    • Set YourRegionLightBlue[2] = Light Blue 2 <gen>
    • Set YourRegionLightBlue[3] = Light Blue 3 <gen>
    • Set YourRegionDarkGreen[1] = Dark Green 1 <gen>
    • Set YourRegionDarkGreen[2] = Dark Green 2 <gen>
    • Set YourRegionDarkGreen[3] = Dark Green 3 <gen>
    • Set YourRegionBrown[1] = Brown 1 <gen>
    • Set YourRegionBrown[2] = Brown 2 <gen>
    • Set YourRegionBrown[3] = Brown 3 <gen>
    • Set TempInt[1] = (Random integer number between 1 and 3)
    • Set TempInt[2] = (Random integer number between 1 and 3)
    • Set TempInt[3] = (Random integer number between 1 and 3)
    • Set TempInt[4] = (Random integer number between 1 and 3)
    • Set TempInt[5] = (Random integer number between 1 and 3)
    • Set TempInt[6] = (Random integer number between 1 and 3)
    • Set TempInt[7] = (Random integer number between 1 and 3)
    • Set TempInt[8] = (Random integer number between 1 and 3)
    • Set TempInt[9] = (Random integer number between 1 and 3)
    • Set TempInt[10] = (Random integer number between 1 and 3)
    • Set TempInt[11] = (Random integer number between 1 and 3)
    • Set TempInt[12] = (Random integer number between 1 and 3)
  • Events
    • Time - Elapsed game time is 15.00 seconds
  • Conditions
  • Actions
    • Unit - Create 4 Peasant for Player 1 (Red) at (Center of YourRegionRed[TempInt[1]]) facing Default building facing degrees
    • Camera - Pan camera for Player 1 (Red) to (Center of YourRegionRed[TempInt[1]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 2 (Blue) at (Center of YourRegionBlue[TempInt[2]]) facing Default building facing degrees
    • Camera - Pan camera for Player 2 (Blue) to (Center of YourRegionBlue[TempInt[2]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 3 (Teal) at (Center of YourRegionTeal[TempInt[3]]) facing Default building facing degrees
    • Camera - Pan camera for Player 3 (Teal) to (Center of YourRegionTeal[TempInt[3]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 4 (Purple) at (Center of YourRegionPurple[TempInt[4]]) facing Default building facing degrees
    • Camera - Pan camera for Player 4 (Purple) to (Center of YourRegionPurple[TempInt[4]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 5 (Yellow) at (Center of YourRegionYellow[TempInt[5]]) facing Default building facing degrees
    • Camera - Pan camera for Player 5 (Yellow) to (Center of YourRegionYellow[TempInt[5]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 6 (Orange) at (Center of YourRegionOrange[TempInt[6]]) facing Default building facing degrees
    • Camera - Pan camera for Player 6 (Orange) to (Center of YourRegionOrange[TempInt[6]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 7 (Green) at (Center of YourRegionGreen[TempInt[7]]) facing Default building facing degrees
    • Camera - Pan camera for Player 7 (Green) to (Center of YourRegionGreen[TempInt[7]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 8 (Pink) at (Center of YourRegionPink[TempInt[8]]) facing Default building facing degrees
    • Camera - Pan camera for Player 8 (Pink) to (Center of YourRegionPink[TempInt[8]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 9 (Gray) at (Center of YourRegionGray[TempInt[9]]) facing Default building facing degrees
    • Camera - Pan camera for Player 9 (Gray) to (Center of YourRegionGray[TempInt[9]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 10 (Light Blue) at (Center of YourRegionLightBlue[TempInt[10]]) facing Default building facing degrees
    • Camera - Pan camera for Player 10 (Light Blue) to (Center of YourRegionLightBlue[TempInt[10]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 11 (Dark Green) at (Center of YourRegionDarkGreen[TempInt[11]]) facing Default building facing degrees
    • Camera - Pan camera for Player 11 (Dark Green) to (Center of YourRegionDarkGreen[TempInt[11]]) over 2.00 seconds
    • Unit - Create 4 Peasant for Player 12 (Brown) at (Center of YourRegionBrown[TempInt[12]]) facing Default building facing degrees
    • Camera - Pan camera for Player 12 (Brown) to (Center of YourRegionBrown[TempInt[12]]) over 2.00 seconds
Mmh. It did work the first few times but after like 3-4 times everyone would just spawning at the same EXACT location every game after that.
1/3x(1/3 twelve times)=A very low chance that everyone would spawn at the exact same location, especially 2 games in a row before I decided to look into it.

(This script only runs once ingame so the bug carriers over to each game... somehow.)
 
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
I suggest using only 1 variable for the regions (called "YourRegion" or something).
YourRegion[4] = Blue 1
YourRegion[5] = Blue 2
In general: YourRegion[N + (Player Number - 1) * 3], where N is the region number.

I also don't understand how it works correctly "the first few times". It should only work the very first time.
The reason is simple:
  • Set TempInt[1] = (Random integer number between 1 and 3)
It's set to either 1, 2, or 3. You never change it.

  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set PlayerRegion[1] = Red 1 <gen>
      • Set PlayerRegion[2] = Red 2 <gen>
      • Set PlayerRegion[3] = Red 3 <gen>
      • Set PlayerRegion[4] = Blue 1 <gen>
      • Set PlayerRegion[5] = Blue 2 <gen>
      • Set PlayerRegion[6] = Blue 3 <gen>
  • Spawn
    • Events
      • Time - Elapsed game time is 15.00 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • Set TempInt = (Random integer number between (((Integer A) x 3) - 2) and ((Integer A) x 3))
          • Set TempLoc = (Center of PlayerRegion[TempInt])
          • Unit - Create 1 Footman for (Player((Integer A))) at TempLoc facing Default building facing degrees
          • Camera - Pan camera for (Player((Integer A))) to TempLoc over 0.00 seconds
          • Custom script: call RemoveLocation( udg_TempLoc )
I hope this is clear enough :).
 
Level 7
Joined
Jul 1, 2012
Messages
188
I suggest using only 1 variable for the regions (called "YourRegion" or something).
YourRegion[4] = Blue 1
YourRegion[5] = Blue 2
In general: YourRegion[N + (Player Number - 1) * 3], where N is the region number.

I also don't understand how it works correctly "the first few times". It should only work the very first time.
The reason is simple:
  • Set TempInt[1] = (Random integer number between 1 and 3)
It's set to either 1, 2, or 3. You never change it.

  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set PlayerRegion[1] = Red 1 <gen>
      • Set PlayerRegion[2] = Red 2 <gen>
      • Set PlayerRegion[3] = Red 3 <gen>
      • Set PlayerRegion[4] = Blue 1 <gen>
      • Set PlayerRegion[5] = Blue 2 <gen>
      • Set PlayerRegion[6] = Blue 3 <gen>
  • Spawn
    • Events
      • Time - Elapsed game time is 15.00 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • Set TempInt = (Random integer number between (((Integer A) x 3) - 2) and ((Integer A) x 3))
          • Set TempLoc = (Center of PlayerRegion[TempInt])
          • Unit - Create 1 Footman for (Player((Integer A))) at TempLoc facing Default building facing degrees
          • Camera - Pan camera for (Player((Integer A))) to TempLoc over 0.00 seconds
          • Custom script: call RemoveLocation( udg_TempLoc )
I hope this is clear enough :).

Wait, so the random number is only random the EXACT first time? So next game it's already set to etc. 2?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Wait, so the random number is only random the EXACT first time? So next game it's already set to etc. 2?
That's just how variables work. They store a a piece of data, not a function.

If you store "Position of (Unit)" in a variable, it will also only store the position of the unit at that moment. If the unit moves, the variable will not change with it.
That's actually the reason variables are as useful as they are :p. If they were dynamic, then a lot of new problems would arise.
 
Level 7
Joined
Jul 1, 2012
Messages
188
That's just how variables work. They store a a piece of data, not a function.

If you store "Position of (Unit)" in a variable, it will also only store the position of the unit at that moment. If the unit moves, the variable will not change with it.
That's actually the reason variables are as useful as they are :p. If they were dynamic, then a lot of new problems would arise.

Anyway possible to make the trigger pick a random location each time?
 
Level 7
Joined
Jul 1, 2012
Messages
188
  • Unit - Create 1 Footman for Player 1 (Red) at (Center of YourRegionRed[(Random integer number between 1 and 3)]) facing 188.00 degrees
Mmh I tested this trigger and it seems to work, and is much less complicated than yours. Why didn't you recommend this one? Leaks or something?
 
Status
Not open for further replies.
Top