[SOLVED] Sorting Function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED] Sorting Function (
/showthread.php?tid=84685)
[SOLVED] Sorting Function -
abhinavdabral - 02.07.2009
I have already search on this forum, but didn't found one.
I need a function that will sort the Player Scores and give me the rank of the player .... like 1st is he/she has the greatest score and 2nd , 3rd etc.....
Thank You for helping in Advance
EDIT: SOLVED - See below the page for the solution.
-Abhinav
Re: [HELP] Sorting Function -
refshal - 02.07.2009
I guess that this function should be in the Las Venturas Moneygrub gamemode. Try to look it up there.
Re: [HELP] Sorting Function -
abhinavdabral - 02.07.2009
Ok ... let Me see
EDIT: Nope, No Success
Re: [HELP] Sorting Function -
yezizhu - 03.07.2009
[quote=?

]
SortArray
I searched in the forum for a function like that but with no result, so I made this.
pawn Code:
stock SortArray(array[], source[], methode = 0, a_size = sizeof array, s_size = sizeof source)
{ //By Nero_3D - 10. May 2009
for(new i; i < a_size; i++) array[i] = -1;
switch(methode)
{
case 0:
for(new i, y, j; i < s_size; i++)
for(y = 0; y < a_size; y++)
if(source[i] > ((array[y] == -1) ? (-1) : (source[array[y]])))
{
for(j = a_size - 2; j >= y; j--)
array[j + 1] = array[j];
array[y] = i;
break;
}
case 1:
for(new i, y, j; i < s_size; i++)
for(y = 0; y < a_size; y++)
if(source[i] < ((array[y] == -1) ? (0x7F800000) : (source[array[y]])))
{
for(j = a_size - 2; j >= y; j--)
array[j + 1] = array[j];
array[y] = i;
break;
}
default: return false;
}
return true;
}
Re: [HELP] Sorting Function -
yezizhu - 03.07.2009
Sorry for double post.
Re: [HELP] Sorting Function -
abhinavdabral - 04.07.2009
Please can u tell me an example, that how can i use it ...
Say the two arrays are
PlayerScore[200];
PlayerRank[200];
I want to sort score an put it into rank.
By The Way, THANKS For Helping
-Abhinav
Re: [HELP] Sorting Function -
yezizhu - 04.07.2009
Code:
SortArray(PlayerRank.PlayerScore);
for(new i; i < MAX_PLAYERS;i++){
printf("id:%03d score:%09d rank:%03d",PlayerRank[i],PlayerScore[PlayerRank[i]],i);
}
Re: [HELP] Sorting Function -
abhinavdabral - 04.07.2009
Thank You So Much ..
Re: [HELP] Sorting Function -
yezizhu - 04.07.2009
No thx,^^
I have 1 suggestion, edit headline as solved.