• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Moving from region to region - help

Status
Not open for further replies.
Level 2
Joined
Nov 10, 2019
Messages
14
Hi, I've been trying to move spawned units from one region to the next region, through a for each loop.
it doesn't seem to work since the unit stops at "T1 03 move2".

I kinda figured out my looping is wrong, but I can't figure out how to do it properly.

What I wanted was to get a "short" trigger that would do the job.


I have another trigger which creates the units, 1 every second for 10 seconds.


Regions are place in an array variable and has been indexed below.

  • regions
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set regions[0] = T1 01 spawn <gen>
      • Set regions[1] = T1 02 move1 <gen>
      • Set regions[2] = T1 03 move2 <gen>
      • Set regions[3] = T1 04 move3 <gen>
      • Set regions[4] = T1 05 move4 <gen>
      • Set regions[5] = T1 06 move5 <gen>
      • Set regions[6] = T1 07 move6 <gen>
      • Set regions[7] = T1 08 move7 <gen>
      • Set regions[8] = T1 09 move8 <gen>
      • Set regions[9] = T1 10 move9 <gen>
      • Set regions[10] = T1 11 endmove <gen>
      • Set regions[11] = T1 12 spawn battle <gen>
      • Set regions[12] = T1 13 battle position <gen>


  • Untitled Trigger 001
    • Events
      • Unit - A unit enters T1 01 spawn <gen>
      • Unit - A unit enters T1 02 move1 <gen>
      • Unit - A unit enters T1 03 move2 <gen>
      • Unit - A unit enters T1 04 move3 <gen>
      • Unit - A unit enters T1 05 move4 <gen>
      • Unit - A unit enters T1 06 move5 <gen>
      • Unit - A unit enters T1 07 move6 <gen>
      • Unit - A unit enters T1 08 move7 <gen>
      • Unit - A unit enters T1 09 move8 <gen>
      • Unit - A unit enters T1 10 move9 <gen>
      • Unit - A unit enters T1 11 endmove <gen>
      • Unit - A unit enters T1 12 spawn battle <gen>
      • Unit - A unit enters T1 13 battle position <gen>
    • Conditions
    • Actions
      • For each (Integer A) from 0 to 10, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (regions[(Integer A)] contains (Entering unit)) Equal to True
            • Then - Actions
              • Unit - Order (Entering unit) to Move To (Center of regions[((Integer A) + 1)])
            • Else - Actions
Thank you for your time.
regards the nooblet.
 

Uncle

Warcraft Moderator
Level 68
Joined
Aug 10, 2018
Messages
7,153
I'm not sure why it doesn't work. I tested it myself and it seemed like either the Event wouldn't fire or the Region didn't contain the entering unit. On top of that it only worked if I manually ordered the units into the region. Very weird.

Anyway, a workaround I found was to use the "A unit comes within range of another unit" Event and use "hidden" Locust units to act like Regions.

If you don't know already, a Locust unit is a Unit with the Locust ability added to it in the Object Editor. This ability prevents the unit from being selected. And to make the unit "hidden", open it's Model and select Custom at the bottom, then type a random unused path like "none". Also, make sure to set the unit's Attacks Enabled to None so it can't attack.

Variables used:
TempUnit = Unit
TempPoint1 = Point
TempPoint2 = Point

In the Setup trigger I set RegionUnit[] the same way you set regions[], just this time I'm using Units instead of Regions. But if you use this method don't delete your regions, because as you can see I still make use of them by moving the RegionUnits to the center of their corresponding Region. I do this just to make sure that the unit is perfectly centered in the region, otherwise you'd just have to eyeball it when placing the unit on the map.
  • Region Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set Variable RegionUnit[1] = Region Unit 001 <gen>
      • Set Variable TempPoint1 = (Center of Region 1 <gen>)
      • Unit - Move RegionUnit[1] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
      • -------- - --------
      • Set Variable RegionUnit[2] = Region Unit 002 <gen>
      • Set Variable TempPoint1 = (Center of Region 2 <gen>)
      • Unit - Move RegionUnit[2] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
      • -------- - --------
      • Set Variable RegionUnit[3] = Region Unit 003 <gen>
      • Set Variable TempPoint1 = (Center of Region 3 <gen>)
      • Unit - Move RegionUnit[3] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
      • -------- - --------
      • Set Variable RegionUnit[4] = Region Unit 004 <gen>
      • Set Variable TempPoint1 = (Center of Region 4 <gen>)
      • Unit - Move RegionUnit[4] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
