Custom MySQLGetPlayerInt(playerid,field[]); Help!
#1

K, so i just made my own command to get a field from a users row in the database.
Код:
public MySQLGetPlayerInt(playerid,field[])
{
	new name[28],query[1024],line[1024],fieldval[1024],destination[64];
	GetPlayerName(playerid,name,sizeof(name));
	format(query,sizeof(query),"SELECT * FROM `users` WHERE username='%s'",name);
	samp_mysql_query(query);
	samp_mysql_store_result();
	samp_mysql_fetch_row(line);
	samp_mysql_get_field(field,destination);
	format(fieldval,sizeof(fieldval),"%% ",destination);
	new Int = strval(fieldval);
	printf("Username: %s. Field: %s. Value: %%",name,fieldval,Int);
	return Int;
}
But it crashes my server using it in the command:
Код:
if(strcmp(cmd,"/adminlevel",true)==0)
	{
		format(string,sizeof(string),"%d",MySQLGetPlayerInt(playerid,"adminlevel"));
		new result;
		result = strval(string);
		format(string,sizeof(string),"%%",result);
	  SendClientMessage(playerid,COLOR_LIME,string);
	  return 1;
	}
It crashes somewhere in the MySQLGetPlayerInt command because it does not print that last line into the command prompt.
Reply
#2

A string is %s, where are you getting %% from?
Reply
#3

result is an integer, so it should be %d%% (if you want to show percentages) - it should print something like "43%"

%d = integer
%% = percent sign
Reply
#4

%% stands for the real wildcard, it is saying it can be anything, string, integer, character.
Reply
#5

Quote:
Originally Posted by tom_jonez
%% stands for the real wildcard, it is saying it can be anything, string, integer, character.
Now thats just pure layzness
Reply
#6

Quote:
Originally Posted by JeNkStAX
Quote:
Originally Posted by tom_jonez
%% stands for the real wildcard, it is saying it can be anything, string, integer, character.
Now thats just pure layzness
or bc the field could be anything from a string to a number....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)