February 24, 2018, 04:02:25 am

Author Topic: [Bubble sort]Get Top 3 Players  (Read 801 times)

0 Members and 1 Guest are viewing this topic.

[MK]Rocky

  • Newbie
  • *
  • Posts: 8
  • Country: in
    • View Profile
    • Awards
[Bubble sort]Get Top 3 Players
« on: December 07, 2013, 02:00:51 pm »
Get Top 3 Players according to their score, kills, K/D ratio, money.

This is one of the thousand ways to get top players according to their Kills, Cash etc.. This example will print the top three richest player in the server, I am sure with minor edits you can use this method to find best killers online. I used Bubble sorting in this code to sort.

Code: [Select]
Plr <- { };
function GetTop3( player )
{
local t, ta,i,j,k=0;
for(i=0;i<GetMaxPlayers();i++)
{
     if( FindPlayer( i ) )
{
        Plr[ i ] <- { };
        Plr[ i ].Nick <- player.Name.tostring();
        Plr[ i ].Money <- FindPlayer( i ).Cash;
k++;
         }
}
  //Player1: 2 p2: 3 p3: 4
  for(j=0;j<GetMaxPlayers();j++)
  {
    for(i=0;i<GetMaxPlayers()-1-j;i++)
{
    if( Plr.rawin( i ) && Plr.rawin( i + 1 ) && Plr[ i ].Money < Plr[ i + 1 ].Money )
{
     t = Plr[ i + 1 ].Nick;
ta = Plr[ i + 1 ].Money;
Plr[ i + 1 ].Nick <- Plr[ i ].Nick;
Plr[ i + 1 ].Money <- Plr[ i ].Money;
Plr[ i ].Nick <- t;
Plr[ i ].Money <- ta;
         }
    }
}
PrivMessage("Richest Players Online:",player );
for(i=0,j=1;i<k;i++,j++)
PrivMessage( j + ". " + Plr[ i ].Nick + " - " + Plr[ i ].Money,player );
}

To use this in your script paste the above code in your script files and add a command to call the function. Please report if you find any bugs.  ;)
Useful Useful x 1 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor