top10 -
StR_MaRy - 19.09.2016
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 ?
Re: top10 -
oMa37 - 19.09.2016
Try this;
PHP код:
CMD:top10(playerid, params[])
{
if(gLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_ERROR, "Tu nu esti logat si nu poti sa folosesti aceasta comanda!");
for(new i, j = GetPlayerPoolSize(); i <= j; i++) // or use foreach
{
if(PlayerInfo[i][pHoursPlayed] >= 1 && IsPlayerConnected(i))
{
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;
}
Re: top10 -
Kaliber - 19.09.2016
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
Re: top10 -
StR_MaRy - 19.09.2016
so why you wont help me with a new one
?
Re: top10 -
Kaliber - 19.09.2016
Okay, i show you how it would be pretty
First download this include:
https://sampforum.blast.hk/showthread.php?tid=343172
PHP код:
CMD:top10(playerid, params[])
{
if(gLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_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; i != -1; i--)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i) || PlayerInfo[i][pHoursPlayed] <= 0) continue;
toSort[idx][0] = PlayerInfo[i][pHoursPlayed];
toSort[idx++][1] = i;
}
SortDeepArray(toSort, 0, .order = SORT_DESC);
for(new i,n[MAX_PLAYER_NAME]; i<max_sort; i++)
{
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(playerid, COLOR_ERROR, "No players where found yet!");
ShowPlayerDialog(playerid, 1337, DIALOG_STYLE_TABLIST_HEADERS, "Top 10 jucatori activi", string, "Iesi", "");
return 1;
}
Not tested, but should work
Re: top10 -
StR_MaRy - 19.09.2016
i will test it
Re: top10 -
Kaliber - 19.09.2016
..what happens?
Re: top10 -
StR_MaRy - 19.09.2016
how should i name that include ?
Re: top10 -
Kaliber - 19.09.2016
...that doesn't matter..ahaha xD
Just include it xD
//Edit: Look at my code pls again..i changed sth
so copy it new..
Re: top10 -
StR_MaRy - 19.09.2016
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