Generic Unit Enters Region Events

Status
Not open for further replies.
Level 6
Joined
Dec 9, 2014
Messages
176
So I was looking for a way to make it so that if a specific unit, decided by a variable, enters a region, then it is ordered to move to the next region which in turn will cause it to move to the next and so on. Each time the trigger would go off, it would move to a region based off which region it happened to enter. This would mean making a simple path for that unit all in one trigger. Instead, I only seem to find that the region event can only be specific. This means, at least to me, I would need to make a different trigger for all 23 region points I have for the unit's journey. If possible I'd rather not have to make so many triggers just for one unit. Also, it would actually be 46 triggers because I also have that same unit going back depending on the situation. I'd much rather this be 2 triggers than 46 lol.

In case you're wondering, it's a wagon that spawns on the western part of the map on a road after a random amount of seconds have passed and then is ordered to move to the next region point and effectively follow the road all the way to the eastern spawn point and be despawned from there. There are 23 region points in use for this to follow the road properly. The idea is to have a caravan of random items and money for players to come across on the road and attack if they want. Bandits on the map near the roads will also be ordered to attack the caravan if it gets close enough to them on the road. If bandits kill the caravan, a random item will be given to the bandit lord hero at the main bandit camp. Sorta like they are robbing people which makes the bandits stronger. The bandits are neutral hostile so players will want to attack them for xp and items of course just like any other melee map.
 
Last edited:
Level 11
Joined
Nov 23, 2013
Messages
665
I would try to use a Wait for condition action, and use a boolean condition to check if the unit is in the next region. Something like this:
  • Moving Unit
    • Actions
      • Unité - Order Footman to Move to (Center of Region01)
      • Wait until ((Region01 contains Footman) Equal to TRUE), checking every X seconds
      • Unité - Order Footman to Move to (Center of Region02)
      • Wait until ((Region02 contains Footman) Equal to TRUE), checking every X seconds
      • Unité - Order Footman to Move to (Center of Region03)
Etc
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,272
I suggest learning to use JASS directly. This gives you access to the region (not supported in GUI, hence why this needs JASS) handle that triggered a trigger. One can then data feed the entire system from arrays of location (GUI point) and rect (GUI region) pairs. Convert each rect into a region and then use a hashtable to map the appropriate index to the region handle and register a unit entry event to the trigger. When the trigger fires get the triggering region, resolve the index it was for using the hashtable and look up the point to order the entering unit to go to from the arrays.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,223
I think the wait until is a bad solution as waits are not exactly reliable.

That being said, solution with few rows might be a tad complicated.

Init Trigger
set region[1] = someRegion1
set region[2] = someRegion2
set region[3] = someRegion3
set region[4] = someRegion4

set myHash = new hashtable

loop 1-4
add unit enters region[integer a/b] event to someTrigger​


someTrigger
set handle = handle id of triggering unit
set current = Hashtable - Load 0 of key handle in myHash + 1
Hashtable - current as 0 of handle in myHash
order triggering unit to move to center of region[current]​
 
Level 6
Joined
Dec 9, 2014
Messages
176
I suggest learning to use JASS directly. This gives you access to the region (not supported in GUI, hence why this needs JASS) handle that triggered a trigger. One can then data feed the entire system from arrays of location (GUI point) and rect (GUI region) pairs. Convert each rect into a region and then use a hashtable to map the appropriate index to the region handle and register a unit entry event to the trigger. When the trigger fires get the triggering region, resolve the index it was for using the hashtable and look up the point to order the entering unit to go to from the arrays.

I've never used JASS at all. Where's the best place to start learning for dummies? The only reason I was able to figure out GUI is because of how simple it is and straight forward. JASS looks really difficult lol
 
