Score/rank positions... help! - 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)
+--- Thread: Score/rank positions... help! (
/showthread.php?tid=600541)
Score/rank positions... help! -
JR_Junior - 09.02.2016
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!
Re: Score/rank positions... help! -
ikey07 - 09.02.2016
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
}
Re: Score/rank positions... help! -
Ritzy2K - 09.02.2016
If you're using MySQL its far more easier. Can be done in descending as well as ascending order.
Re: Score/rank positions... help! -
JR_Junior - 09.02.2016
Someone can help me?
Re: Score/rank positions... help! -
Ritzy2K - 09.02.2016
Use the ORDER BY clause(if MySQL).
Re: Score/rank positions... help! -
Gammix - 09.02.2016
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);
}
}