• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Making units travel as a group

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
Hi,

I've never been able to get this one to work so I thought I'd ask for some help...

How can I make computer units move as a group? I am using unit groups but they always move singularly rather than if you where to select a group yourself and them move in a formation?
 
Level 24
Joined
Jun 26, 2020
Messages
1,853
For that you have to use the function
  • Unit Group - Order "Your group" <Your stuff>
But that function only works to max 12 units, so I created a new functions that works to groups with any quantity of units
JASS:
function filter takes nothing returns nothing
//This is if you wanna add an exception
    if true then
        call GroupAddUnit(bj_groupAddGroupDest,GetEnumUnit())
    endif
endfunction

function PointOrderGroupEX takes group g, string s, location l returns nothing
    local integer i=1
    local group ref=CreateGroup()
    local group vase
    local unit u
    set bj_groupAddGroupDest=ref
    call ForGroup(g,function filter)
    loop
        exitwhen IsUnitGroupEmptyBJ(ref)
        set vase=GetRandomSubGroup(12,ref)
        call GroupPointOrderLoc(vase,s,l)
        call GroupRemoveGroup(vase,ref)
        call DestroyGroup(vase)
    endloop
    call DestroyGroup(ref)
    set vase=null
    set ref=null
endfunction

function TargetOrderGroupEX takes group g, string s, widget w returns nothing
    local integer i=1
    local group ref=CreateGroup()
    local group vase
    local unit u
    set bj_groupAddGroupDest=ref
    call ForGroup(g,function filter)
    loop
        exitwhen IsUnitGroupEmptyBJ(ref)
        set vase=GetRandomSubGroup(12,ref)
        call GroupTargetOrder(vase,s,w)
        call GroupRemoveGroup(vase,ref)
        call DestroyGroup(vase)
    endloop
    call DestroyGroup(ref)
    set vase=null
    set ref=null
endfunction

function ImmediateOrderGroupEX takes group g, string s returns nothing
    local integer i=1
    local group ref=CreateGroup()
    local group vase
    local unit u
    set bj_groupAddGroupDest=ref
    call ForGroup(g,function filter)
    loop
        exitwhen IsUnitGroupEmptyBJ(ref)
        set vase=GetRandomSubGroup(12,ref)
        call GroupImmediateOrder(vase,s)
        call GroupRemoveGroup(vase,ref)
        call DestroyGroup(vase)
    endloop
    call DestroyGroup(ref)
    set vase=null
    set ref=null
endfunction
To use it just add it to the top of the triggers in the part of "Custom script code" and in your triggers simply do:
  • Set TempGroup = "Your group"
  • Set TempLoc = "Your location"
  • Custom script: call PointOrderGroupEX(udg_TempGroup,<Your order, exm: "move", "attack", etc>,udg_TempLoc)
  • Custom script: call RemoveLocation(udg_TempLoc)
  • Custom script: call DestroyGroup(udg_TempGroup)
 
Last edited:
Level 13
Joined
Oct 16, 2010
Messages
731
Thanks I will have to give it a go. I basically have AI waves and I'm trying to add some enemy heroes, but would like them to travel with a group of units. And the method I'm using just makes them all move individually (faster units moving ahead of the rest of the group etc)
 
Level 24
Joined
Jun 26, 2020
Messages
1,853
Thanks I will have to give it a go. I basically have AI waves and I'm trying to add some enemy heroes, but would like them to travel with a group of units. And the method I'm using just makes them all move individually (faster units moving ahead of the rest of the group etc)
Did you do?:
  • Unit Group - Pick every unit in "Your group" and then do (Actions)
    • Loop - Actions
      • Unit - Order (Picked unit) move to "Your point"
Because in that case, the units will move individually, if you wanna make them moving in group, do what I said before.
 
Level 4
Joined
May 19, 2020
Messages
319
@HerlySQR I think the friend doesn't look for that basically, I mean in relation to the 12 units limitation per group move, although your tip is good for a deeper request. There are some known maps that move up to 20 units per group, such as Rome II Total War, I even found maps that had 60 units per group, but they are all protected, and I wasn't interested in unlocking them either.
I think his intention is for a simpler group movement system made only by GUI itself and not by functions Jass. In the composition of the leader unit (flag) and units linked to it, in addition to modifying the style of the formations, spacing between each of the units in the distribution of the troop, etc...
I've met some really good systems (and extremely simple). There are many batallion systems created here at Hive, but most are very old and few are really useful and didactic. Suggestions:
This is one of the best system I've found with lock-free availability here at Hive, I believe it doesn't have "Leaks", being the use only by the GUI (I don't know the author). The original version has flags that are the leading unit that commands the direction of the group. For each unit killed, the leader loses 1 point of HP. In the Object Editor, the battalion leaders are just flags with invulnerability skill, having HP worth the amount of units in the battalion. If all units die, the leader (flag) will die, taking the definitive loss of all his HP.
--- Original link:"Grantuu's Siege Triggers (JP's Mod)"

But this system causes a conflict if you have more than 1 battalion on the map. For every unit killed, 1 HP will be removed, but for each of the battalion leaders and not just the battalion leader of the unit that was killed. Causing the death of all the leaders of the other battalions that still have units alive on the map. This causes units to detach from other battalions, making all battalions free for individual handling. I still haven't been able to fix this problem created by the author.
Considering this, I created a new version (leaders are vulnerable), in which the Footman unit leaders are real units, with higher HP than the units, if this leader dies, only his troop will suffer dismemberment from all units in the group and not from all similar battalions that exist leaders still alive on the map.
Also added a system "Random Unit", you can have the birth of up to 3 different types of units in the variation of 4 groups of Footman's.
--- Link modification (by me): "AddRandomUnits_Grantuu's Siege Triggers(JP's Mod)"
Ps. Disregard leaks existing!!!

This system created by Tasyen, despite being in GUI, may not be so simple, but it can be interesting to scale the space between the group's units and create different types of formations.
--- Link (by Tasyen): "Formation.w3x"
 

Attachments

  • Grantuu's Siege Triggers (JP's Mod).w3x
    32.7 KB · Views: 31
  • AddRandomUnits_Grantuu's Siege Triggers (JP's Mod).w3x
    34.7 KB · Views: 16
  • Formation.w3x
    24.9 KB · Views: 39
Last edited:
Level 33
Joined
Mar 27, 2008
Messages
8,035
I made this system wayyy back.
You can try it, and see how it goes.

Use the Squad Formation ability from the Blood Mage onto those Knight to recruit them to follow your Formation.
After that, all your leader's orders (move-attack, attack, move, patrol) will be mimicked by your Squad.

For more info: Simple Squad Formation System v1.0
 

Attachments

  • Simple Squad Formation System v1.0.w3x
    19.9 KB · Views: 14
Level 4
Joined
May 19, 2020
Messages
319
I made this system wayyy back. You can try it, and see how it goes. Use the Squad Formation ability from the Blood Mage onto those Knight to recruit them to follow your Formation. After that, all your leader's orders (move-attack, attack, move, patrol) will be mimicked by your Squad.
For more info: Simple Squad Formation System v1.0
I followed your system, it seems to work fine, but the formation style I'm referring to would be instant grouping after a Spawn or Training, recall of games like BFME2, not by Spell or Direct Selections (although it works perfectly too).
 
Status
Not open for further replies.
Top