Score/rank positions... help!
#1

Hello everybody!
How I can make a rank with online players based in they score(example)?

Example:
50 players online...
How to show the position of all in menus or textdraws like
1°- PLAYER
2°- PLAYER
3°- PLAYER
...
50°- PLAYER

THANKS!
Reply
#2

There was a function made by ******, where you can arrange items by its size, cant remember how it was called.

But you can easly figure it out by self, by storing highest score and then comparing it with next one and next one.

like

new PlayerScore = 6;
if(PlayerScore >= Score[0])
{
Score[1] = Score[0];
Score[0] = PlayerScore; // New highest
}
Reply
#3

If you're using MySQL its far more easier. Can be done in descending as well as ascending order.
Reply
#4

Someone can help me?
Reply
#5

Use the ORDER BY clause(if MySQL).
Reply
#6

pawn Код:
QuickSort_Pair(array[][2], bool:desc, left, right)
{
    #define PAIR_FIST (0)
    #define PAIR_SECOND (1)

    new
        tempLeft = left,
        tempRight = right,
        pivot = array[(left + right) / 2][PAIR_FIST],
        tempVar
    ;
    while (tempLeft <= tempRight)
    {
        if (desc)
        {
            while (array[tempLeft][PAIR_FIST] > pivot)
            {
                tempLeft++;
            }
            while (array[tempRight][PAIR_FIST] < pivot)
            {
                tempRight--;
            }
        }
        else
        {
            while (array[tempLeft][PAIR_FIST] < pivot)
            {
                tempLeft++;
            }
            while (array[tempRight][PAIR_FIST] > pivot)
            {
                tempRight--;
            }
        }

        if (tempLeft <= tempRight)
        {
            tempVar = array[tempLeft][PAIR_FIST];
            array[tempLeft][PAIR_FIST] = array[tempRight][PAIR_FIST];
            array[tempRight][PAIR_FIST] = tempVar;

            tempVar = array[tempLeft][PAIR_SECOND];
            array[tempLeft][PAIR_SECOND] = array[tempRight][PAIR_SECOND];
            array[tempRight][PAIR_SECOND] = tempVar;

            tempLeft++;
            tempRight--;
        }
    }
    if (left < tempRight)
    {
        QuickSort_Pair(array, desc, left, tempRight);
    }
    if (tempLeft < right)
    {
        QuickSort_Pair(array, desc, tempLeft, right);
    }

    #undef PAIR_FIST
    #undef PAIR_SECOND
}
Usage example:
pawn Код:
new data[MAX_PLAYERS][2];
new count;
for (new i, j = GetPlayerPoolSize(); i <= j && IsPlayerConnected(i); i++)
{
    data[i][0] = GetPlayerScore(i);
    data[i][1] = i;

    count++;
}

QuickSort_Pair(data, true, 0, count);

SendClientMessage(playerid, -1, "Top players with high-score:");
new buf[150];
for (new i; i < count; i++)
{
    if (data[i][0])
    {
        format(buf, sizeof(buf), "%i. %s(%i) - %i", i + 1, ReturnPlayerName(data[i][1]), data[i][1], data[i][0]);
        SendClientMessage(playerid, -1, buf);
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)