1st/2nd/3rd place, from player scores?

Fulla

Evil Overlord
Reaction score
31
For a minigame map at the end I have each player with a score.
PScore[integer 0-11]

Im not sure the best way how to display the top 3 from highest to lowest>

Is there an easy method?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
I would say somthing like that:

JASS:

function This_Might_Work takes nothing returns nothing
    local integer array points
    local integer array scores
    local integer counter = 0
    local string array name

    set points[0] = //Player 0 current points
    set points[1] = //Player 1 current points
    set points[2] = //Player 2 current points
    set points[3] = //Player 3 current points

    // etc...

    set scores[1] = 0
    set scores[2] = 0
    set scores[3] = 0

    loop
        exitwhen counter > 11
        if points[counter] > scores[1] then
            set scores[1] = points[counter]
            set name[1] = GetPlayerName(Player(counter)
        elseif points[counter] > scores[2] then
            set scores[2] = points[counter]
            set name[2] = GetPlayerName(Player(counter)
        elseif points[counter] > scores[3] then
            set scores[3] = points[counter]
            set name[3] = GetPlayerName(Player(counter)
        endif
        set counter = counter + 1
    endloop

// do somthing

endfunction
 

substance

New Member
Reaction score
34
My try

JASS:
    loop
       exitwhen i == 11
       if PScore<i> &gt; first then
          set first = second
          set first = i
       elseif PScore<i> &gt; second then
          set second = third       
          set second = i
       elseif PScore<i> &gt; third then
          set third = i
       endif          
       set i = i + 1
    endloop
    
    call BJDebugMsg (&quot;Highest score is &quot;+I2S(PScore[first]))
//  etc..</i></i></i>
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
A somewhat simpler way that gives both the player and his score would be to add them to a leaderboard, sort it and read the players back in order.
Even simpler, just show the board :p

You also need to consider the fact that two or more players may have identical scores...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top