• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Units patrols several points

Level 12
Joined
Oct 28, 2019
Messages
475
1687742415613.png


Hi to all, the idea is simple but it is breaking
  • Patrol1
    • Events
      • Unit - A unit enters Patrol1 <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Brigand
    • Actions
      • Unit - Order (Entering unit) to Attack-Move To (Random point in Patrol2 <gen>)
and with this I complete the loop, but sometimes dont work. I dont know why it is not working
6 to 9 brigands will be patrolling the area, it is 13 points,
 
Level 20
Joined
Jun 27, 2011
Messages
1,864
I'm guessing it might be due to the unit's leash range while it's "patrolling". Try this fix from Pyrogasm:
... the unit has a leash range that it's leaving. Order it to stop, then patrol onward when it reaches a new region.

Similar thread:
 
Level 12
Joined
Oct 28, 2019
Messages
475
I´ve done this and worked

  • Path1
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in Patrol1 <gen> owned by Player 21 (Coal)) and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To (Center of Patrol2 <gen>)
Doing to all points 1-->2 / 2-->3 etc...
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,552
You probably want to fix those memory leaks. Also, that's not guaranteed to work since there's a gap in time where things can go wrong.

A good method is to setup a Point array which stores the center of these different Patrol regions, then use Unit Indexing to store an Integer to each Brigand which keeps track of where they should head to next:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set Variable PatrolPoint[1] = (Center of Patrol1 <gen>)
    • Set Variable PatrolPoint[2] = (Center of Patrol2 <gen>)
    • Set Variable PatrolPoint[3] = (Center of Patrol3 <gen>)
    • // Repeat for all 13 regions
Now using Unit Indexing we can assign our Brigand's an Integer (PatrolIndex) which represents which PatrolPoint[] they should be going to next:
  • Actions
    • Unit - Create 1 Brigand for Player X at PatrolRegion[1]...
    • Set Variable PatrolUnit = (Last created unit)
    • Set Variable PatrolCV = (Custom value of PatrolUnit)
    • Set Variable PatrolIndex[PatrolCV] = 2
    • Unit - Order PatrolUnit to Attack-Move To PatrolPoint[PatrolIndex[PatrolCV]]
    • Unit Group - Add PatrolUnit to PatrolGroup
Now at any given moment we can order them to move to their next patrol point:
  • Brigand Patrol Fix
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in PatrolGroup and do (Actions)
        • Loop - Actions
          • Set Variable PatrolUnit = (Picked unit)
          • Set Variable PatrolCV = (Custom value of PatrolUnit)
          • Unit - Order PatrolUnit to Attack-Move To PatrolPoint[PatrolIndex[PatrolCV]]
Also, when they Enter one of these Regions you can update their PatrolIndex[] to match their next destination:
  • Events
    • Unit - A unit enters Patrol1 <gen>
    • Unit - A unit enters Patrol2 <gen>
    • Unit - A unit enters Patrol3 <gen>
    • // Repeat for all 13 regions
  • Conditions
    • It's a Brigand-type unit
  • Actions
    • Set Variable PatrolUnit = (Entering unit)
    • Set Variable PatrolCV = (Custom value of PatrolUnit)
    • Set Variable PatrolIndex[PatrolCV] = (PatrolIndex[PatrolCV] + 1)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • PatrolIndex[PatrolCV] Greater than 13
      • Then - Actions
        • Set Variable PatrolIndex[PatrolCV] = 1
      • Else - Actions
    • Unit - Order PatrolUnit to Attack-Move To PatrolPoint[PatrolIndex[PatrolCV]]
You could also have one trigger per Region and manually Set PatrolIndex to the exact value you want.

Also, if your Brigand units are pre-placed on the map then you would want to assign them a PatrolIndex AFTER map initialization:
  • Events
    • Time - Elapsed game time is 0.01 seconds
  • Conditions
  • Actions
    • Set Variable PatrolUnit = One of your Brigand units
    • Set Variable PatrolCV = (Custom value of PatrolUnit)
    • Set Variable PatrolIndex[PatrolCV] = 2
    • Unit - Order PatrolUnit to Attack-Move To PatrolPoint[PatrolIndex[PatrolCV]]
    • Unit Group - Add PatrolUnit to PatrolGroup
    • // Repeat this for each Brigand unit
Or better yet, use PatrolGroup and Pick Every Unit to easily set them all up:
  • Events
    • Time - Elapsed game time is 0.01 seconds
  • Conditions
  • Actions
    • Set Variable PatrolGroup = (Units in Patrol1 <gen> owned by Player 21 (Coal))
    • Unit Group - Pick every unit in PatrolGroup and do (Actions)
      • Loop - Actions
        • Set Variable PatrolUnit = (Picked unit)
        • Set Variable PatrolCV = (Custom value of PatrolUnit)
        • Set Variable PatrolIndex[PatrolCV] = 2
        • Unit - Order PatrolUnit to Attack-Move To PatrolPoint[PatrolIndex[PatrolCV]]
 
Last edited:
Top