• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Sorting players by Gold

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
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 41
Joined
Jun 9, 2011
Messages
13,248
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