SA-MP Forums Archive
Offline - Ban mysql ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Offline - Ban mysql ? (/showthread.php?tid=548454)



Offline - Ban mysql ? - Metharon - 29.11.2014

I tried to make:
- if the player is online to ban him
- if isn't online to check on db then ban him


But isn't working...


pawn Код:
if(strcmp(cmd, "/ban", true) == 0)
    {
        if (PlayerInfo[playerid][Administrator] >= 3)
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "{FFFFFF}(( {FFCC00}Exemplu folosire: {C0C0C0} /ban [playerid/nume jucator] [motiv] {FFFFFF}))");
                return 1;
            }
            giveplayerid = ReturnUser(tmp);
            if(giveplayerid == playerid) { SendClientMessage(playerid, -1, "{FFFFFF}(( {FFCC00}Informatie - {C0C0C0}aceasta comanda trebuie executata pe alta persoana {FFFFFF}))"); return 1; }
            if(IsPlayerConnected(giveplayerid))
            {
                if(giveplayerid != INVALID_PLAYER_ID)
                {
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                    new length = strlen(cmdtext);
                    while ((idx < length) && (cmdtext[idx] <= ' '))
                    {
                        idx++;
                    }
                    new offset = idx;
                    new result[64];
                    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                    {
                        result[idx - offset] = cmdtext[idx];
                        idx++;
                    }
                    result[idx - offset] = EOS;
                    if(!strlen(result))
                    {
                        SendClientMessage(playerid, COLOR_GRAD2, "{FFFFFF}(( {FFCC00}Exemplu folosire: {C0C0C0} /ban [playerid/nume jucator] [motiv] {FFFFFF}))");
                        return 1;
                    }
                    new Year, Month, Day;
                    getdate(Year, Month, Day);
                    new stringdata[456];
                    format(stringdata, sizeof(stringdata), "%02d/%02d/%02d", Day,Month,Year);
                    new Hour, Minute, Second;
                    gettime(Hour, Minute, Second);
                    new stringora[456];
                    format(stringora, sizeof(stringora), "%02d:%02d", Hour,Minute);
                    new stringmotiv[456];
                    format(stringmotiv, sizeof(stringmotiv), "%s", (result));
                    format( szQuery, 500, "INSERT INTO `bans` (Data,Ora,Echipa,Jucator,Motiv) VALUES ('%s','%s','%s','%s','%s')", stringdata,stringora,stringmotiv,GetName(playerid),giveplayer);
                    mysql_tquery( SQL, szQuery, "", "" );
                    new string[456];
                    format(string, sizeof(string), "{CC0033}(Anunt) {CC0033}Jucatorul %s a fost banat de catre administratorul %s (%s)", giveplayer,GetName(playerid), (result));
                    SendClientMessageToAllEx(COLOR_GRAD1,string);
                    format(string, sizeof(string),"{FFFFFF}- Jucator , din pacate ai primit {FF0033}ban{FFFFFF} de la administratorul %s!\n\n{FFF1AF}[Administratorul ti-a banat contul motivul pentru care ai fost banat in joc este %s !]",GetName(playerid),(result));
                    ShowPlayerDialog(giveplayerid, DIALOG_BAN, DIALOG_STYLE_MSGBOX, "  ", string, "Bine", "");
                    new name[MAX_PLAYER_NAME+1], query8[450];
                    GetPlayerName(giveplayerid, name, sizeof(name));
                    PlayerInfo[giveplayerid][Banned] = 1;
                    format(query8, sizeof(query8),"UPDATE `Accounts` SET `Banned` = 1, `BannedM` = '%s'  WHERE `Name` = '%s'", (result), name);
                    mysql_tquery( SQL , query8 , "" , "" );
                    SetTimerEx("KickTimer", 1000, 0, "d", giveplayerid);
 
                    return 1;
                }
            }
            else
            {
                new length = strlen(cmdtext);
                while ((idx < length) && (cmdtext[idx] <= ' '))
                {
                    idx++;
                }
                new offset = idx;
                new tmp2[64];
                while ((idx < length) && ((idx - offset) < (sizeof(tmp2) - 1)))
                {
                    tmp2[idx - offset] = cmdtext[idx];
                    idx++;
                }
                tmp2[idx - offset] = EOS;
                if(!strlen(tmp2))
                {
                    SendClientMessage(playerid, COLOR_GRAD2, "{FFFFFF}(( {FFCC00}Exemplu folosire: {C0C0C0} /ban [playerid/nume jucator] [motiv] {FFFFFF}))");
                    return 1;
                }
                new result[64];
                while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                {
                    result[idx - offset] = cmdtext[idx];
                    idx++;
                }
                result[idx - offset] = EOS;
                if(!strlen(result))
                {
                    SendClientMessage(playerid, COLOR_GRAD2, "{FFFFFF}(( {FFCC00}Exemplu folosire: {C0C0C0} /ban [playerid/nume jucator] [motiv] {FFFFFF}))");
                    return 1;
                }
                new Destinatar[256];
                format(Destinatar, 50, "%s", (tmp2));
                new Motiv[256];
                format(Motiv, 256, "%s", (result));
                format( szQuery, 500, "SELECT * FROM `Accounts` WHERE `Name` = '%s' LIMIT 1;", Destinatar );
                new Get[ 2 ], query8[256];
                cache_get_data( Get[ 0 ], Get[ 1 ], SQL );
                if( !Get[ 0 ] )
                {
                    SendClientMessage(playerid, -1, "{FFFFFF}(( {FFCC00}Informatie -{C0C0C0} acest jucator nu a fost gasit in baza de date! {FFFFFF}))");
                    return 1;
                }
                format(query8, sizeof(query8),"UPDATE `Accounts` SET `Banned` = 1, `BannedM` = '%s'  WHERE `Name` = '%s'", Motiv,Destinatar);
                mysql_tquery( SQL , query8 , "" , "" );
                new string[456];
                format(string, sizeof(string), "{CC0033}(Anunt) {CC0033}Jucatorul %s a fost banat-offline de catre administratorul %s (%s)", Destinatar, GetName(playerid),Motiv);
                SendClientMessageToAllEx(COLOR_GRAD1,string);
                new Year, Month, Day;
                getdate(Year, Month, Day);
                new stringdata[456];
                format(stringdata, sizeof(stringdata), "%02d/%02d/%02d", Day,Month,Year);
                new Hour, Minute, Second;
                gettime(Hour, Minute, Second);
                new stringora[456];
                format(stringora, sizeof(stringora), "%02d:%02d", Hour,Minute);
                new stringmotiv[456];
                format(stringmotiv, sizeof(stringmotiv), "%s", (result));
                format( szQuery, 500, "INSERT INTO `bans` (Data,Ora,Echipa,Jucator,Motiv) VALUES ('%s','%s','%s','%s','%s')", stringdata,stringora,stringmotiv,GetName(playerid),giveplayerid);
                mysql_tquery( SQL, szQuery, "", "" );
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "{FFFFFF}(( {FFCC00}Informatie -{C0C0C0} nu ai accces la aceasta comanda! {FFFFFF}))");
        }
        return 1;
    }

