1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  5. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  6. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  7. The results are out! Check them out.
    Dismiss Notice
  8. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  9. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  10. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

SortGroup [GUI Friendly]

Submitted by Tasyen
This bundle is marked as approved. It works and satisfies the submission rules.
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.
Variable Info


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

Flux
chobibo

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...
  1. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    354
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    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: Jan 16, 2018
  2. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,304
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    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.
     
  3. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,305
    Resources:
    7
    Models:
    1
    Icons:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    7
    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.
     
  4. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,305
    Resources:
    7
    Models:
    1
    Icons:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    7
    Added GUI/Triggers tag as it allows GUIers to utilize the bundle.
     
  5. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.​
     
  6. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,304
    Resources:
    16
    Tools:
    2
    Maps:
    2
    Spells:
    7
    Tutorials:
    4
    JASS:
    1
    Resources:
    16
    Uploaded SortGroup 1.3b: added more demo sort options and all can now be used (one by one) without having to restart the map. Renamed the demo Triggers and changed the demo info msg.
     
    Last edited: May 15, 2019
  7. Daffa the Mage

    Daffa the Mage

    Map Moderator

    Joined:
    Jan 30, 2013
    Messages:
    7,662
    Resources:
    27
    Packs:
    1
    Maps:
    8
    Spells:
    16
    Tutorials:
    2
    Resources:
    27
    Nice, just what I need to improve one of my works!
     
  8. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.​