/unban using MySQL
#1

pawn Код:
command(unban, playerid, params[])
{
    new giveplayername[24];
    if(sscanf(params, "s[24]", giveplayername)) return SendClientMessage(playerid, COLOR_WHITE, " USAGE: /unban [player name]");

    mysql_format(sqldb, query, sizeof(query), "SELECT * FROM accounts WHERE accname ='%e' LIMIT 0, 1", giveplayername);
    mysql_tquery(sqldb, query);

    new rows = mysql_num_rows();
    if(!rows)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "That player doesn't exists in server's database!");
    }
    if(rows == 1)
    {
        if(cache_get_row_int(0, 4, sqldb))
        {
            mysql_format(sqldb, query, sizeof(query), "UPDATE accounts SET banvar ='0' WHERE accname ='%e'", giveplayername);
            mysql_tquery(sqldb, query);
        }
        if(cache_get_row_int(0, 4, sqldb)) return SendClientMessage(playerid, COLOR_LIGHTRED, " That player isn't banned!");
    }
    return 1;
}
It allways returns "That player doesn't exists in server's database!"

What's wrong?
Reply
#2

Must use callback!
Reply
#3

I found out that and now I did that... But now my callback won't print SendClientMessage, I did this:
pawn Код:
command(unban, playerid, params[])
{
    new giveplayername[24];
    if(sscanf(params, "s[24]", giveplayername)) return SendClientMessage(playerid, COLOR_WHITE, " USAGE: /unban [player name]");

    mysql_format(sqldb, query, sizeof(query), "SELECT * FROM accounts WHERE accname ='%e' LIMIT 0, 1", giveplayername);
    mysql_tquery(sqldb, query, "UnbanPlayer", "is", playerid, giveplayername);
    return 1;
}
pawn Код:
forward UnbanPlayer(playerid, giveplayername);
public UnbanPlayer(playerid, giveplayername)
{

    new rows = mysql_num_rows();
    if(!rows)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "That player doesn't exists in server's database!");
    }
    if(rows == 1)
    {
        new temp[24], isbanned;
        cache_get_row(0, 4, temp); isbanned = strval(temp);
        if(isbanned == 1)
        {
            mysql_format(sqldb, query, sizeof(query), "UPDATE accounts SET banvar ='0' WHERE accname ='%e' LIMIT 0, 1", giveplayername);
            mysql_tquery(sqldb, query);
        }
        else if(isbanned == 0)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, " That player isn't banned!");
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)