SA-MP Forums Archive
MySQL spammed due to slow timer. - 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: MySQL spammed due to slow timer. (/showthread.php?tid=609374)



MySQL spammed due to slow timer. - Dokins - 11.06.2016

pawn Код:
new query[256];
        GetPlayerIp(playerid, ip, sizeof(ip));
        format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Weapon Hacking', %d, 0)", GetName(playerid), ip, gettime());
        mysql_tquery(dbHandle, query, "", "");


        SavePlayerData(playerid);
        ClearPlayerID(playerid);
        SetTimerEx("KickPlayer", 100,false,"i",playerid);
Bans are spammed in mysql 5 or 6 times before the player is kicked, is there a way to avoid duplicate inserts?


Re: MySQL spammed due to slow timer. - iGetty - 11.06.2016

Make a variable:

new bool:HasBeenKicked[MAX_PLAYERS] = false; //At the top of the script

HasBeenKicked[playerid] = false; //OnPlayerConnect

HasBeenKicked[playerid] = true; //Above the timer and below ClearPlayerID(playerid)


Then wrap it in:

pawn Код:
new bool:HasBeenKicked[MAX_PLAYERS] = false;

public OnPlayerConnect(playerid)
{
    HasBeenKicked[playerid] = false;
    return 1;
}

if(!HasBeenKicked[playerid]){
    new query[256];
    GetPlayerIp(playerid, ip, sizeof(ip));
    format(query, sizeof(query), "INSERT INTO `bans` (playername, ip, Reason, Date, BanBy) VALUES ('%s', '%s', 'Weapon Hacking', %d, 0)", GetName(playerid), ip, gettime());
    mysql_tquery(dbHandle, query, "", "");

    SavePlayerData(playerid);
    ClearPlayerID(playerid);
    HasBeenKicked[playerid] = true;
    SetTimerEx("KickPlayer", 100,false,"i",playerid);
}



Re: MySQL spammed due to slow timer. - Dokins - 11.06.2016

Thank you.

I'm having another issue with something else, could I kindly add you on skype or the sorts?


Re: MySQL spammed due to slow timer. - iGetty - 11.06.2016

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Thank you.

I'm having another issue with something else, could I kindly add you on skype or the sorts?
I don't have Skype mate, sorry.