SA-MP Forums Archive
Bancommand ORM SQL - 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: Bancommand ORM SQL (/showthread.php?tid=557735)



Bancommand ORM SQL - Markus1337 - 14.01.2015

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;
}



Re: Bancommand ORM SQL - Schneider - 14.01.2015

I think you have set the bannedby and banreason as an integer instead of a string.
The unbantime looks good. This number means the player will get unbaned 1421280394 seconds after January 1st 1970 at 12 o'clock. In this case January 15th 2015 at 00:06:34 GMT


Re: Bancommand ORM SQL - Markus1337 - 14.01.2015

The end of create table line:
pawn Код:
`banned` int(1), `bannedby` varchar(24), `banreason` varchar(20), `bantime` int(30), `unbantime` int(30))", false);



Re: Bancommand ORM SQL - xVIP3Rx - 14.01.2015

Show us how do you update your table.


Re: Bancommand ORM SQL - Markus1337 - 14.01.2015

On disconnect:
pawn Код:
g_MysqlRaceCheck[playerid]++;
    if(Player[playerid][IsLoggedIn] && Player[playerid][ID] > 0)
        orm_save(Player[playerid][ORM_ID]); //if Player[playerid][ID] has a valid value, orm_save sends an UPDATE query, else an INSERT query
    orm_destroy(Player[playerid][ORM_ID]);
Which should save everything stored in this on disconnection:
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];
It's not a problem with it saving, it's just giving the wrong banreason and bannedby as it seems..


Re: Bancommand ORM SQL - xVIP3Rx - 14.01.2015

I think I got why, BannedBy, BanReason should be strings,
in the enum,
pawn Код:
BannedBy[MAX_PLAYER_NAME],
BanReason[20],
Try debugging the unban time to see if it's saving and loading right results, though I think there's nothing wrong with it, it gives the correct timestamp plus the seconds you added


Re: Bancommand ORM SQL - Markus1337 - 15.01.2015

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
I think I got why, BannedBy, BanReason should be strings,
in the enum,
pawn Код:
BannedBy[MAX_PLAYER_NAME],
BanReason[20],
Try debugging the unban time to see if it's saving and loading right results, though I think there's nothing wrong with it, it gives the correct timestamp plus the seconds you added
God i'm stupid, I suspect you're correct I'll go ahead and try it out.


Re: Bancommand ORM SQL - Markus1337 - 15.01.2015

Quote:
Originally Posted by Markus1337
Посмотреть сообщение
God i'm stupid, I suspect you're correct I'll go ahead and try it out.
Didn't help unfortunatly.. :S


Re: Bancommand ORM SQL - xVIP3Rx - 15.01.2015

Maybe you have to destroy the old values at the table ? I don't know much about ORM but until here there should be no problems with the string and formatting it, the problem's in saving/loading it.