#1

hey guys i did this command but it saying only my hours and my name but i have 10 account's in my `players` from db

Код HTML:
CMD:top10(playerid, params[])
{
    if(gLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Tu nu esti logat si nu poti sa folosesti aceasta comanda!");
    if(IsPlayerConnected(playerid))
	{
	    for(new i = 0; i < MAX_PLAYERS; i++)
	    {
			if(PlayerInfo[i][pHoursPlayed] >= 1)
			{
			    new sendername[30], string2[1000], coordsstring[1000];
				GetPlayerName(playerid, sendername, sizeof(sendername));
				
		        format(coordsstring, sizeof(coordsstring), "Nume\tOre jucate\n", sendername, PlayerInfo[playerid][pHoursPlayed]);
		    	strcat(string2, coordsstring);
		    	format(coordsstring, sizeof(coordsstring), "%s\t%d\n", sendername, PlayerInfo[playerid][pHoursPlayed]);
		    	strcat(string2, coordsstring);
		    	
			    ShowPlayerDialog(playerid, 1341345, DIALOG_STYLE_TABLIST_HEADERS, "Top 10 jucatori activi", string2, "Iesi", "");
            }
		}
	}
    return 1;
}
and if i take out

Код HTML:
if(IsPlayerConnected(playerid))
it still wont work

how can i see the account's from `players` table not only for connected players instead of

Код HTML:
if(IsPlayerConnected(playerid))
what should i put ?
Reply
#2

Try this;

PHP код:
CMD:top10(playeridparams[])
{
    if(
gLogged[playerid] == 0) return SendClientMessage(playeridCOLOR_ERROR"Tu nu esti logat si nu poti sa folosesti aceasta comanda!");
        for(new 
iGetPlayerPoolSize(); <= ji++) // or use foreach
        
{
            if(
PlayerInfo[i][pHoursPlayed] >= && IsPlayerConnected(i))
            {
                new 
sendername[30], string2[1000], coordsstring[1000];
                
GetPlayerName(playeridsendernamesizeof(sendername));
                
                
format(coordsstringsizeof(coordsstring), "Nume\tOre jucate\n"sendernamePlayerInfo[playerid][pHoursPlayed]);
                
strcat(string2coordsstring);
                
format(coordsstringsizeof(coordsstring), "%s\t%d\n"sendernamePlayerInfo[playerid][pHoursPlayed]);
                
strcat(string2coordsstring);
                
                
ShowPlayerDialog(playerid1341345DIALOG_STYLE_TABLIST_HEADERS"Top 10 jucatori activi"string2"Iesi""");
            }
        }
    return 
1;

Reply
#3

That will not work...for 3 Reasons:

1. Dont declare variables in a loop..thats nonsense..cause they will be created always new...thats your number 1 mistake...
2. You are not sorting anything...there will just appear 10 Names...random..
3. Your Dialog Number is too huge...and strings are much too big
Reply
#4

so why you wont help me with a new one ?
Reply
#5

Okay, i show you how it would be pretty

First download this include: https://sampforum.blast.hk/showthread.php?tid=343172

PHP код:
CMD:top10(playeridparams[])
{
    if(
gLogged[playerid] == 0) return SendClientMessage(playeridCOLOR_ERROR"Tu nu esti logat si nu poti sa folosesti aceasta comanda!");
    const 
max_sort 10;
    new 
toSort[MAX_PLAYERS][2], string[16 + (MAX_PLAYER_NAME+3)*max_sort] = "Nume\tOre jucate\n"bool:found;
    for(new 
i=GetPlayerPoolSize(),idx!= -1i--)
    {
        if(!
IsPlayerConnected(i) || IsPlayerNPC(i) || PlayerInfo[i][pHoursPlayed] <= 0) continue;
        
toSort[idx][0] = PlayerInfo[i][pHoursPlayed];
        
toSort[idx++][1] = i;
    }
    
SortDeepArray(toSort0, .order SORT_DESC);
    for(new 
i,n[MAX_PLAYER_NAME]; i<max_sorti++)
    {
        if(
toSort[i][0] == 0) break;
        
found=true;
        
GetPlayerName(toSort[i][1],n,MAX_PLAYER_NAME);
        
format(string,sizeof(string),"%s%s\t%d\n",string,n,toSort[i][0]);
    }
    if(!
found) return SendClientMessage(playeridCOLOR_ERROR"No players where found yet!");
    
ShowPlayerDialog(playerid1337DIALOG_STYLE_TABLIST_HEADERS"Top 10 jucatori activi"string"Iesi""");
    return 
1;

Not tested, but should work
Reply
#6

i will test it
Reply
#7

..what happens?
Reply
#8

how should i name that include ?
Reply
#9

...that doesn't matter..ahaha xD
Just include it xD

//Edit: Look at my code pls again..i changed sth so copy it new..
Reply
#10

is working man , it's working same to me , i just wanted to take first 10 players from my DataBase with biggest HoursPlayed

accounts: `players`
how to determine hoursplayed: `HoursPlayed` or pHoursPlayed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)