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

[Solved] Get nearby spawn point

Status
Not open for further replies.
Level 14
Joined
Oct 16, 2010
Messages
749
Hi,

So I've hit a bit of an issue in a map.... There's loads of regions that enemies can spawn in but I want them to spawn close to the player(s). My logic is to get the players point (TempPoint) and then get a random point from a spawn (TempPoint3), then if the distance between these is higher than how close I want them to spawn then run through all the spawn points and basically do the same thing. However it's working for the most part but sometimes no spawn point is getting picked and therefore the unit isn't being spawned at all (BIG ISSUES!)

The "Spawn Zombie" trigger is run from a different trigger and the "Get Spawn Point" trigger is run from "Spawn Zombie". Anyone got an idea what I'm doing wrong? (Sorry I can't seem to get the triggers posted properly with the new site!)

  • Spawn Zombie
    • Events
    • Conditions
    • Actions
      • Trigger - Run Get Spawn Point <gen> (checking conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to RoundNumber
          • RoundNumber Greater than or equal to 25
        • Then - Actions
          • Unit - Create 1 Zombie (6) for Player 12 (Brown) at TempPoint3 facing Default building facing degrees
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 80) Less than or equal to RoundNumber
              • RoundNumber Greater than or equal to 20
            • Then - Actions
              • Unit - Create 1 Zombie (5) for Player 12 (Brown) at TempPoint3 facing Default building facing degrees
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Random integer number between 1 and 60) Less than or equal to RoundNumber
                  • RoundNumber Greater than or equal to 15
                • Then - Actions
                  • Unit - Create 1 Zombie (4) for Player 12 (Brown) at TempPoint3 facing Default building facing degrees
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Random integer number between 1 and 40) Less than or equal to RoundNumber
                      • RoundNumber Greater than or equal to 10
                    • Then - Actions
                      • Unit - Create 1 Zombie (3) for Player 12 (Brown) at TempPoint3 facing Default building facing degrees
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Random integer number between 1 and 20) Less than or equal to RoundNumber
                          • RoundNumber Greater than or equal to 5
                        • Then - Actions
                          • Unit - Create 1 Zombie (2) for Player 12 (Brown) at TempPoint3 facing Default building facing degrees
                        • Else - Actions
                          • Unit - Create 1 Zombie (1) for Player 12 (Brown) at TempPoint3 facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_TempPoint3)
      • Unit Group - Add (Last created unit) to ZombieGroup
      • Unit - Set the custom value of (Last created unit) to (Player number of (Owner of (Random unit from SurvivorGroup)))
      • -------- Hp Buffs --------
      • For each (Integer HpGainLoop) from 1 to HpBonus_10000, do (Actions)
        • Loop - Actions
          • Unit - Add Life Bonus (+10000) to (Last created unit)
          • Unit - Set level of Life Bonus (+10000) for (Last created unit) to 2
          • Unit - Remove Life Bonus (+10000) from (Last created unit)
      • For each (Integer HpGainLoop) from 1 to HpBonus_1000, do (Actions)
        • Loop - Actions
          • Unit - Add Life Bonus (+1000) to (Last created unit)
          • Unit - Set level of Life Bonus (+1000) for (Last created unit) to 2
          • Unit - Remove Life Bonus (+1000) from (Last created unit)
      • For each (Integer HpGainLoop) from 1 to HpBonus_100, do (Actions)
        • Loop - Actions
          • Unit - Add Life Bonus (+100) to (Last created unit)
          • Unit - Set level of Life Bonus (+100) for (Last created unit) to 2
          • Unit - Remove Life Bonus (+100) from (Last created unit)
      • For each (Integer HpGainLoop) from 1 to HpBonus_10, do (Actions)
        • Loop - Actions
          • Unit - Add Life Bonus (+10) to (Last created unit)
          • Unit - Set level of Life Bonus (+10) for (Last created unit) to 2
          • Unit - Remove Life Bonus (+10) from (Last created unit)
      • For each (Integer HpGainLoop) from 1 to HpBonus_1, do (Actions)
        • Loop - Actions
          • Unit - Add Life Bonus (+1) to (Last created unit)
          • Unit - Set level of Life Bonus (+1) for (Last created unit) to 2
          • Unit - Remove Life Bonus (+1) from (Last created unit)

  • Get Spawn Point
    • Events
    • Conditions
    • Actions
      • Set TempPoint = (Position of (Random unit from SurvivorGroup))
      • Set TempPoint3 = (Center of SpawnZone[(Random integer number between 1 and SpawnZoneMax)])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between TempPoint and TempPoint3) Greater than 5000.00
        • Then - Actions
          • For each (Integer SpawnPointLoop) from 1 to SpawnZoneMax, do (Actions)
            • Loop - Actions
              • Set TempPoint2 = (Center of SpawnZone[SpawnPointLoop])
              • Set TempReal = (Distance between TempPoint and TempPoint2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TempReal Less than or equal to 5000.00
                • Then - Actions
                  • Custom script: call RemoveLocation(udg_TempPoint3)
                  • Set TempPoint3 = TempPoint2
                • Else - Actions
              • Custom script: call RemoveLocation(udg_TempPoint2)
        • Else - Actions
      • Game - Display to (All players) the text: (String((Distance between TempPoint and TempPoint3)))
      • Custom script: call RemoveLocation(udg_TempPoint)
 
Last edited by a moderator:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
Each spawn point should be added to a list of spawn points. Then periodically search the list for appropriate spawn points, placing references to the spawn point in another temporary list. The search can be for all spawn points within X distance, with a minimum of 3 nearest spawn points if that does not return enough. One can then randomly select an element of that temporary list to be the spawn point to spawn at. The 3 nearest spawn points guarantees that there is always a spawn point to spawn at, even if it is not optimally close. This can be a good thing as it means that zombie spawning behaviour is slightly less predictable and they will come from other places not just the very closest spawn point, while still being near the player for optimum map performance.

Another approach could be to forgo spawn points entirely and instead spawn units outside player LoS. This gives the illusion the unit came from somewhere where in reality it was created on demand right nearby the player, just where they could not see. If the spawned units get too far away from the player they can be either removed or teleported to a spawn position to prevent them having to cross the entire map.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Another thing to note is that your current method, by nature of looping via index, preferentially selects closer spawn points that are lower in index. For example even if rect[3] is closest, as long as rect[2] is close enough 3 will never be chosen. This is solved in Dr Super Good's method.
 
Level 14
Joined
Oct 16, 2010
Messages
749
Sorry if I'm being a pain, I understand what you mean but I honestly don't know how to put it in a trigger. I have to make it support up to 4 players (Those are in Survivor Group) so I'm just getting confused.

Throughout the map there are set regions that enemies spawn in, as you open different areas of the map these regions get added to the index and the index goes up. So the regions won't be in the same order everytime you play it, that depends what route you take. I know how to get the closest point, but I'm lost on how to get a selection of close points? If I pick a specific hero and get the location of them, how do I then get the closest 3-5 spawn regions? I'm rather confused here!!!

EDIT: Seem to have managed to work it out... Thanks for the help!
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
  1. Get location of the player/players you want to spawn near (however)
  2. Loop through all active spawn zones and check if their distance to the target point is < THRESHOLD; if so add its index to an array and increment some sort of temp counter variable
  3. Pick a random index from the list of 'close enough' indexes, and set TempPoint to be the center of that chosen region
  • Set TargetPoint = whatever()
  • Set RandSpawnCount = 0
  • For each (integer A) from 1 to NUM_SPAWNS do (actions)
    • Loop - Actions
      • Set TempPoint = Center of SpawnRegions[(integer A)]
      • If (conditions) then (actions) else (actions)
        • If - Conditions
          • Distance between TempPoint and TargetPoint <= THRESHOLD
        • Then - Actions
          • Set RandSpawn[RandSpawnCount] = (Integer A)
          • set RandSpawnCount = RandSpawnCount + 1
        • Else - Actions
      • Custom Script: call RemoveLocation(udg_TempPoint)
  • Set SpawnPoint3 = Center of SpawnRegions[RandSpawn[(Random integer from 1 to RandSpawnCount)]]
 
Level 14
Joined
Oct 16, 2010
Messages
749
I've currently got them to spawn in the 3 closest spawns which does work. I might try the threshold idea as I'm intending to have lots of spawn areas nearby anyway and it'd make a bit more variety (and less chaos........)

Will give it a go when I'm home!
 
Status
Not open for further replies.
Top