new pname[24];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() != 0)//if number of rows is different from 0 then continue
{
ShowPlayerDialog(playerid, 2344, DIALOG_STYLE_MSGBOX,"Name is banned from the server","Your name is banned from the server!\n post it in the Unban appeals Category.","OK","");
Kick(playerid);
}
mysql_free_result();
mysql_tquery(connectionHandle, "SELECT Banned FROM players WHERE user = Bondage", "QueryResultCallback", "i", playerid); //passing the playerid as parameter to be able to send him a message if he's banned
public QueryResultCallback(playerid) //the only param of this function is playerid, which has been passed from the query
{
//get the number of rows
if(rows) // he's banned
{
//something - here you can use playerid to send the player a message and maybe kick him
}
else
{
//he's not banned - send a welcome message, call a login system if required etc
}
}
Here you go:
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery Basically you're sending the query and you're calling a function when the query executes (successfully or not). pawn Код:
[1] https://sampwiki.blast.hk/wiki/MySQL/R33..._get_row_count [2] https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_data |
new pname[24];
GetPlayerName(playerid, pname, 24);
mysql_format(/*mysql connection*/, query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
mysql_tquery(/*mysql connection*/, query, "", "");
new rows, fields;
cache_get_data(rows, fields, /*mysql connection*/);
if(rows)
{
ShowPlayerDialog(playerid, 2344, DIALOG_STYLE_MSGBOX,"Name is banned from the server","Your name is banned from the server!\n post it in the Unban appeals Category.","OK","");
Kick(playerid);
}
Try with this:
pawn Код:
|
mysql_format(/*mysql connection*/, query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
mysql_tquery(/*mysql connection*/, query, "", "");
cache_get_data(rows, fields, /*mysql connection*/);
static mysql; //i'm using this
mysql_format(mysql, query, sizeof(query), "SELECT `Banned` FROM `players` WHERE `user` = '%s' AND `Banned` = 1 LIMIT 1", pname);
mysql_tquery(mysql, query, "", "");
cache_get_data(rows, fields, mysql);
Documentation for BlueG's MySQL plugin version R33 and later. |
The "mysql connection" thing, which i called connectionHandle, is the value returned by the mysql_connect function (https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_connect). You need to connect to a database before running any query.
I'm not sure if what bgedition wrote there actually works, you'll have to test it. I have my doubts, because as far as I know, the cache functions will return the correct values only if they are somehow related to the "parent" query, so they must be used within a callback which is called by that query, as I wrote in my example (the QueryResultCallback thing). Regarding other versions, I guess this should work on them too, because I see some R35, R36 references on the wiki page. Also, there is this paragraph at the top of the page: |