• 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] Random Spawns Within Region but not water?

Status
Not open for further replies.
Level 5
Joined
Feb 5, 2021
Messages
89
Greetings to the people of HIVE Workshop

I have run into a problem since i have a map that looks like this:
memaplooksliekdis.PNG

(Its blue cause of the region i made across everything in it)

I would really love it if the trigger could do something like this

Mob dies - checks what mob - respawns the mob somewhere randomly in the region on land (making sure no mob is spawned in the water)

i have gotten something to work in a previous try but i ended up giving up the idea and just going with another map layout, this time im hoping for some expert advice.

BTW, i consider myself a beginner in triggers and variables

- Ruvven
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
This will prevent a creep from spawning in DEEP water. It won't prevent Shallow Water spawning but can be adjusted to do that as well.
  • Setup Respawn
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- If all of the attempts to spawn the unit ended up in water, give up and instead spawn the unit in one of your "safe regions". --------
      • Set VariableSet Spawn_SafeRegion[1] = Safe1 <gen>
      • Set VariableSet Spawn_SafeRegion[2] = Safe2 <gen>
      • Set VariableSet Spawn_SafeRegion[3] = Safe3 <gen>
      • Set VariableSet Spawn_SafeRegion[4] = Safe4 <gen>
      • -------- --------
      • -------- Make sure to set this value to however many "safe regions" you have! --------
      • Set VariableSet Spawn_TotalSafeRegions = 4
  • Respawn Creep
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • -------- Increasing this number improves the odds that a unit ends up in a random non-water spot. This can hurt performance if it's too high. --------
      • Set VariableSet Spawn_Attempts = 10
      • -------- --------
      • Set VariableSet Spawn_Success = False
      • For each (Integer Spawn_Loop) from 1 to Spawn_Attempts, do (Actions)
        • Loop - Actions
          • Set VariableSet Spawn_Point = (Random point in (Playable map area))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain pathing at Spawn_Point of type Floatability is off) Equal to True
              • (Terrain pathing at Spawn_Point of type Walkability is off) Equal to False
            • Then - Actions
              • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
              • Custom script: call RemoveLocation (udg_Spawn_Point)
              • Set VariableSet Spawn_Success = True
              • Custom script: exitwhen udg_Spawn_Success
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spawn_Loop Equal to Spawn_Attempts
                • Then - Actions
                  • -------- If all of the attempts to spawn the unit ended up in water, give up and instead spawn the unit in one of your "safe regions". --------
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
                  • Set VariableSet Spawn_Point = (Random point in Spawn_SafeRegion[(Random integer number between 1 and Spawn_TotalSafeRegions)])
                  • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
                  • Set VariableSet Spawn_Success = True
                  • Custom script: exitwhen udg_Spawn_Success
                • Else - Actions
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
 

Attachments

  • Respawn Creeps Water.w3m
    27.6 KB · Views: 16
Level 5
Joined
Feb 5, 2021
Messages
89
This will prevent a creep from spawning in DEEP water. It won't prevent Shallow Water spawning but can be adjusted to do that as well.
  • Setup Respawn
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- If all of the attempts to spawn the unit ended up in water, give up and instead spawn the unit in one of your "safe regions". --------
      • Set VariableSet Spawn_SafeRegion[1] = Safe1 <gen>
      • Set VariableSet Spawn_SafeRegion[2] = Safe2 <gen>
      • Set VariableSet Spawn_SafeRegion[3] = Safe3 <gen>
      • Set VariableSet Spawn_SafeRegion[4] = Safe4 <gen>
      • -------- --------
      • -------- Make sure to set this value to however many "safe regions" you have! --------
      • Set VariableSet Spawn_TotalSafeRegions = 4
  • Respawn Creep
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • -------- Increasing this number improves the odds that a unit ends up in a random non-water spot. This can hurt performance if it's too high. --------
      • Set VariableSet Spawn_Attempts = 10
      • -------- --------
      • Set VariableSet Spawn_Success = False
      • For each (Integer Spawn_Loop) from 1 to Spawn_Attempts, do (Actions)
        • Loop - Actions
          • Set VariableSet Spawn_Point = (Random point in (Playable map area))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain pathing at Spawn_Point of type Floatability is off) Equal to True
              • (Terrain pathing at Spawn_Point of type Walkability is off) Equal to False
            • Then - Actions
              • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
              • Custom script: call RemoveLocation (udg_Spawn_Point)
              • Set VariableSet Spawn_Success = True
              • Custom script: exitwhen udg_Spawn_Success
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spawn_Loop Equal to Spawn_Attempts
                • Then - Actions
                  • -------- If all of the attempts to spawn the unit ended up in water, give up and instead spawn the unit in one of your "safe regions". --------
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
                  • Set VariableSet Spawn_Point = (Random point in Spawn_SafeRegion[(Random integer number between 1 and Spawn_TotalSafeRegions)])
                  • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
                  • Set VariableSet Spawn_Success = True
                  • Custom script: exitwhen udg_Spawn_Success
                • Else - Actions
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
This is ... This is incredible! and this is so complicated with so many variables and that would explain why i could never get anything simple to work!
Thank you very much! also it is only deep water that i am having trouble with since i have no shallow water, yet atleast but thank you very much!

