• 🏆 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!

SortGroup [GUI Friendly]

  • Like
Reactions: deepstrasz
SortGroup automates the access of using Merges Sort by Flux onto an unit group.
This makes it easy to get the members(s) of an group having most/least of an wanted value.


Avaible Sorting modus:

Modus Additional Info

SORTGROUP__MpMax

SORTGROUP__MpLost

SORTGROUP__MpPercent

SORTGROUP__Mp

SORTGROUP__HpMax

SORTGROUP__HpLost

SORTGROUP__HpPercent

SORTGROUP__Hp

SORTGROUP__Level
Heroes > non-Heroes

SORTGROUP__Distance
needs SortGroupOrigin or X/Y

SORTGROUP__FacingToLoc
difference Unit-Facing and Angle to Loc, treating clockwise and anticlockwise the same
needs SortGroupOrigin or X/Y

SORTGROUP__Buffs
Any Buff

SORTGROUP__BuffsNeg

SORTGROUP__BuffsPos

SORTGROUP__FlyHeight

SORTGROUP__MoveSpeed

SORTGROUP__CustomData
One has to define SortGroupCustomDataTrigger to use it.

Important Variables:

Variable Info

SortGroupGroup
the unitgroup you want an sorted unit array from

SortGroupModus
the value your sorting is based on

SortGroupAscending
true = small to big, false = big to small

SortGroupOrigin
needed for FacingToLoc & Distance.

SortGroupAutoDestroy
when true will destroy SortGroupGroup and Remove SortGroupOrigin
reset every time to false.

MSort_Indices[index]
use this to access the result array in an sorted way.

MSort_EndIndex
last index of the result array

SortGroupResult
the unitarray, it is not sorted.

SortGroupResultValue
the realarray ,it is not sorted.

SortGroupCustomDataTrigger
the code which will be executed when choosing customData mod

SortGroupCustomData
the value picked unit has, set it inside your SortGroupCustomDataTrigger

SortGroupCustomDataAdjust
makes an customdata Value be more heavy/leighter in the sorting

How to use:
This Piece of Code will move all Units from least current Hitpoints to most current Hitpoints to the center of map.
  • HowToUse Wo HP
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set SortGroupGroup = (Units in (Playable map area))
      • Set SortGroupModus = SORTGROUP__Hp
      • Set SortGroupAscending = True
      • Set SortGroupAutoDestroy = True
      • Trigger - Run SortGroup <gen> (ignoring conditions)
      • Set Point[0] = (Center of (Playable map area))
      • For each (Integer A) from 1 to MSort_EndIndex, do (Actions)
        • Loop - Actions
          • Set Point[1] = Point[0] offset by (0.00, (80.00 x (Real((Integer A))))))
          • Unit - Move SortGroupResult[MSort_Indices[(Integer A)]] instantly to Point[1]
          • Custom script: call RemoveLocation(udg_Point[1]
      • Custom script: call RemoveLocation(udg_Point[0])
How to load CustomData:
First you write an small Trigger Loading the data:
  • Load CustomData STR
    • Events
    • Conditions
    • Actions
      • -------- Inside an CustomData Trigger use picked unit to access the unit currently checked. --------
      • Set SortGroupCustomData = (Real((Strength of (Picked unit) (Include bonuses))))
      • -------- Adjust allows to give this unit more/less weight in the sorting. --------
      • Set SortGroupCustomDataAdjust = 0.00
Then Choose Modus = SORTGROUP__CustomData
and set SortGroupCustomDataTrigger = wanted Trigger (Load CustomData STR)
  • CustomData Str
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set SortGroupGroup = (Units in (Playable map area))
      • Set SortGroupModus = SORTGROUP__CustomData
      • Set SortGroupCustomDataTrigger = Load CustomData STR <gen>
      • -------- CustomData needs you to define the trigger used to load the data. --------
      • Set SortGroupAscending = False
      • Set SortGroupAutoDestroy = True
      • Trigger - Run SortGroup <gen> (ignoring conditions)
      • For each (Integer A) from 1 to MSort_EndIndex, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) for 30.00 seconds the text: ((Name of SortGroupResult[MSort_Indices[(Integer A)]]) + ( amount of Str: + (String(SortGroupResultValue[MSort_Indices[(Integer A)]]))))
Credits
Changelog

  • V1.3b added more demo options to sor,t they are also choosen in a dialog after pressing ES. Demo Units are now sorted in a row instead of a colom.
  • V1.3a HpPercent & MpPercent were incorrect, added into Imports a ini-File useable by GUI-isator.
  • V1.3 Added Sort by HpPercent,MpPercent, added a missing variable for auto generation
  • V1.2 cleans now Index 1, Added adjust
Contents

SortGroup V1.3b (Map)

Reviews
Dr Super Good
Comments and Suggestions: Potentially useful to GUI users. Despite how easy the concept is, a lot of people do struggle with implementing sorting algorithms. A useful improvement might be if one could allow statistical ties to be resolved...
Level 12
Joined
Jun 12, 2010
Messages
413
Wow, this looks pretty useful! I like the fact that you also added the possibility of defining your own custom data. I'll test it out when I have the time, so I can give some feedback. But it looking good, and GUI compatibility is always nice xD

Something like this is great for creating custom abilities, like a triggered AoE heal that prioritizes damaged units. Though there are a lot of other applications one could come up with, too.
 
Last edited:
Yeah that's the reason why this was created at the first place, wanted to create an customizeable bouncing spell (supporting both damage and healing as option). After I wrote a version only supporting most/least, I though that could be more useful when allowing to choose more as least/most. Then got the idea that a sorting algo would produce such an behaviour and found some already made on hive. Flux's merge sort seems like a good one, it has a simlear demo, but sortgroup automates the group -> array stuff which most people have to do anyway when using it for groups.

Think some mod is actually missing but not sure which one it is.
 
This is what I got from the preview triggers. Please note that this is subject to changes, and may soon be overridden.

NOTES:

  • Function names are clear, clean and concise.
  • Not really a must-have for most mappers, but can be extremely useful for those with priority schemas.
  • You might want to add a warning to those who would use this to not spam the function calls.
With that being said, I would say that this is a well-done system, definitely helpful for those who fall under what I have stated above.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Required for Approval:
Fix the in game information text. Currently it appears to be a leftover from another spell completely unrelated to this. It says that pressing Esc will get the unit closest to the facing of the Peasant. However it should say that pressing Esc will sort all units into a column by current health percentage.
Comments and Suggestions:
Potentially useful to GUI users. Despite how easy the concept is, a lot of people do struggle with implementing sorting algorithms.

Might be useful to add additional demonstrations showing the results of different sort modes. Especially with the custom sort mode this could help people understand it more easily. Maybe implemented by dialog or separate unit groups.​
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Comments and Suggestions:
Potentially useful to GUI users. Despite how easy the concept is, a lot of people do struggle with implementing sorting algorithms.

A useful improvement might be if one could allow statistical ties to be resolved deterministically, eg by unit handle ID value, rather than seemingly randomly. Currently if one selects to sort by stats like strength, which not all units have, then the units without strength will shuffle order randomly each time. This might or might not be desirable depending on intended use. A possible implementation to control such behaviour could be a global boolean variable the user can set.​
 
Top