Level 43
Joined
Feb 27, 2007
Messages
5,465
I also recommend you use JASS but there's an easy way to get the region in GUI. You need to assign all of your regions to different indexes of a region array on map init and then loop through the regions to check if the unit is inside any of them when the event fires. I would recommend setting it up so that MoveRegion[1] is the first region it will enter, then goes to MoveRegion[2], then MoveRegion[3], etc.
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set RegionCount = (RegionCount + 1)
    • Set MoveRegion[RegionCount] = First Region <gen>
    • Set RegionCount = (RegionCount + 1)
    • Set MoveRegion[RegionCount] = Second Region <gen>
    • Set RegionCount = (RegionCount + 1)
    • Set MoveRegion[RegionCount] = Third Region <gen>
    • -------- and so on --------
    • For each (Integer A) from 1 to RegionCount do (Actions)
      • Loop - Actions
        • Trigger - Add to REGION_ENTER_TRIGGER <gen> the event (Unit - A unit enters MoveRegion[(Integer A)])
  • Events
    • -------- none, added by above trigger --------
  • Conditions
    • (Triggering Unit) equal to YOUR_UNIT_VARIABLE
  • Actions
    • For each (Integer A) from 1 to RegionCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (MoveRegion[(Integer A)] contains (Triggering Unit)) equal to true
            • (Integer A) less than or equal to RegionCount //so it doesn't try to move on the last region
          • Then - Actions
            • Set TempPoint = (Center of MoveRegion[(Integer A) + 1]
            • Unit - Order (Triggering Unit) to move to TempPoint
            • Custom script: call RemoveLocation(udg_TempPoint) //change this to match the name of your point variable, but keep the udg_ prefix
            • Skip remaining actions
          • Else - Actions
 
Level 6
Joined
Aug 28, 2015
Messages
213
In addition what Pyrogasm says here is the system in MUI.
  • Waypoints Initialize
    • Events
      • Time - Elapsed game time is 0.30 seconds
    • Conditions
    • Actions
      • -------- Set the Regions to loop through later on --------
      • Set WayPoint_Regions[1] = WayPointRegion01 <gen>
      • Set WayPoint_Regions[2] = WayPointRegion02 <gen>
      • Set WayPoint_Regions[3] = ...
      • -------- Because the entering unit event fires before the unit is inside the Region --------
      • -------- we have to create points in offset around the unit to check which region is entered --------
      • Set WayPoint_PointOffset = 60.00
      • -------- Set the trigger that should be fired when a unit enters one of these regions --------
      • Set WayPoint_EnterTrigger = Waypoint Enter <gen>
      • -------- Loop through all Regions and save their contained units in groups --------
      • For each (Integer WayPoint_Index) from 0 to WayPoint_RegionAmount, do (Actions)
        • Loop - Actions
          • -------- check if there will be more regions --------
          • Custom script: if ( not(udg_WayPoint_Regions[udg_WayPoint_RegionAmount + 1 ] == null)) then
          • Set WayPoint_RegionAmount = (WayPoint_RegionAmount + 1)
          • -------- Add Region to entering trigger --------
          • Trigger - Add to Waypoint Enter <gen> the event (Unit - A unit enters WayPoint_Regions[WayPoint_RegionAmount])
          • Custom script: endif
      • -------- The direction is 1 for increseing the Waypoint South to North --------
      • -------- and -1 for decreasing North to South the next waypoint --------
  • Waypoint Enter
    • Events
    • Conditions
      • (Owner of (Triggering unit)) Equal to Patroling Player
    • Actions
      • Set WayPoint_TriggeringUnit = (Triggering unit)
      • Set WayPoint_UnitIndex = (Custom value of WayPoint_TriggeringUnit)
      • Set WayPoint_Points[0] = (Position of WayPoint_TriggeringUnit)
      • -------- we have to create a area around the triggering unit to be able to check in wich region the unit is --------
      • Set WayPoint_Points[1] = (WayPoint_Points[0] offset by ((WayPoint_PointOffset x -1.00), (WayPoint_PointOffset x -1.00)))
      • Set WayPoint_Points[2] = (WayPoint_Points[0] offset by ((WayPoint_PointOffset x -1.00), WayPoint_PointOffset))
      • Set WayPoint_Points[3] = (WayPoint_Points[0] offset by (WayPoint_PointOffset, WayPoint_PointOffset))
      • Set WayPoint_Points[4] = (WayPoint_Points[0] offset by (WayPoint_PointOffset, (WayPoint_PointOffset x -1.00)))
      • -------- Check in which region the unit is --------
      • For each (Integer WayPoint_Index) from 1 to WayPoint_RegionAmount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (WayPoint_Regions[WayPoint_Index] contains WayPoint_Points[1]) Equal to True
                  • (WayPoint_Regions[WayPoint_Index] contains WayPoint_Points[2]) Equal to True
                  • (WayPoint_Regions[WayPoint_Index] contains WayPoint_Points[3]) Equal to True
                  • (WayPoint_Regions[WayPoint_Index] contains WayPoint_Points[4]) Equal to True
              • Or - Any (Conditions) are true
                • Conditions
                  • WayPoint_CurrentState[WayPoint_UnitIndex] Equal to WayPoint_Index
                  • WayPoint_CurrentState[WayPoint_UnitIndex] Equal to 0
            • Then - Actions
              • -------- If the unit don't has progress yet, it will assigned the progress of the entered region --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • WayPoint_CurrentState[WayPoint_UnitIndex] Equal to 0
                • Then - Actions
                  • -------- If the unit don't has a direction it will move towards the North by default --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • WayPoint_Direction[WayPoint_UnitIndex] Equal to 0
                    • Then - Actions
                      • Set WayPoint_Direction[WayPoint_UnitIndex] = 1
                    • Else - Actions
                  • Set WayPoint_CurrentState[WayPoint_UnitIndex] = WayPoint_Index
                • Else - Actions
              • -------- Check if an end is reached and revert the units direction --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • WayPoint_Index Greater than or equal to WayPoint_RegionAmount
                • Then - Actions
                  • Set WayPoint_Direction[WayPoint_UnitIndex] = -1
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • WayPoint_Index Less than or equal to 1
                    • Then - Actions
                      • Set WayPoint_Direction[WayPoint_UnitIndex] = 1
                    • Else - Actions
              • -------- Send the unit to the next regions position --------
              • Set WayPoint_CurrentState[WayPoint_UnitIndex] = (WayPoint_CurrentState[WayPoint_UnitIndex] + WayPoint_Direction[WayPoint_UnitIndex])
              • Set WayPoint_Points[5] = (Center of WayPoint_Regions[WayPoint_CurrentState[WayPoint_UnitIndex]])
              • Unit - Order WayPoint_TriggeringUnit to Move To WayPoint_Points[5]
              • -------- Remove Memory leaks --------
              • Custom script: call RemoveLocation(udg_WayPoint_Points[0])
              • Custom script: call RemoveLocation(udg_WayPoint_Points[1])
              • Custom script: call RemoveLocation(udg_WayPoint_Points[2])
              • Custom script: call RemoveLocation(udg_WayPoint_Points[3])
              • Custom script: call RemoveLocation(udg_WayPoint_Points[4])
              • Custom script: call RemoveLocation(udg_WayPoint_Points[5])
              • Skip remaining actions
            • Else - Actions
It needs @Bribe unit indexer but this is nearly always a must have if you work in GUI.
Attached is the test map just in case...
 

Attachments

  • Waypoint Pathing System.w3x
    31.8 KB · Views: 30
Status
Not open for further replies.
Top