Top 10 ?
#1

how can i get the top players from my server ?

By their score ?
PLS help
Reply
#2

to get the highest score use this
pawn Код:
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...
}
Reply
#3

Quote:
Originally Posted by park4bmx
Посмотреть сообщение
to get the highest score use this
pawn Код:
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...
}
ok ty but i want the TOP 10 players /:
Reply
#4

well, try this:

#include <a_samp>
#define I3 13
public OnFilterScriptInit() return 1;
public OnFilterScriptExit() return 1;
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/top10", cmdtext, true, 6) == 0)
{
new Player[10] = {-1,...}, PlayersScore[10];

// #1
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[0])
{
PlayersScore[0] = GetPlayerScore(p);
Player[0] = p;
}
}

// #2
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[1] && p != Player[0])
{
PlayersScore[1] = GetPlayerScore(p);
Player[1] = p;
}
}

// #3
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[2] && p != Player[0] && p != Player[1])
{
PlayersScore[2] = GetPlayerScore(p);
Player[2] = p;
}
}
// #4
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[3] && p != Player[0] && p != Player[1] && p != Player[2])
{
PlayersScore[3] = GetPlayerScore(p);
Player[3] = p;
}
}
// #5
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[4] && p != Player[0] && p != Player[1] && p != Player[2] && p != Player[3])
{
PlayersScore[4] = GetPlayerScore(p);
Player[4] = p;
}
}
// #6
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[5] && p != Player[0] && p != Player[1] && p != Player[2] && p != Player[3] && p != Player[4])
{
PlayersScore[5] = GetPlayerScore(p);
Player[5] = p;
}
}
// #7
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[6] && p != Player[0] && p != Player[1] && p != Player[2] && p != Player[3] && p != Player[4] && p != Player[5])
{
PlayersScore[6] = GetPlayerScore(p);
Player[6] = p;
}
}
// #8
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[7] && p != Player[0] && p != Player[1] && p != Player[2] && p != Player[3] && p != Player[4] && p != Player[5] && p != Player[6])
{
PlayersScore[7] = GetPlayerScore(p);
Player[7] = p;
}
}
// #9
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[8] && p != Player[0] && p != Player[1] && p != Player[2] && p != Player[3] && p != Player[4] && p != Player[5] && p != Player[6] && p != Player[7])
{
PlayersScore[8] = GetPlayerScore(p);
Player[8] = p;
}
}
// #10
for(new p = 0; p < MAX_PLAYERS; p++)
{
if(IsPlayerConnected(p) && GetPlayerScore(p) > PlayersScore[9] && p != Player[0] && p != Player[1] && p != Player[2] && p != Player[3] && p != Player[4] && p != Player[5] && p != Player[6] && p != Player[7] && p != Player[8])
{
PlayersScore[9] = GetPlayerScore(p);
Player[9] = p;
}
}

new Stringas[512];
format(Stringas, 512,"\t\tServerio TOP 10 pagal score\n\n#1 - %s - %d pts\n#2 - %s - %d pts\n#3 - %s - %d pts\n#4 - %s - %d pts\n#5 - %s - %d pts\n#6 - %s - %d pts\n#7 - %s - %d pts\n#8 - %s - %d pts\n#9 - %s - %d pts\n#10 - %s - %d pts",
GetName(Player[0]), PlayersScore[0],
GetName(Player[1]), PlayersScore[1],
GetName(Player[2]), PlayersScore[2],
GetName(Player[3]), PlayersScore[3],
GetName(Player[4]), PlayersScore[4],
GetName(Player[5]), PlayersScore[5],
GetName(Player[6]), PlayersScore[6],
GetName(Player[7]), PlayersScore[7],
GetName(Player[8]), PlayersScore[8],
GetName(Player[9]), PlayersScore[9]);

ShowPlayerDialog(playerid, I3, DIALOG_STYLE_MSGBOX, "Server TOP 10", Stringas, "OK", "Exit");
return 1;
}
return 0;
}
stock GetName(playerid)
{
new Player_Name[MAX_PLAYER_NAME];
if(IsPlayerConnected(playerid)) GetPlayerName(playerid, Player_Name, MAX_PLAYER_NAME);
else Player_Name = "There is no name";
return Player_Name;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == I3) return 1;
return 1;
}


Reply
#5