This next trigger is similar to your "A unit Enters region" trigger, except I'm using Units instead of Regions. Also, this time instead of checking if "Region contains Unit" I check the Distance between the Region Unit and the Unit coming within range of it. If Distance is Less than or equal to 200.00 (You can adjust these values) then we know that our Entering Unit came into range of RegionUnit[IntegerA]. Note that this only works if there's at least a bit of distance between your Regions. Also, make sure your Region Units don't come within range of one another.
  • Enter Region
    • Events
      • Unit - A unit comes within 100.00 of Region Unit 001 <gen>
      • Unit - A unit comes within 100.00 of Region Unit 002 <gen>
      • Unit - A unit comes within 100.00 of Region Unit 003 <gen>
      • Unit - A unit comes within 100.00 of Region Unit 004 <gen>
    • Conditions
    • Actions
      • Set Variable TempUnit = (Triggering unit)
      • Set Variable TempPoint1 = (Position of TempUnit)
      • -------- - --------
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • Set Variable TempPoint2 = (Position of RegionUnit[(Integer A)])
          • Set Variable Distance = (Distance between TempPoint1 and TempPoint2)
          • Custom script: call RemoveLocation (udg_TempPoint2)
          • -------- - --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Distance Less than or equal to 200.00
            • Then - Actions
              • Set Variable TempPoint2 = (Position of RegionUnit[((Integer A) + 1)])
              • Unit - Order TempUnit to Move To TempPoint2
              • Custom script: call RemoveLocation (udg_TempPoint2)
            • Else - Actions
      • -------- - --------
      • Custom script: call RemoveLocation (udg_TempPoint1)

Also, make sure to clean up your leaks or your map's performance will get worse and worse as the game goes on.

That's what I'm doing with the custom script "Custom Script: call RemoveLocation (udg_TempPoint1)". This is used to remove Point leaks.

So whenever you create a unit somewhere or order a unit to move/do something somewhere in the map/region, you'll want to set a Point variable there first. Like "Set Variable Point = (Center of playable map area)", then reference that Point in your Actions, "Order triggering unit to move to Point", then clean up the Point when you're done with it, "call RemoveLocation (udg_Point)".

Things That Leak
 
Last edited:
Level 2
Joined
Nov 10, 2019
Messages
14
I'm not sure why it doesn't work. I tested it myself and it seemed like either the Event wouldn't fire or the Region didn't contain the entering unit. On top of that it only worked if I manually ordered the units into the region. Very weird.

Anyway, a workaround I found was to use the "A unit comes within range of another unit" Event and use "hidden" Locust units to act like Regions.

If you don't know already, a Locust unit is a Unit with the Locust ability added to it in the Object Editor. This ability prevents the unit from being selected. And to make the unit "hidden", open it's Model and select Custom at the bottom, then type a random unused path like "none". Also, make sure to set the unit's Attacks Enabled to None so it can't attack.

Variables used:
TempUnit = Unit
TempPoint1 = Point
TempPoint2 = Point

In the Setup trigger I set RegionUnit[] the same way you set regions[], just this time I'm using Units instead of Regions. But if you use this method don't delete your regions, because as you can see I still make use of them by moving the RegionUnits to the center of their corresponding Region. I do this just to make sure that the unit is perfectly centered in the region, otherwise you'd just have to eyeball it when placing the unit on the map.
  • Region Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set Variable RegionUnit[1] = Region Unit 001 <gen>
      • Set Variable TempPoint1 = (Center of Region 1 <gen>)
      • Unit - Move RegionUnit[1] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
      • -------- - --------
      • Set Variable RegionUnit[2] = Region Unit 002 <gen>
      • Set Variable TempPoint1 = (Center of Region 2 <gen>)
      • Unit - Move RegionUnit[2] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
      • -------- - --------
      • Set Variable RegionUnit[3] = Region Unit 003 <gen>
      • Set Variable TempPoint1 = (Center of Region 3 <gen>)
      • Unit - Move RegionUnit[3] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
      • -------- - --------
      • Set Variable RegionUnit[4] = Region Unit 004 <gen>
      • Set Variable TempPoint1 = (Center of Region 4 <gen>)
      • Unit - Move RegionUnit[4] instantly to TempPoint1
      • Custom script: call RemoveLocation (udg_TempPoint1)
