open.mp forum
[Pawn] /top online - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] /top online (/showthread.php?tid=1509)



/top online - zetrazak - 2021-01-09

Can you explain me how to make a command wich shows players with the most hours on the server, in sqlite? YSI included

Please.


RE: /top online - Pinch - 2021-01-09

You don't need YSI if you're using sqlite

Code:
SELECT
   online_time
FROM
   Players
WHERE
    is_online = 1
ORDER BY
    online_time DESC
LIMIT 10;

EDIT: If you want to have command like /top [from] [to], edit the LIMIT to [to] and add OFFSET [from] after LIMIT [to] in the query, example:

Code:
SELECT
   online_time
FROM
   Players
WHERE
    is_online = 1
ORDER BY
    online_time DESC
LIMIT 5 OFFSET 10;
That will show 5 players from 11th to 15th place


RE: /top online - zetrazak - 2021-01-10

(2021-01-09, 07:36 PM)Pinch Wrote: You don't need YSI if you're using sqlite

Code:
SELECT
? online_time
FROM
? Players
WHERE
? ? is_online = 1
ORDER BY
? ? online_time DESC
LIMIT 10;

EDIT: If you want to have command like /top [from] [to], edit the LIMIT to [to] and add OFFSET [from] after LIMIT [to] in the query, example:

Code:
SELECT
? online_time
FROM
? Players
WHERE
? ? is_online = 1
ORDER BY
? ? online_time DESC
LIMIT 5 OFFSET 10;
That will show 5 players from 11th to 15th place

[code]YCMD:toponline(playerid, params[], help) {

new szString[256];
format(szString, sizeof(szString), "SELECT online_time FROM Players WHERE is_online = 1 ORDER BY online_time DESC LIMIT 5 OFFSET 10;");
new DBResult:res = db_query(sqliteconnection, szString);

if(db_num_rows(res)) {
new szBuffer;

do
{

format(szBuffer, sizeof szBuffer, "%s\n", szBuffer);
}
while(db_next_row(res));

ShowPlayerDialog(playerid, 0, DIALOG_STYLE_TABLIST, "TOP ONLINE", szBuffer, "Close", "");

}
else {
return SendErrorMessage(playerid, "Can't find any player.");
}

return 1;
}[/code]


i tried this, but dont work. Why?


RE: /top online - Pinch - 2021-01-10

Why do I have a feeling that you just copied my query without adapting it to your database..?


RE: /top online - zetrazak - 2021-01-10

I created only 2 column in 'Players', is_online and online_time. But i dont know how to adapt it