oh sorry you wanted the top 10
i know Setkus allredy posted a code
but i made a really simple one but its not tested so if someone could test it it would be great
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;
}
Reply
#6

Made by me =D

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(
strcmp(cmdtext"/top10"true) == 0)
    {
        new 
topstr[64], maxx;
        for(new 
0MAX_PLAYERS++)
        {
            if(
GetPlayerScore(i) > top) { top GetPlayerScore(i); }
        }
        for(new 
top>= 0t--)
        {
            for(new 
0MAX_PLAYERS++)
            {
                if(!
IsPlayerConnected(i)) continue;
                if(
GetPlayerScore(i) != t) continue;
                new 
n[24];
                
GetPlayerName(in24);
                
maxx++;
                
format(strsizeof str" %d >> %s - Score: %d"maxxnGetPlayerScore(i));
                
SendClientMessage(playerid0xFFFF00FFstr);
            }
            if(
maxx == 10) break;
        }
        return 
1;
    }
    return 
0;

Reply
#7

Cananyone do it in Dialogs ..i also want this!!!
Reply
#8

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(
strcmp(cmdtext"/top10"true) == 0)
    {
        new 
topstr[64], str2[256], maxx;
        for(new 
0MAX_PLAYERS++)
        {
            if(
GetPlayerScore(i) > top) { top GetPlayerScore(i); }
        }
        for(new 
top>= 0t--)
        {
            for(new 
0MAX_PLAYERS++)
            {
                if(!
IsPlayerConnected(i)) continue;
                if(
GetPlayerScore(i) != t) continue;
                
GetPlayerName(istr24);
                
maxx++;
                
format(strsizeof str" %d >> %s - Score: %d"maxxstrGetPlayerScore(i));
                
strcat(str2str);
            }
            
ShowPlayerDialog(playerid150"TOP 10"str2"Close""");
            if(
maxx == 10) break;
        }
        return 
1;
    }
    return 
0;

Reply
#9

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if(
strcmp(cmdtext"/top10"true) == 0)
    {
        new 
topstr[64], str2[256], maxx;
        for(new 
0MAX_PLAYERS++)
        {
            if(
GetPlayerScore(i) > top) { top GetPlayerScore(i); }
        }
        for(new 
top>= 0t--)
        {
            for(new 
0MAX_PLAYERS++)
            {
                if(!
IsPlayerConnected(i)) continue;
                if(
GetPlayerScore(i) != t) continue;
                
GetPlayerName(istr24);
                
maxx++;
                
format(strsizeof str" %d >> %s - Score: %d"maxxstrGetPlayerScore(i));
                
strcat(str2str);
            }
            
ShowPlayerDialog(playerid150"TOP 10"str2"Close""");
            if(
maxx == 10) break;
        }
        return 
1;
    }
    return 
0;

Not working
Reply
#10

Quote:
Originally Posted by Ronaldo_raul™
Посмотреть сообщение
Not working
Try my code:
PHP код:
#include <a_samp>
new VQS[2][MAX_PLAYERS];
stock quickSort(startend)
{
    new 
pivot VQS[0][(start end) / 2],
        
start,
        
end,
        
aux;
    while(
<= j)
    {
        while(
VQS[0][i] < pivoti++;
        while(
VQS[0][j] > pivotj--;
        if(
<= 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 jquickSort(startj);
    if(
end   iquickSort(iend);
}
// Add this under OnPlayerCommandText
    
if(!strcmp(cmdtext"/top10"true))
    {
        new 
str[36], string[(10*MAX_PLAYER_NAME) + 36], pName2[MAX_PLAYER_NAME];
        new 
0;
        for(new 
0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                
VQS[0][k]   = GetPlayerScore(i);
                
VQS[1][k++] = i;
            }
        }
        if(
1)
        {
            
quickSort(0k-1);
            for(new 
0= (10 ? (10) : (k)); xj++)
            {
                
GetPlayerName(VQS[1][j], pName2MAX_PLAYER_NAME);
                
format(str36"{FFFFFF}%d. {62ACE0}%s - {E06262}%d score\n"j+1pName2VQS[0][j]);
                
strcat(stringstr);
            }
            
ShowPlayerDialog(playerid0xFFDIALOG_STYLE_LIST"TOP 10"string"OK""");
        }
        else 
SendClientMessage(playerid, -1"Can't make a TOP !");
        return 
1;

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)