System Mass Unit Ordering

Tru_Power22

You can change this now in User CP.
Reaction score
144
Mass Unit Ordering​

Newest Version: 1.2​

General Information:

This is just a simple system for ordering more than 12 units at one time. Easy to implement and easy to use. Why should you use this? It's lagless, and GUI (FTW).

Requires Jassnewgen pack with UMSWE enabled.

How to implement:

Copy over all the triggers used in the system. Make sure you have "Automatically create unknown variables while pasting trigger data" is enabled in the World Editor general preferences.

How to enable:

Press escape in game to turn it on. If you want it enabled by default change the variable MUO_Enabled to "true".

Configureation:

You can change the number of units that need to be selected in order to get this to run. Simply change MUO_Units_Needed to whatever number you want.

Known Issues:
If you select enough unit to trigger the mass ordering and the randomly picked unit is not the one you intended it may move every unit of the wrong type.

Leaks a group.

Code:

Initialization Trigger:
Trigger:
  • MUO Init Player Selection Events Iniltalization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to MUO Unit selection <gen> the event (Player - (Player((Integer A))) Selects a unit)
          • Trigger - Add to MUO Mass Unit Ordering Toggle <gen> the event (Player - (Player((Integer A))) skips a cinematic sequence)


Storing the unit type of the units selected
Trigger:
  • MUO Unit selection
    • Events
    • Conditions
    • Actions
      • -------- Sets the temp group units currently selected by triggering player. This is to prevent leaks. --------
      • Set MUO_Temp_Group = (Units currently selected by (Triggering player))
      • Set MUO_Temp_Unit = (Random unit from MUO_Temp_Group)
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Number of units in MUO_Temp_Group) Greater than or equal to (>=) MUO_Units_Needed
          • Then - Actions
            • -------- Sets the selected unit type to the first unit in the group (units currently selected by triggering player). --------
            • Custom script: set udg_MUO_SelecteUnitType[GetConvertedPlayerId(GetTriggerPlayer())] = GetUnitTypeId(udg_MUO_Temp_Unit)
          • Else - Actions
      • -------- Destoyes the unit group --------
      • Custom script: call DestroyGroup (udg_MUO_Temp_Group)


The toggling trigger to turn the system on and off.

Trigger:
  • MUO Mass Unit Ordering Toggle
    • Events
    • Conditions
    • Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MUO_Enabled[(Player number of (Triggering player))] Equal to (==) True
        • Then - Actions
          • -------- Enables the massive movemnet --------
          • Set MUO_Enabled[(Player number of (Triggering player))] = False
          • Set MUO_Temp_Force = (Player group((Triggering player)))
          • Game - Display to MUO_Temp_Force the text: Massive Unit Select...
          • Custom script: call DestroyForce( udg_MUO_Temp_Force )
        • Else - Actions
          • -------- Disables the massive movemnet --------
          • Set MUO_Enabled[(Player number of (Triggering player))] = True
          • Set MUO_Temp_Force = (Player group((Triggering player)))
          • Game - Display to MUO_Temp_Force the text: Massive Unit Select...
          • Custom script: call DestroyForce( udg_MUO_Temp_Force )


Mass ordering point targeted:

Trigger:
  • MUO Unit Actions Point Targeted
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • MUO_Enabled[(Player number of (Triggering player))] Equal to (==) True
    • Actions
      • -------- Turns off the trigger so it doesn't run in in infinite loop. --------
      • Trigger - Turn off (This trigger)
      • Set MUO_Order_Issued = (Issued order)
      • Set MUO_Temp_Point = (Target point of issued order)
      • Set MUO_Temp_Group = (Units of type MUO_SelecteUnitType[(Player number of (Triggering player))])
      • Unit Group - Pick every unit in MUO_Temp_Group and do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Picked unit)) Equal to (==) (Triggering player)
            • Then - Actions
              • Unit - Order (Picked unit) to MUO_Order_Issued MUO_Temp_Point
            • Else - Actions
      • -------- Null unit type to prevent leaks --------
      • Custom script: call DestroyGroup (udg_MUO_Temp_Group)
      • Custom script: call RemoveLocation (udg_MUO_Temp_Point)
      • Custom script: set udg_MUO_Order_Issued = 0
      • -------- Turns on the trigger so it will run again. --------
      • Trigger - Turn on (This trigger)


Mass ordering unit targeted:

Trigger:
  • MUO Unit Actions Unit Targeted
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • MUO_Enabled[(Player number of (Triggering player))] Equal to (==) True
    • Actions
      • -------- Turns off the trigger so it doesn't run in in infinite loop. --------
      • Trigger - Turn off (This trigger)
      • Set MUO_Order_Issued = (Issued order)
      • Set MUO_Temp_Unit = (Target unit of issued order)
      • Set MUO_Temp_Group = (Units of type MUO_SelecteUnitType[(Player number of (Triggering player))])
      • Unit Group - Pick every unit in MUO_Temp_Group and do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Picked unit)) Equal to (==) (Triggering player)
            • Then - Actions
              • Unit - Order (Picked unit) to MUO_Order_Issued MUO_Temp_Unit
            • Else - Actions
      • -------- Null unit type to prevent leaks --------
      • Custom script: call DestroyGroup (udg_MUO_Temp_Group)
      • Custom script: set udg_MUO_Order_Issued = 0
      • -------- Turns on the trigger so it will run again. --------
      • Trigger - Turn on (This trigger)


-------------
Screenshot:
WC3ScrnShot_121209_161218_06.png


Changelog:
1.1: Fixes an enum units leak. Thanks Sickle! - Nevermind I fixed it in the next version.
1.2: Instead of getting the first unit from the group. I pick a random unit to avoid the enum leak. I also removed a few redundant lines of code.

That's everything. Not a super complicated system, but hopefully any maps dealing with a lot of units may find this handy.
 

Attachments

  • Mass Unit Ordering 1.0.w3x
    26.2 KB · Views: 224
  • Mass Unit Ordering 1.1.w3x
    26.3 KB · Views: 252
  • Mass Unit Ordering 1.2.w3x
    26.3 KB · Views: 218

Sickle

New Member
Reaction score
13
The party pooper is here to tell you that your system is not leakless. Every time you enumerate the units selected by a player in GUI, it leaks.
 

Tru_Power22

You can change this now in User CP.
Reaction score
144
The party pooper is here to tell you that your system is not leakless. Every time you enumerate the units selected by a player in GUI, it leaks.

So when I get the first unit for the unit group? I can fix that by just setting it to a temp unit then nulling it. Give me a sec.
 

Sickle

New Member
Reaction score
13
No. And, by the way, nulling integers and reals does nothing. Unit types are integers.

The GUI action leaks internally and cannot be fixed without replacing it totally.
 

Sickle

New Member
Reaction score
13
[lJASS]call GroupEnumUnitsSelected(udg_GroupVariable, udg_PlayerVariable, null)[/lJASS]

And the group must be created first on map initialization.

[lJASS]set udg_GroupVariable = CreateGroup()[/ljASS]
 

Tru_Power22

You can change this now in User CP.
Reaction score
144
I'm just going to get a random unit from the group instead. That way I don't need to change much, and it was kind of pointless for me to get an enumerated unit seeing as when they are added to group by selection it's fairly random anyway.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Interesting idea, I think it would be a lot easier to simply create it in (v)Jass, as it would allow many more features (such as ordering all selected unit-types within range).

I thought getting a random unit didn't enumerate them.

It does:

JASS:
function GroupPickRandomUnit takes group whichGroup returns unit
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupRandomConsidered = 0
    set bj_groupRandomCurrentPick = null
    call ForGroup(whichGroup, function GroupPickRandomUnitEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
    return bj_groupRandomCurrentPick
endfunction


Specifically, this line:

JASS:
    call ForGroup(whichGroup, function GroupPickRandomUnitEnum)


This system mass orders EVERY unit in the entire map. Why doesn't it just group all the units within X of each selected unit, (and recursively continue to group units until there are no more units left not already in the group), so that you can have specific groups of units do this?

Trigger:
  • Set MUO_Temp_Group = (Units currently selected by (Triggering player))
    • Set MUO_Temp_Unit = (Random unit from MUO_Temp_Group)

What are you going to do if a person selects a bunch of different types of units? If a person selects 1 footman and 11 priests, and the trigger randoms to footman, it's going to mass order all the footmen in the map.

I'm going to graveyard this until these problems are either well documented or fixed.
 

Tru_Power22

You can change this now in User CP.
Reaction score
144
Ok, I documented the issues, I'm going to see if I can fix the other problems.
 

Azlier

Old World Ghost
Reaction score
461
Using null in group enumerations doesn't leak anymore. Patch 1.24c saw to that.
 

Sickle

New Member
Reaction score
13
No. Your system still leaks a group. Azlier did not say that all of the leaks here were fixed.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top