Ban system, with days.
#1

Hi guys.

I want to make a ban system with ban days. Exemple: I will ban a player for 5-6 days. I don't know how can I make it, with TIMESTAMP in MySQL. I've never used TIMESTAMP before .. and i don't know how to use it.

Can anyone explain me? Thanks.
Reply
#2

First of all you should create a new structur in your table users or whatever.
Call him disable Inteneger. Ban command for ZCMD

pawn Код:
CMD:tban(playerid, params[])
{
    new pID, days;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You aren't an admin.");
    if(sscanf(params, "ud", pID, days)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /tban (username) (days)");
    if(!IsPlayerConnected(pID)) return SendClientMessage(playerid, COLOR_RED, "Invalid Player.");
    // example your tablename = users structur = disable
    mysql_query("UPDATE users SET disable = '%d' WHERE username = '%s'", days + getdate(), PlayerName(pID));
    new string[128];
    format(string, sizeof(string), "You are banned for %d Days.", days + getdate());
    SendClientMessage(pID, COLOR_PINK, string);
    Kick(pID);
    return 1;
}
Checking is player banned or not

pawn Код:
public OnPlayerConnect(playerid)
{
    new result = mysql_query("SELECT disable FROM users WHERE username = '%s'", PlayerName(pID));
    mysql_store_result(result);
    new value = mysql_fetch_int(result);
    mysql_free_result(result);
    if(value > getdate())
    {
        // player still banned
    }
    return 1;
}
Reply
#3

@MouseBreaker thanks, it works. What value returns getdate?
Reply
#4

The number of days since the start of the year.
Reply
#5

Quote:
Originally Posted by MouseBreaker
Посмотреть сообщение
The number of days since the start of the year.
Ok, thanks
Reply
#6

Better to use unix timestamps. Check the tutorial on that in the tutorial section.
Reply
#7

Quote:
Originally Posted by MouseBreaker
Посмотреть сообщение
Checking is player banned or not

pawn Код:
public OnPlayerConnect(playerid)
{
    [COLOR="Red"]new result[/COLOR] = mysql_query("SELECT disable FROM users WHERE username = '%s'", PlayerName(pID));
    mysql_store_result(result);
    new value = mysql_fetch_int(result);
    mysql_free_result(result);
    if(value > getdate())
    {
        // player still banned
    }
    return 1;
}
You don't need that^
Also better create a stock and put it onplayerconnect
Here's an example:
pawn Код:
public OnPlayerConnect(playerid)
{
    IsPlayerBanned(playerid);
    return 1;
}
stock IsPlayerBanned(playerid);
{
    new String[128], index[128], Lenght;
    format(String, sizeof(String), "SELECT `Lenght` FROM `Your ban table` WHERE `username` = '%s'", PlayerName(playerid));
    mysql_query(String);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        while(mysql_fetch_row_format(String,"|"))
        {
            mysql_fetch_field_row(index, "Lenght"); Lenght = strval(index);
        }
        if(Lenght > getdate())
        {
            SendClientMessage(playerid, -1, "You are banned from this server");
            format(String, sizeof(String), "Your Ban expires %s, ", timec(gettime()-(gettime()-Lenght)));
            SendClientMessage(playerid, -1, String);
        }
        else
        {
            SendClientMessage(playerid, -1, "You are unbanned!");
            format(String, sizeof(String), "DELETE FROM `Ban table` WHERE `User` = '%s'", PlayerName(playerid));
            mysql_query(String);
            // Or whatever you want
        }
    }
    mysql_free_result();
    return 1;
}

//This stock is created by Blacklite
stock timec(timestamp, compare = -1)
{
    if (compare == -1) {
        compare = gettime();
    }
    new
        n,
        Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,
        returnstr[32];
    if (d < 60) {
        format(returnstr, sizeof(returnstr), "Less than a minute");
        return returnstr;
    } else if (d < 3600) { // 3600 = 1 hour
        n = floatround(floatdiv(d, 60.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "minute");
    } else if (d < 86400) { // 86400 = 1 day
        n = floatround(floatdiv(d, 3600.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "hour");
    } else if (d < 2592000) { // 2592000 = 1 month
        n = floatround(floatdiv(d, 86400.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "day");
    } else if (d < 31536000) { // 31536000 = 1 year
        n = floatround(floatdiv(d, 2592000.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "month");
    } else {
        n = floatround(floatdiv(d, 31536000.5), floatround_floor);
        format(returnstr, sizeof(returnstr), "year");
    }
    if (n == 1) {
        format(returnstr, sizeof(returnstr), "1 %s", returnstr);
    } else {
        format(returnstr, sizeof(returnstr), "%d %ss", n, returnstr);
    }
    return returnstr;
}
Reply
#8

@Mr_DjolE

I know but i scripted this in 3 minutes, so i didn't have time and i just show him, how to use time ban system.
Reply
#9

Quote:
Originally Posted by Vince
Посмотреть сообщение
Better to use unix timestamps. Check the tutorial on that in the tutorial section.
https://sampforum.blast.hk/showthread.php?tid=254915 yeah, now i understand how unix timestamp works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)