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

[General] How to calculate the position of the player by leaderboard?

Status
Not open for further replies.
In my map there are 10 players and 2 teams. 1-5, 6-10
Their damage is collected through the whole game. And at the end of the game you can see their position by damage in the leaderboard.
Then, what I want to do is to put each hero of every player on pedestral, depending on his position of damage in his team.
There is function in the integer triggers leaderboard - position of player in <leaderboard>, however I do not know how to get #1 #2 #3 #4 and #5 player by damage from each team. Could you help me?

TIP: the damage of every player is stored in integer variable array DAMAGE_INT[array] and then displayed in the leaderboard.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Something like this might work.

  • Events
  • Conditions
  • Actions
    • For each integer A from 1 to 10 do (multiple actions)
      • loop
        • set tempInt = position of Player(Integer A) in MyLeaderboard
        • set damageRank[tempInt] = Integer A
    • set tempInt1 = 0
    • set tempInt2 = 0
    • For each integer A from 1 to 10 do (multiple actions)
      • loop
        • set tempInt = damageRank[(Integer A)]
        • if (multiple actions)
          • conditions
            • tempInt is Less than or equal to 5
          • then
            • set tempInt1 = tempInt + 1
            • team1DamageRank[tempInt1] = tempInt
          • else
            • set tempInt2 = tempInt2 + 1
            • set team2DamageRank[tempInt2] = tempInt
At the end, team1DamageRank is an array with 1-5 being the team 1 players in order from most damage to least damage and team2DamageRank is the same except for the other team.

tempInt, tempInt1, and tempInt2 are all integers that you can replace with whatever you want. Since they are only used in this one trigger and other triggers won't likely be called, you can use some temporary ones if you have any like that.

team1DamageRank, team2DamageRank, and damageRank are integer arrays and they are used to store player numbers.

MyLeaderboard is your leaderboard. I don't know if the function to find the player placement starts from 0 or 1, but I assumed it starts at 1. I also haven't used the function so I don't know if it has any problems or if it does what I think it does.

You'd have to place the units after these loops or you can replace the part where it sets team1DamageRank and team2DamageRank with your code to place the heroes on the pedestals. You'd just use the "then" part for placing them on team 1 pedestals and the else part for placing them on the team 2 pedestals.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
I did exactly this not too long ago, I will see if I can find the thread.

edit:
  • Untitled Trigger 002
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set A[0] = 5
      • Set A[1] = 3
      • Set A[2] = 6
      • Custom script: call wtf()
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

Code from wikipedia:
Code:
for i = 1 to length(A) - 1
    x = A[i]
    j = i
    while j > 0 and A[j-1] > x
        A[j] = A[j-1]
        j = j - 1
    end while
    A[j] = x
 end for
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
You copy the jass into your map set all scores into the A variable. ( A[number] ) then call the function "wtf" as shown in the GUI part.

Once that's done all the numbers will be re-arranged into order. so A[0] will be the lowest value.

edit: I will update this post with a little better demo, give me a few mins.

edit2: Okay gave 'all' players a score which is random between 1 and 100 and it gave the following result.
99983f4925991479c5139571deede925.png

JASS:
//! zinc
    library test
    {
        public function wtf(integer max)
        {
            integer i, j, x = 0;
            for(0 <= i < max)
            {
                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 < max)
            {
                BJDebugMsg(I2S(udg_A[i]));
            }
        }
    }
//! endzinc
  • demo
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- This should be set properly, but I just set it to 5 for test purposes --------
      • Set numberOfPlayers = 5
      • For each (Integer A) from 0 to numberOfPlayers, do (Actions)
        • Loop - Actions
          • Set A[(Integer A)] = (Random integer number between 1 and 100)
      • Custom script: call wtf(udg_numberOfPlayers)
 
Status
Not open for further replies.
Top