•  
Welcome, Guest. Please login or register.

News:


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

Offline Rocky

  • [MK]
  • Godfather
  • *
  • Posts: 359
  • Karma: +0/-0
    • View Profile
[SQUIRREL][Bubble sort]Get Top 3 Players
« on: December 07, 2013, 02:48:46 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.  ;)

Offline DeViL_JiN

  • [MK]
  • Godfather
  • *
  • Posts: 318
  • Karma: +0/-0
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #1 on: December 07, 2013, 04:44:26 pm »
from where do you learn all these stuff.
btw nice work....

Offline Rocky

  • [MK]
  • Godfather
  • *
  • Posts: 359
  • Karma: +0/-0
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #2 on: December 08, 2013, 04:17:09 am »
from where do you learn all these stuff.
btw nice work....

Bubble sort from school and squirrel myself :P

Offline Anirudh

  • OG ROCKS :D
  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
  • My website 8) www.pirated-things.com
    • View Profile
    • Pirated Things
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #3 on: December 08, 2013, 12:00:22 pm »
Nice work :D


Quote
Give me Pelikan theme i beg your leg pls i will do whatever you will say my boss - Klitz

Offline Nexus

  • MK Server Founder
  • Godfather
  • *
  • Posts: 991
  • Karma: +0/-0
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #4 on: December 12, 2013, 01:57:18 pm »
There's a better way to do so, but it's fine though.

Offline Rocky

  • [MK]
  • Godfather
  • *
  • Posts: 359
  • Karma: +0/-0
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #5 on: December 12, 2013, 02:31:52 pm »
There's a better way to do so, but it's fine though.

Like i mentioned there are lots of ways to sort but if you referring to inbuilt squirrel .sort function? I came to know about it after i created this. By the way thanks for teaching me the { } array method, I learned a lot after this method came into my mind :)

Offline FaF

  • Administrator
  • Godfather
  • *
  • Posts: 2370
  • Karma: +11/-3
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #6 on: December 12, 2013, 03:10:05 pm »
so wheres the cookie?

Offline NewK

  • Administrator
  • Godfather
  • *
  • Posts: 1508
  • Karma: +0/-1
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #7 on: December 12, 2013, 06:09:26 pm »
Yea there's alot of sorting algorithms you can use. Bubble sort works fine if the amount of data to organize isn't as big. Quicksorting will be alot faster though, if the amount of data to organize is bigger.

Offline Rocky

  • [MK]
  • Godfather
  • *
  • Posts: 359
  • Karma: +0/-0
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #8 on: December 13, 2013, 03:29:59 am »
Yea there's alot of sorting algorithms you can use. Bubble sort works fine if the amount of data to organize isn't as big. Quicksorting will be alot faster though, if the amount of data to organize is bigger.

Sorting players of maximum 50 isn't that big, is it? I'll Google Quicksort.

so wheres the cookie?


Offline NewK

  • Administrator
  • Godfather
  • *
  • Posts: 1508
  • Karma: +0/-1
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #9 on: December 13, 2013, 05:14:57 pm »
Yea there's alot of sorting algorithms you can use. Bubble sort works fine if the amount of data to organize isn't as big. Quicksorting will be alot faster though, if the amount of data to organize is bigger.
Sorting players of maximum 50 isn't that big, is it? I'll Google Quicksort.
I don't think so, I never really used any sorting algorithms in squirrel before so X_94 would know better. For only 50 items, I believe that bubble sort is fast enough though. Infact, I believe that using Quicksort instead of Bubble Sort to sort 50 items only wouldn't really show any noticeable difference in speed since the amount of data to sort is so little. Then again, I have very little experience with squirrel so other people would know better.

Offline Cerberus

  • Godfather
  • *
  • Posts: 619
  • Karma: +0/-0
    • View Profile
Re: [SQUIRREL][Bubble sort]Get Top 3 Players
« Reply #10 on: April 14, 2016, 04:39:03 pm »
gr8 job m8
« Last Edit: April 14, 2016, 04:55:43 pm by Cerberus »