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

Sorting players by Gold

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Try one of the many ways to sort collections of data.

I personally would recommend the rather inefficient but easy to implement Linear Search. Use a force (player group) for the unsorted players. Find the best from the force, add it to a player list in the form of a player array and then remove it from the force. Repeat until the force is empty and player list is full and in order.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
Just use the "detect the closest unit" trigger (Sorting distances) to make a "detect the richest player" trigger.

  • Closest Unit of Type
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Detect the Closest Unit
    • Actions
    • Set TempLocA = (Position of (Casting unit))
    • Set TempRealB = 1000000000.00
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) belongs to an ally of (Owner of (Casting unit))) Equal to True) and ((Unit-type of (Matching unit)) Equal to Goblin Shipyard)))) and do (Actions)
      • Loop - Actions
        • Set TempLocB = (Position of (Picked unit))
        • Set TempRealA = (Distance between TempLocA and TempLocB)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TempRealA Less than TempRealB
          • Then - Actions
            • Custom script: set udg_TempUnitA = null
            • Set TempUnitA = (Picked unit)
            • Set TempRealB = TempRealA
          • Else - Actions
            • Custom script: call RemoveLocation(udg_TempLocB)
            • Custom script: call RemoveLocation(udg_TempLocA)
    • -------- So in the end TempUnitA will be the closest Goblin Shipyard that is allied to your unit. --------
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
No problem, I've been thinking about a little idea to achieve this in another way.
Maybe (as far as I remember) the leader board has some 'ascending/descending' orders for its rows. Maybe sorting the values in a hidden leaderboard then make the order you want, then determine which value is at the first row and whose it is (I don't know if this exists but if it does, I assure it does work.)
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
This was requested here:
http://www.hiveworkshop.com/forums/triggers-scripts-269/finding-x-lowest-hp-values-area-270212/

Which led me to doing the following:
Thank you, Zwie. It works now.

This is the code that worked in case someone finds this thread at a later date and wonders.
JASS:
//! zinc
    library test
    {
        public function wtf()
        {
            integer i, j, x = 0;
            for(0 <= i < 3)
            {
                x = udg_A[i];
                j = i;
                while(j > 0 && udg_A[j - 1] > x)
                {
                    udg_A[j] = udg_A[j - 1];
                    j = j - 1;
                }
                udg_A[j] = x;
            }
            i = 0;
            for(0 <= i < 3)
            {
                BJDebugMsg(I2S(udg_A[i]));
            }
        }
    }
//! endzinc

This sorts the values in the array A[0-2] and be be changed to your purpose.
 
Status
Not open for further replies.
Top