16.07.2011, 15:38
how can i get the top players from my server ?
By their score ?
PLS help
By their score ?
PLS help
new highestid = INVALID_PLAYER_ID, highest = -1;
for(new i = 0; i < MAX_PLAYERS; ++i)
{
if(GetPlayerScore(i) > highest)
{
highestid = i;
highest = GetPlayerScore(i);
}
}
if(highestid != INVALID_PLAYER_ID)
{
//your function...
}
to get the highest score use this
pawn Код:
|
COMMAND:top10(playerid, params[])
{
new TopPlayers[9+1];
new highestid = INVALID_PLAYER_ID, highest = -1;
SendClientMessage(playerid,YELLOW,"Top 10 Players");
new MAX;
MAX=0;
for(new i = 0; i < MAX_PLAYERS; ++i)
{
if(GetPlayerScore(i) > highest && MAX<=10)
{
MAX++;
highestid = i;
highest = GetPlayerScore(i);
new Name[MAX_PLAYER_NAME];GetPlayerName(i,Name,sizeof(Name));
new TOP[128];format(TOP,sizeof(TOP),"[%d]%s",TopPlayers,Name);
SendClientMessage(playerid,YELLOW,TOP);
}
return 1;
}
if(highestid != INVALID_PLAYER_ID && TopPlayers[0])
{
SendClientMessage(playerid,YELLOW,"Num 1");
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/top10", true) == 0)
{
new top, str[64], maxx;
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(GetPlayerScore(i) > top) { top = GetPlayerScore(i); }
}
for(new t = top; t >= 0; t--)
{
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(!IsPlayerConnected(i)) continue;
if(GetPlayerScore(i) != t) continue;
new n[24];
GetPlayerName(i, n, 24);
maxx++;
format(str, sizeof str, " %d >> %s - Score: %d", maxx, n, GetPlayerScore(i));
SendClientMessage(playerid, 0xFFFF00FF, str);
}
if(maxx == 10) break;
}
return 1;
}
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/top10", true) == 0)
{
new top, str[64], str2[256], maxx;
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(GetPlayerScore(i) > top) { top = GetPlayerScore(i); }
}
for(new t = top; t >= 0; t--)
{
for(new i = 0; i < MAX_PLAYERS; i ++)
{
if(!IsPlayerConnected(i)) continue;
if(GetPlayerScore(i) != t) continue;
GetPlayerName(i, str, 24);
maxx++;
format(str, sizeof str, " %d >> %s - Score: %d", maxx, str, GetPlayerScore(i));
strcat(str2, str);
}
ShowPlayerDialog(playerid, 150, "TOP 10", str2, "Close", "");
if(maxx == 10) break;
}
return 1;
}
return 0;
}
PHP код:
|
#include <a_samp>
new VQS[2][MAX_PLAYERS];
stock quickSort(start, end)
{
new pivot = VQS[0][(start + end) / 2],
i = start,
j = end,
aux;
while(i <= j)
{
while(VQS[0][i] < pivot) i++;
while(VQS[0][j] > pivot) j--;
if(i <= j)
{
/*Change vals*/ aux = VQS[0][i], VQS[0][i] = VQS[0][j], VQS[0][j] = aux;
/*Change IDs*/ aux = VQS[1][i], VQS[1][i] = VQS[1][j], VQS[1][j] = aux;
i++, j--;
}
}
if(start < j) quickSort(start, j);
if(end > i) quickSort(i, end);
}
// Add this under OnPlayerCommandText
if(!strcmp(cmdtext, "/top10", true))
{
new str[36], string[(10*MAX_PLAYER_NAME) + 1 + 36], pName2[MAX_PLAYER_NAME];
new k = 0;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
VQS[0][k] = GetPlayerScore(i);
VQS[1][k++] = i;
}
}
if(k > 1)
{
quickSort(0, k-1);
for(new j = 0, x = (k > 10 ? (10) : (k)); j < x; j++)
{
GetPlayerName(VQS[1][j], pName2, MAX_PLAYER_NAME);
format(str, 36, "{FFFFFF}%d. {62ACE0}%s - {E06262}%d score\n", j+1, pName2, VQS[0][j]);
strcat(string, str);
}
ShowPlayerDialog(playerid, 0xFF, DIALOG_STYLE_LIST, "TOP 10", string, "OK", "");
}
else SendClientMessage(playerid, -1, "Can't make a TOP !");
return 1;
}