.-=Clan Miami Killers=-.
Other => Scripting => Topic started by: Rocky 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.
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. ;)
-
from where do you learn all these stuff.
btw nice work....
-
from where do you learn all these stuff.
btw nice work....
Bubble sort from school and squirrel myself :P
-
Nice work :D
-
There's a better way to do so, but it's fine though.
-
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 :)
-
so wheres the cookie?
-
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.
-
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?
(http://blogs.babble.com/toddler-times/files/2012/07/Chocolate_chip_cookies.jpg)
-
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.
-
gr8 job m8