[SOLVED] Sorting Function
#1

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
Reply
#2

I guess that this function should be in the Las Venturas Moneygrub gamemode. Try to look it up there.
Reply
#3

Ok ... let Me see

EDIT: Nope, No Success
Reply
#4

[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;
}
Reply
#5

Sorry for double post.
Reply
#6

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

Reply
#7

Code:
SortArray(PlayerRank.PlayerScore);
for(new i; i < MAX_PLAYERS;i++){
  printf("id:%03d score:%09d rank:%03d",PlayerRank[i],PlayerScore[PlayerRank[i]],i);
}
Reply
#8

Thank You So Much ..
Reply
#9

No thx,^^
I have 1 suggestion, edit headline as solved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)