Ordering integer array

ArmyOfFrogs

New Member
Reaction score
20
Is there any easy way to order the integers in an array from greatest to least? I was thinking you could a lot of if/then/elses in order to figure out the correct ranking, but there's got to be some easier way to do this. I'll be working on a more.. efficient way of doing this, but if you know one please post the general idea, doesn't have to be coded ^^

Thanks

Edit: The array is size 10, thats why it would be ridiculous to do if/then/elses for it all ;\
 

Faust

You can change this now in User CP.
Reaction score
123
Trigger:
  • For each (Integer A) from 1 to 10, do (Actions)
    • Loop - Actions
      • Set String[(Integer A)] = <Empty String>
 

ArmyOfFrogs

New Member
Reaction score
20
Sorry I guess I didn't clarify enough. I want the values of DamageDone[1-10] put in order in DamageShowOrder[1-10]. So say #5 in damage done is the highest, then #9, then #2, then 4, 1, , 6 , 3, 7, 8. I want DamageShowOrder[1] to be equal to DamageDone[5], DamageShowOrder[2] = DamageDone[9], DamageShowOrder[3] = DamageDone[2], etc.
 

jig7c

Stop reading me...-statement
Reaction score
123
do you have a way to figure how who did the most damage?
 

ArmyOfFrogs

New Member
Reaction score
20
Currently... Nope ;[ I just have their total damage being stored in DamageDone[player number].

Though I mean i can do about 300-400 if then elses to figure it out, but there's got to be a way to use loops in this ._.
 

Romek

Super Moderator
Reaction score
963
If there are only 10 values, you could make a leaderboard, add the values for Player(index), then sort the leaderboard. From there, you can get the positions of the players.

You don't need to show the leaderboard.
 

WilliamPa

Active Member
Reaction score
51
Loop integer in a loop, and check each number individually. First loop resembles the arrays, second one resembles it's location. So each array is set to start from 1, and checked if they are higher than array loopB + 1, if yes, swap their locations.

I suck teaching <.<
 

ArmyOfFrogs

New Member
Reaction score
20
Trigger:
  • DmgOrder
    • Events
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled damage order
      • Leaderboard - Hide (Last created leaderboard)
      • Player Group - Pick every player in (All players matching ((((Matching player) slot status) Equal to Is playing) and (((Matching player) controller) Equal to User))) and do (Actions)
        • Loop - Actions
          • Leaderboard - Add (Picked player) to (Last created leaderboard) with label Rank and value DamageMeter[(Player number of (Picked player))]
      • Leaderboard - Sort (Last created leaderboard) by Value in Descending order
      • For each (Integer A) from 1 to PlayersActive, do (Actions)
        • Loop - Actions
          • Set DmgShowNames[(Integer A)] = (Name of (Player in position (Integer A) of (Last created leaderboard)))
          • Set DmgShowOrder[(Integer A)] = (Position of Player[(Integer A)] in (Last created leaderboard))


Trigger:
  • DmgShow
    • Events
      • Player - Player 1 (Red) types a chat message containing -dmg as An exact match
      • Player - Player 2 (Blue) types a chat message containing -dmg as An exact match
      • Player - Player 3 (Teal) types a chat message containing -dmg as An exact match
      • Player - Player 4 (Purple) types a chat message containing -dmg as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -dmg as An exact match
      • Player - Player 6 (Orange) types a chat message containing -dmg as An exact match
      • Player - Player 7 (Green) types a chat message containing -dmg as An exact match
      • Player - Player 8 (Pink) types a chat message containing -dmg as An exact match
      • Player - Player 9 (Gray) types a chat message containing -dmg as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -dmg as An exact match
    • Conditions
    • Actions
      • Trigger - Run DmgOrder &lt;gen&gt; (ignoring conditions)
      • Wait 0.50 seconds
      • For each (Integer A) from 1 to PlayersActive, do (Actions)
        • Loop - Actions
          • Game - Display to (Player group(Player[(Player number of (Triggering player))])) the text: (DmgShowNames[(Integer A)] + <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> + (String(DamageMeter[DmgShowOrder[(Integer A)]]))))

PlayersActive is just the number of users playing.
Will that work? Thanks for the tip romek, had no idea leaderboards had the capability of sorting stuff.

Edit: Has worked so far, going to post in tutorials incase someone else needs the full trigger ^^
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top