Can somebody fix me this code.. ?


Re: Offline - Ban mysql ? - Vince - 29.11.2014

Why some people still swear by using this outdated code, including several copies of strtok, is far beyond me. Use a modern command processor. Use sscanf. Use threaded queries! Honestly, why do I still bother?









As far as the problem concerns, I see a query being formatted but it isn't actually sent to the server.


Re: Offline - Ban mysql ? - Metharon - 30.11.2014

Somebody else , help?


Re: Offline - Ban mysql ? - Abagail - 30.11.2014

He means you're not executing the query. Consider upgrading your script to use R-39. In that case, it would need to actually execute:
hence-forth
pawn Код:
mysql_tquery
would need to be called somewhere.


Re: Offline - Ban mysql ? - Metharon - 30.11.2014

oh lol th i don't saw that


Re: Offline - Ban mysql ? - Metharon - 30.11.2014

UP : Still not finding the player... can somebody help me ?... i want to find a player in db ..


Re: Offline - Ban mysql ? - AnthonyTimmers - 30.11.2014

Use DCMD/ZCMD. Reading this hurts my eyes.


Re: Offline - Ban mysql ? - StreetGT - 30.11.2014

Quote:
Originally Posted by Vince
Посмотреть сообщение
Why some people still swear by using this outdated code, including several copies of strtok, is far beyond me. Use a modern command processor. Use sscanf. Use threaded queries! Honestly, why do I still bother?









As far as the problem concerns, I see a query being formatted but it isn't actually sent to the server.
That was the first thing i thought LOL


Re: Offline - Ban mysql ? - Metharon - 01.12.2014

Nvm , i fixed by myself.

Thanks for nothing.