Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Sorting players by Gold

Discussion in 'World Editor Help Zone' started by Evil seal, Oct 5, 2015.

  1. Evil seal

    Evil seal

    Joined:
    Nov 23, 2009
    Messages:
    238
    Resources:
    2
    Icons:
    2
    Resources:
    2
    I need to make a trigger that finds the player with the most gold among all players. I'm not sure on how to go about this and would greatly appreciate some advice.
     
  2. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,132
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  3. jonhysone

    jonhysone

    Joined:
    Oct 29, 2012
    Messages:
    1,241
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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. --------
     
  4. Evil seal

    Evil seal

    Joined:
    Nov 23, 2009
    Messages:
    238
    Resources:
    2
    Icons:
    2
    Resources:
    2
    Thanks alot to you both.
     
  5. jonhysone

    jonhysone

    Joined:
    Oct 29, 2012
    Messages:
    1,241
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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.)
     
  6. Chaosy

    Chaosy

    Tutorial Reviewer

    Joined:
    Jun 9, 2011
    Messages:
    11,066
    Resources:
    18
    Icons:
    1
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    18
    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:
    This sorts the values in the array A[0-2] and be be changed to your purpose.