/Toprich command help sqlite
#1

Hello guys, I switched to SQLite finally, but I have a problem, how to make a top command including offline players, I would like if someone give me a code with an explanation

I'm using easy - sqlite include , If is there anyway to do that by this include plz tell me that method too

VARS:
cash - USERINFO[playerid][pCash]

DB:
name - Top.db
table - Players

for now plz give me an example code for /toprich

THANKS
Reply
#2

First of all you need to have column for cash in Players table. In this example, I will use cash as an column of value of cash.
So, here it is, but notice that: I don't use easy sqlite and am in a hurry, so take this code and do the same with easy sqlite.
PHP код:
CMD:toprich(playeridparams[])
{
    new 
toprichDBResult:result;
    
result db_query(<DB>, "SELECT max(cash) FROM Players");
    if(
db_num_rows(result)) 
        
toprich db_get_field_int(result);
    
db_free_result(result);
    
va_SendClientMessage(playerid, -1"Max amount of cash is %d"toprich); //FROM YSI
    
return 1;

Also notice: <DB> is the placeholder of real database (you create it first like this: new DB:dbname;)
Reply
#3

The include does not provide ORDER BY clause and there is lack of documentation too. It is more complex than using default sa-mp natives and get the job done.

MAX returns the highest value on cash, you need to select the columns you want (name, cash) and order it by highest (DESC).

If you search "samp sqlite top 10", you can find many threads.
Reply
#4

Quote:
Originally Posted by DAKYSKYE
Посмотреть сообщение
First of all you need to have column for cash in Players table. In this example, I will use cash as an column of value of cash.
So, here it is, but notice that: I don't use easy sqlite and am in a hurry, so take this code and do the same with easy sqlite.
PHP код:
CMD:toprich(playeridparams[])
{
    new 
toprichDBResult:result;
    
result db_query(<DB>, "SELECT max(cash) FROM Players");
    if(
db_num_rows(result)) 
        
toprich db_get_field_int(result);
    
db_free_result(result);
    
va_SendClientMessage(playerid, -1"Max amount of cash is %d"toprich); //FROM YSI
    
return 1;

Also notice: <DB> is the placeholder of real database (you create it first like this: new DB:dbname;)
Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
The include does not provide ORDER BY clause and there is lack of documentation too. It is more complex than using default sa-mp natives and get the job done.

MAX returns the highest value on cash, you need to select the columns you want (name, cash) and order it by highest (DESC).

If you search "samp sqlite top 10", you can find many threads.
Thanks for the help guys, I found a code It is working well
Код:
new str[200], name[MAX_PLAYER_NAME], DBResult: result = db_query(db_open("Top.db"), "SELECT `Name`,`Kills` FROM `Players` ORDER BY `Kills` DESC limit 10");
	for (new a, rows = db_num_rows(result); a < rows; a++) 
	{ 
    	db_get_field(result, 0, name, sizeof(name)); 
    	format(str, sizeof(str), "%d. %s - Kills: %d", a + 1, name, db_get_field_int(result, 1)); 
    	SendClientMessage(playerid, -1, str);
    	db_next_row(result);
	}
but I don't like to send it as a message I want it as a MSG_BOX
but if I put that inside loop dialog will repeat
so can anyone tell me how to do that Thanks again
Reply
#5

Plz guys help me I need it in a dialog style msg box but I don't know how to do that plz help
Reply
#6

Код:
new str[200], name[MAX_PLAYER_NAME], DBResult: result = db_query(db_open("Top.db"), "SELECT `Name`,`Kills` FROM `Players` ORDER BY `Kills` DESC limit 10");
	for (new a, rows = db_num_rows(result); a < rows; a++) 
	{ 
    	db_get_field(result, 0, name, sizeof(name)); 
    	format(str, sizeof(str), "%d. %s - Kills: %d\n", a + 1, name, db_get_field_int(result, 1)); 
    	ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top Rich List", str , "Exit", "");
    	db_next_row(result);
	}
Reply
#7

Quote:
Originally Posted by UFF
Посмотреть сообщение
Код:
new str[200], name[MAX_PLAYER_NAME], DBResult: result = db_query(db_open("Top.db"), "SELECT `Name`,`Kills` FROM `Players` ORDER BY `Kills` DESC limit 10");
	for (new a, rows = db_num_rows(result); a < rows; a++) 
	{ 
    	db_get_field(result, 0, name, sizeof(name)); 
    	format(str, sizeof(str), "%d. %s - Kills: %d\n", a + 1, name, db_get_field_int(result, 1)); 
    	ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top Rich List", str , "Exit", "");
    	db_next_row(result);
	}
Thanks for the reply bro, but this won't work because 'ShowPlayerDialog' is inside the loop, Therefore it will repeat 10 times(actually we can't see it's very fast and only the 10th one we can see because it stops from 10)

Then the result will be like this
Код:
10. GameOvr - Kills; 5 (Only shows the last one because it is 10th dialog)
If some one knows how to do this please reply
I was waiting for a long time
Reply
#8

oh my mistake

Код:
new str[200], name[MAX_PLAYER_NAME], DBResult: result = db_query(db_open("Top.db"), "SELECT `Name`,`Kills` FROM `Players` ORDER BY `Kills` DESC limit 0,10");
	for (new a, rows = db_num_rows(result); a < rows; a++) 
	{ 
    	db_get_field(result, 0, name, sizeof(name)); 
    	format(str, sizeof(str), "%d. %s - Kills: %d\n", a + 1, name, db_get_field_int(result, 1)); 
    	db_next_row(result);
	}
        ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top Rich List", str , "Exit", "");
try this!
Reply
#9

You need to concatenate the strings. One way is `strcat`:
pawn Код:
// example:
format(part_of, sizeof part_of, "...", ...);
strcat(str, part_of);
every time it formats the text, it joins it with the rest and you show the dialog after the loop with `str`.

Another way is to re-format but it is slower if the string gets longer in length.
pawn Код:
// example:
format(str, sizeof str, "%s...", str, ...);
Quote:
Originally Posted by UFF
Посмотреть сообщение
oh my mistake

Код:
new str[200], name[MAX_PLAYER_NAME], DBResult: result = db_query(db_open("Top.db"), "SELECT `Name`,`Kills` FROM `Players` ORDER BY `Kills` DESC limit 0,10");
	for (new a, rows = db_num_rows(result); a < rows; a++) 
	{ 
    	db_get_field(result, 0, name, sizeof(name)); 
    	format(str, sizeof(str), "%d. %s - Kills: %d\n", a + 1, name, db_get_field_int(result, 1)); 
    	db_next_row(result);
	}
        ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top Rich List", str , "Exit", "");
try this!
Again you are showing the last row.
Reply
#10

plz can you provide me an example code I dont know much about sqlite
Reply
#11

FIXED now working thanks you calisthenics + REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)