Bancommand ORM SQL
#1

It bans like it should but gives totally wrong unbantimes, banreason and bannedby.
Posting alot of questions but i'm kinda getting the hang of this.. err I think =P
Explainations would be nice too.
Pic from DB:

pawn Код:
enum E_PLAYERS
{
    ORM:ORM_ID,

    ID,
    Name[MAX_PLAYER_NAME],
    Password[129],
    Money,
    Kills,
    Deaths,
    AdminLevel,
    bool:IsLoggedIn,
    bool:CanSellCar,
    bool:IsRegistered,
    LoginAttempts,
    Banned,
    BannedBy,
    BanReason,
    BanTime,
    UnbanTime,
    LoginTimer
};
new Player[MAX_PLAYERS][E_PLAYERS];
pawn Код:
CMD:ban(playerid, params[])
{
    new target_id, hours, minutes, seconds, reason[20], name[MAX_PLAYER_NAME];
    // new variables, purpose stated below.
    if(Player[playerid][AdminLevel] == 0) return SendClientMessage(playerid, -1, "SERVER: Unknown command.");
    // You ain't logged into RCON, dude!
    if(sscanf(params, "uddds[20]", target_id, hours, minutes, seconds, reason)) return SendClientMessage(playerid, -1, "USAGE: /ban (playerid) (hours) (mins) (secs) (reason)");
    // We insert values the command executor typed after ban in the respective variables.
    // u -> player -> target_id - the player to be banned
    // d -> hours -> hours to be banned
    // s -> reason (string) -> 20 max chars.
    // We return him the USAGE string if all parameters were not filled.
    if(!IsPlayerConnected( target_id ) ) return SendClientMessage(playerid, -1, "ERROR: Requested player is offline.");
    {
        // okay, he's admin, he has typed correctly.
        GetPlayerName(playerid, name, MAX_PLAYER_NAME);
        Player[target_id][Banned] = 1; // okay, now set the ban status of target to 1
        Player[target_id][BanTime] = gettime(); // returns a timestamp of the current moment!
        format( Player[target_id][BanReason], 20, "%s", reason ); // Now pBANNEDfor contains the reason.
        format( Player[target_id][BannedBy], MAX_PLAYER_NAME, "%s", name); // the person who banned the target
        // the main part. When is he going to be unbanned?
        new total_banned_seconds_from_now = seconds + ( minutes * 60 ) + (hours * 60 * 60);
        // now the variable contains the total seconds the target is to be banned, from now!
        // If you don't know why we multipled by 60, go back to school!
        Player[target_id][UnbanTime] = total_banned_seconds_from_now + gettime();
        // So if I typed /ban player 0 1 50 TEST, current gettime() would be datestamp.
        // let datestamp be 124124. I need to ban 'player' 1 minute and 50 seconds.
        // according to calculations, that is 110 seconds. Hence, the timestamp when the 'player' player is to be unbanned is
        // 124124 + 110 = 124230 !

        // Let's update the target_id's table.

        new query[200], TARGETname[MAX_PLAYER_NAME];

        GetPlayerName(target_id, TARGETname, 24);



        SendClientMessage(target_id, -1, "You have been banned.");
        SendClientMessage(playerid, -1, "You have banned the requested player successfully.");
        // You can format and add effects like gametext, sending to jail, freezing, etc. I am keeping it simple.
        DelayedKick(target_id);
        // I assume KickWithDelay as the function where you set a timer to kick, etc.
        // The link for it is https://sampwiki.blast.hk/wiki/Kick, look in the example section.
    }
    return 1;
}
Reply


Messages In This Thread
Bancommand ORM SQL - by Markus1337 - 14.01.2015, 22:26
Re: Bancommand ORM SQL - by Schneider - 14.01.2015, 22:33
Re: Bancommand ORM SQL - by Markus1337 - 14.01.2015, 22:56
Re: Bancommand ORM SQL - by xVIP3Rx - 14.01.2015, 23:15
Re: Bancommand ORM SQL - by Markus1337 - 14.01.2015, 23:37
Re: Bancommand ORM SQL - by xVIP3Rx - 14.01.2015, 23:54
Re: Bancommand ORM SQL - by Markus1337 - 15.01.2015, 00:29
Re: Bancommand ORM SQL - by Markus1337 - 15.01.2015, 02:53
Re: Bancommand ORM SQL - by xVIP3Rx - 15.01.2015, 09:50

Forum Jump:


Users browsing this thread: 1 Guest(s)