I cant wait to try this!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,871
No problem!

So I edited one of the triggers to be slightly more efficient and attached the map below:
  • Respawn Creep
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • -------- Increasing this number improves the odds that a unit ends up in a random non-water spot. This can hurt performance if it's too high. --------
      • Set VariableSet Spawn_Attempts = 10
      • -------- --------
      • -------- This next set of actions creates points at random places in the region until it finds one that isn't in Deep Water. --------
      • -------- If after X attempts you somehow got really unlucky and couldn't find a non-Deep Water point, then... --------
      • -------- the system instead relies on your Safe Regions which are guaranteed to be outside of Deep Water. --------
      • -------- Finally, the unit is created (respawned) at this safe to use point. --------
      • For each (Integer Spawn_Loop) from 1 to Spawn_Attempts, do (Actions)
        • Loop - Actions
          • Set VariableSet Spawn_Point = (Random point in (Playable map area))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain pathing at Spawn_Point of type Floatability is off) Equal to True
              • (Terrain pathing at Spawn_Point of type Walkability is off) Equal to False
            • Then - Actions
              • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
              • Set VariableSet Spawn_Success = True
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spawn_Loop Equal to Spawn_Attempts
                • Then - Actions
                  • -------- If all of the attempts to spawn the unit ended up in water, give up and instead spawn the unit in one of your "safe regions". --------
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
                  • Set VariableSet Spawn_Point = (Random point in Spawn_SafeRegion[(Random integer number between 1 and Spawn_TotalSafeRegions)])
                  • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
                  • Set VariableSet Spawn_Success = True
                • Else - Actions
          • Custom script: call RemoveLocation (udg_Spawn_Point)
          • Custom script: exitwhen udg_Spawn_Success
      • -------- --------
      • -------- This boolean is used to prevent the actions in our loop from continuing once a unit is spawned. --------
      • Set VariableSet Spawn_Success = False

An important reminder:
Inside of the Respawn Creep trigger I have this action:
  • Set VariableSet Spawn_Point = (Random point in (Playable map area))
You'll probably want to change that to a Random point in your REGION and not the Playable map area.

Also to clarify, Safe Regions are a set of Regions that you create yourself and place outside of Deep Water areas. These are fail-safes that only come into play if the Respawn Creep trigger fails to find a point that's outside of Deep Water. The more Safe Regions you have the better, since this increases the randomness of the spawns in situations where you were very unlucky to begin with (failed all X attempts). You can also increase the Spawn_Attempts variable to further increase the odds that you find a completely random point, but this can come at a performance cost so don't set it too high.
 

Attachments

  • Respawn Creeps Water 2.w3m
    28 KB · Views: 9
Last edited:
Level 5
Joined
Feb 5, 2021
Messages
89
No problem!

So I edited one of the triggers to be slightly more efficient and attached the map below:
  • Respawn Creep
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • -------- Increasing this number improves the odds that a unit ends up in a random non-water spot. This can hurt performance if it's too high. --------
      • Set VariableSet Spawn_Attempts = 10
      • -------- --------
      • -------- This next set of actions creates points at random places in the region until it finds one that isn't in Deep Water. --------
      • -------- If after X attempts you somehow got really unlucky and couldn't find a non-Deep Water point, then... --------
      • -------- the system instead relies on your Safe Regions which are guaranteed to be outside of Deep Water. --------
      • -------- Finally, the unit is created (respawned) at this safe to use point. --------
      • For each (Integer Spawn_Loop) from 1 to Spawn_Attempts, do (Actions)
        • Loop - Actions
          • Set VariableSet Spawn_Point = (Random point in (Playable map area))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain pathing at Spawn_Point of type Floatability is off) Equal to True
              • (Terrain pathing at Spawn_Point of type Walkability is off) Equal to False
            • Then - Actions
              • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
              • Set VariableSet Spawn_Success = True
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spawn_Loop Equal to Spawn_Attempts
                • Then - Actions
                  • -------- If all of the attempts to spawn the unit ended up in water, give up and instead spawn the unit in one of your "safe regions". --------
                  • Custom script: call RemoveLocation (udg_Spawn_Point)
                  • Set VariableSet Spawn_Point = (Random point in Spawn_SafeRegion[(Random integer number between 1 and Spawn_TotalSafeRegions)])
                  • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Spawn_Point facing Default building facing degrees
                  • Set VariableSet Spawn_Success = True
                • Else - Actions
          • Custom script: call RemoveLocation (udg_Spawn_Point)
          • Custom script: exitwhen udg_Spawn_Success
      • -------- --------
      • -------- This boolean is used to prevent the actions in our loop from continuing once a unit is spawned. --------
      • Set VariableSet Spawn_Success = False
An important reminder:
Inside of the Respawn Creep trigger I have this action:
  • Set VariableSet Spawn_Point = (Random point in (Playable map area))
You'll probably want to change that to a Random point in your REGION and not the Playable map area.
Gosh! than you again! this is being increasingly more interesting and i feel like i am both learning alot and getting things to be working!

About the playable map area, thank you for pointing it out, though i had seen it and was like "Yes this is something i can understand and make work!" :D

Can i +rep or something? :D (If i can rep you i dont know how to)
 
Status
Not open for further replies.
Top