How to make a group of units attack move? Best way to do it?

Level 3
Joined
Jun 11, 2024
Messages
12
I wish to make units I placed attack move to a point after a certain event.

Like if a structure gets attacked the group of 10 footmen at some camp move there

Now my problem is that I am not sure how to do this efficiently, I know I could make a region and do it like that or unit group but if I use region I feel like I make a mess sooner or later and about ordering a unit group I'd have to manually add every single unit to said group. Not to mention groups are also limited to 12 or does it not matter if its within a variable?

My question is essentially, whats the cleanest/best/efficient way to attack-move my preset group of footmen to the specified area? In general how can I select a group of units properly to then change whatever about them?

Pictures:
1718783071365.png


1718783089885.png
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,609
Unit Group variables are the goto method for managing multiple units at once and can contain any number of units. That being said, there's also the Unit array + For Loop method for managing multiple units at once but that's rarely ideal.

Here's an example of tracking that group of Footman:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Set VariableSet TempPoint = (Position of Footman 0264)
    • Set VariableSet FootmanGroup1 = (Units within 600.00 range of Temp_Point matching (Matching unit) is a Building Equal to False)
    • Custom script: call RemoveLocation( udg_TempPoint )
This is assuming that Footman 0264 is near the group of Footman in your picture.

Alternatively, you can just look at the map X/Y coordinates and create the Point there:
  • Set VariableSet TempPoint = (Point(574.00, 1049.00))
There's no need for a Region a lot of the time.

Then for ordering the entire group, use the Pick Every Unit action:
  • Actions
    • Set VariableSet TempPoint = (Center of Region GateTarget <gen>)
    • Unit Group - Pick every unit in FootmanGroup1 and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked unit) to Attack-Move to TempPoint
    • Custom script: call RemoveLocation( udg_TempPoint )
I'm cleaning up the memory leaks by using the TempPoint variable + Custom Script to remove it.
 
Last edited:
Level 3
Joined
Jun 11, 2024
Messages
12
Thank you very much! this will help me out alot. If the temp point wouldn't get removed it would bloat up the map and be like a memory leak right? Did you wrote the script yourself?
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,609
Thank you very much! this will help me out alot. If the temp point wouldn't get removed it would bloat up the map and be like a memory leak right? Did you wrote the script yourself?
No problem.

Yes, that's the basic idea for memory leaks, but I'm not exactly sure what you mean by "writing it yourself".

Understand that certain things can only be done when using Jass/Lua code. This means that a standard trigger doesn't have access to all of the Events/Conditions/Actions that exist in the game. The Custom Script action is the solution to this problem, providing the user a way to write code and access code-only things inside of their triggers. So by taking advantage of it you're able to make hybrid triggers that use both non-code and code solutions.

The Custom Script in my example is running a code-only Action called "RemoveLocation" which takes a given Point variable (you can see this being done in the parenthesis) and destroys the "Location" object that the Point is keeping track of. It doesn't destroy the Point variable itself, but rather the object that the variable is tracking. (Technically it's running a code-only function but that's essentially the same thing)

So "RemoveLocation" already exists in the game, it's not something I created. But you do need to write it out yourself, use proper syntax, and reference the correct variable names when using any kind of Custom Script.

Also, don't forget to enable JassHelper from the Trigger Editor's drop-down menu if you haven't already. You could get a bunch of strange errors otherwise.
 
Last edited:
Level 3
Joined
Jun 11, 2024
Messages
12
Thanks for the info, is there any way to learn how to make such a custom script or examples about syntax too? Although I probably dont need it right away

and with "writing it yourself" I mean if you yourself coded/wrote the script or if you took it from somewhere
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,609
Thanks for the info, is there any way to learn how to make such a custom script or examples about syntax too? Although I probably dont need it right away

and with "writing it yourself" I mean if you yourself coded/wrote the script or if you took it from somewhere
You can learn about Jass through one of the many tutorials on Hive, which will teach you how to use Custom Script since that's exactly what it is. Also, the entire API is documented in multiple places. I'm not exactly sure what the best resource is but the one I linked is nice since you can quickly search for what you want. For example, search for "unit dies".

But a great way to get started and quickly find code is to convert a GUI trigger into "custom text":
1718853551237.png
ct.png

(WARNING: This cannot be undone. Make a backup of your trigger if you want to keep it!)

This will convert your trigger into Jass code, showing you how everything is handled in code form:
1718853682443.png


Note that some of the converted functions may be using a less than ideal version. This is because multiple versions of a function can exist, one used when writing in pure Jass and another for GUI which is often objectively worse. Also, the way this Jass code is structured isn't ideal either. But that's not really worth worrying about just yet. The functions here such as DisplayTimedTextToForce() and IsUnitType() shed light on how you could call them in Custom Script. Although, this isn't a great example since you can just use the standard GUI versions instead.

Here's a better example, it's a function that only exists in code that you could access with Custom Script.

This will stun a unit instantly without any ability/buff being necessary:
  • Actions
    • Set VariableSet TempUnit = (Triggering unit)
    • Custom script: call BlzPauseUnitEx( udg_TempUnit, true )
Call it again but set true to false to unstun the unit:
  • Custom script: call BlzPauseUnitEx( udg_TempUnit, false )
 
Last edited:
Level 3
Joined
Jun 11, 2024
Messages
12
I see, thats all good to know. By the way, does what you wrote work for moving more than 12 units at once or is there no way and I just need multiple triggers for that?
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,609
I see, thats all good to know. By the way, does what you wrote work for moving more than 12 units at once or is there no way and I just need multiple triggers for that?
There is no limitation, a Unit Group variable can contain any number of units and the Pick Every Unit action will run it's Loop - Actions once per unit.

It's only the "Order Unit Group" action that has this problem.

However, you may run into a separate issue where units begin "lagging behind". They will periodically stop for a moment before resuming their movement again. This has to do with too many orders being issued to too many units owned by the same player. The solution is to divide the ordered units amongst multiple players, reduce collision size (or so I've heard), and of course avoid high unit counts.
 
Last edited:
Level 3
Joined
Jun 11, 2024
Messages
12
Yeah I remember on big maps the units lagging behind, good old times haha

I hoped with Reforged the selection limit and unit lagging would be a thing of the past but we all know how that turned out.

I always used "Order Unit Group" and workarounds cause of the 12 unit selection limit but now I did it too with loop and pick every unit and it all works well! Thank you :)
 
Top