This next trigger is similar to your "A unit Enters region" trigger, except I'm using Units instead of Regions. Also, this time instead of checking if "Region contains Unit" I check the Distance between the Region Unit and the Unit coming within range of it. If Distance is Less than or equal to 200.00 (You can adjust these values) then we know that our Entering Unit came into range of RegionUnit[IntegerA]. Note that this only works if there's at least a bit of distance between your Regions. Also, make sure your Region Units don't come within range of one another.
  • Enter Region
    • Events
      • Unit - A unit comes within 100.00 of Region Unit 001 <gen>
      • Unit - A unit comes within 100.00 of Region Unit 002 <gen>
      • Unit - A unit comes within 100.00 of Region Unit 003 <gen>
      • Unit - A unit comes within 100.00 of Region Unit 004 <gen>
    • Conditions
    • Actions
      • Set Variable TempUnit = (Triggering unit)
      • Set Variable TempPoint1 = (Position of TempUnit)
      • -------- - --------
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • Set Variable TempPoint2 = (Position of RegionUnit[(Integer A)])
          • Set Variable Distance = (Distance between TempPoint1 and TempPoint2)
          • Custom script: call RemoveLocation (udg_TempPoint2)
          • -------- - --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Distance Less than or equal to 200.00
            • Then - Actions
              • Set Variable TempPoint2 = (Position of RegionUnit[((Integer A) + 1)])
              • Unit - Order TempUnit to Move To TempPoint2
              • Custom script: call RemoveLocation (udg_TempPoint2)
            • Else - Actions
      • -------- - --------
      • Custom script: call RemoveLocation (udg_TempPoint1)

Also, make sure to clean up your leaks or your map's performance will get worse and worse as the game goes on.

That's what I'm doing with the custom script "Custom Script: call RemoveLocation (udg_TempPoint1)". This is used to remove Point leaks.

So whenever you create a unit somewhere or order a unit to move/do something somewhere in the map/region, you'll want to set a Point variable there first. Like "Set Variable Point = (Center of playable map area)", then reference that Point in your Actions, "Order triggering unit to move to Point", then clean up the Point when you're done with it, "call RemoveLocation (udg_Point)".

Things That Leak


Amazing, it works, I just had to add events with the units & regions dynamicly as it changes ingame depending on the maze one picks I ended up with:

  • Move Unit NW1
    • Events
    • Conditions
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • Set Temp_Loc1 = (Position of Temp_Unit)
      • For each (Integer A) from 1 to RegionsAmountInt, do (Actions)
        • Loop - Actions
          • Set Temp_Loc2 = (Position of UnitMovement1[(Integer A)])
          • Set Temp_Distance = (Distance between Temp_Loc1 and Temp_Loc2)
          • Custom script: call RemoveLocation (udg_Temp_Loc2)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Temp_Distance Less than or equal to 70.00
            • Then - Actions
              • Set Temp_Loc2 = (Position of UnitMovement1[((Integer A) + 1)])
              • Unit - Order Temp_Unit to Move To Temp_Loc2
              • Custom script: call RemoveLocation (udg_Temp_Loc2)
            • Else - Actions
      • Custom script: call RemoveLocation (udg_Temp_Loc1)
No events here as they are added in another trigger
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • PlayingGroupsBool[3] Equal to True
    • Then - Actions
      • For each (Integer A) from 0 to RegionsAmountInt, do (Actions)
        • Loop - Actions
          • Set Temp_Loc = (Center of RegionsChosenTeam3[(Integer A)])
          • Unit - Create 1 Dummy Unit for Neutral Passive at Temp_Loc facing Default building facing degrees
          • Set UnitMovement3[(Integer A)] = (Last created unit)
          • Trigger - Add to Move Unit SW3 <gen> the event (Unit - A unit comes within 15.00 of UnitMovement3[(Integer A)])
          • Custom script: call RemoveLocation(udg_Temp_Loc)
    • Else - Actions
EDIT: Don't mind that the UnitMovement1, UnitMovement3 & RegionsChosenTeam3, isn't set correctly, it was copied from different parts triggers & I didn't notice at that point.

Works perfectly for now idk yet if units starts to gather up.
Thanks for your reply! much appreciated!
 
Status
Not open for further replies.
Top