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

Ideas for making a "leash" effect work properly (support units always stay close to main unit)?

Level 15
Joined
Jun 9, 2008
Messages
309
Now I have experimented with several versions of this already - I bet many of you are familiar by now with the good old "Squad" concept, several maps use something like that.
The idea is to have a group of "support" units who always stay close to a "main" unit, the player only controls the main unit. Useful for controlling huge swarms/armies of units.

I am actually quite happy with the latest system I have for this.
Trigger spawns support units when you create the main unit, support units are made attackable but unselectable by using Locust and Chaos, and then movement triggers make sure that whenever the main unit moves, the support units follow.

Here's the basic setup:
  • -------- Boat2 --------
  • Unit - Create 1 Fleet Support (1st Fleet) dummy for (Owner of (Triggering unit)) at Standpoint facing Default building facing degrees
  • Set Replazzo = (Last created unit)
  • Unit - Set the custom value of Replazzo to (Custom value of (Triggering unit))
  • Custom script: call UnitAddAbility(udg_Replazzo, 'Aloc')
  • Unit - Add Chaos for Fleet 1 to Replazzo
  • Unit Group - Add Replazzo to Fleet
I also made it more efficient by using global unit groups (in the above example: "Fleet") rather than creating and deleting temporary unit groups.
But now I ran into an unexpected problem:

It works perfectly for human players, or "hollow" computer players (computer players without a AI).
But as it turns out, the full-AI computer player can still manually control units that are supposed to be unselectable.
[EDIT: Did some more reading, and realize that is ALSO a very common problem, actually. I'll see if I someone had found a fix that works in my case, and change this to "SOLVED" if possible.]
[EDIT1: The GUI AI action "eliminate guard positions" seems to do the trick, but I'll have to do more testing.]

What that means is that they will treat the support units like any other unit, and use them separately from their main unit, usually by making them chill uselessly at the base.

Now, one obvious work-around is to have periodic triggers that force the support unit to move close to their main unit at regular interval, "fighting" against the orders of the AI.
I know that this works, but I really want to avoid periodic triggers, I really fear they add to the lag of the map.

To salvage my current solution, is it possible to deny the AI control of the support units?
If not, is there another fix for this?
 
Last edited:
Level 15
Joined
Jun 9, 2008
Messages
309
Only if you are not designing them intelligently.
In that spirit:
  • Fleet periodical Copy
    • Events
      • Time - Every 4.13 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Fleet and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in Fleet) Greater than 0
            • Then - Actions
              • Game - Display to (All players) the text: Fleet Period!
            • Else - Actions
          • Set Fleetpoint = (Position of (Picked unit))
          • Set Gewerbegebiet = (Region centered at Fleetpoint with size (600.00, 600.00))
          • Custom script: call RemoveLocation(udg_Fleetpoint)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Life of Flagship[(Custom value of (Picked unit))]) Equal to (Max life of Flagship[(Custom value of (Picked unit))])
            • Then - Actions
              • Unit - Set life of (Picked unit) to 100.00%
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Fleet Support (1st Fleet) dead
                • Then - Actions
                  • Unit - Add Chaos for Fleet 1 to (Picked unit)
                • Else - Actions
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Gewerbegebiet contains Flagship[(Custom value of (Picked unit))]) Equal to False
            • Then - Actions
              • Custom script: call RemoveRect(udg_Gewerbegebiet)
              • Unit - Change ownership of (Picked unit) to Neutral Passive and Change color
              • AI - Ignore (Picked unit)'s guard position
              • Unit - Order (Picked unit) to Right-Click Flagship[(Custom value of (Picked unit))]
              • Unit - Set (Picked unit) movement speed to ((Current movement speed of Flagship[(Custom value of (Picked unit))]) + 50.00)
              • Animation - Change (Picked unit)'s vertex coloring to (100.00%, 0.00%, 0.00%) with 0.00% transparency
            • Else - Actions
              • Custom script: call RemoveRect(udg_Gewerbegebiet)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Owner of (Picked unit)) Not equal to (Owner of Flagship[(Custom value of (Picked unit))])
                • Then - Actions
                  • Unit - Change ownership of (Picked unit) to (Owner of Flagship[(Custom value of (Picked unit))]) and Change color
                  • AI - Ignore (Picked unit)'s guard position
                • Else - Actions
                  • AI - Ignore (Picked unit)'s guard position
                  • Unit - Order (Picked unit) to Hold Position
Now my question with this is not so much about how to "optimize" it, but rather, for starters I'd just like to know if something like that would cause
1) significant lag
2) infinite loops that crash the game
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Nothing wrong with that. What could loop infinitely? You're not using such a boundless loop. This line is silly: (Life of Flagship[(Custom value of (Picked unit))]) Equal to (Max life of Flagship[(Custom value of (Picked unit))]). Just use this instead:

(Percentage life of Flagship[(Custom value of (Picked unit))]) Greater than or equal to 100.00
 
Top