SA-MP Forums Archive
Ban Length CMD - 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: Ban Length CMD (/showthread.php?tid=567473)



Ban Length CMD - XXCrazyMan707XX - 14.03.2015

Hello, so I've searched everywhere, with no luck, to try and find a tutorial or command that might help me with what I am after.

Basically I want to make my /ban command syntax to be /ban [length] - (1w/1m/1h) [id/name] [reason].

Where:
- 1w = 1 week;
- 1m = 1 month;
- 1h = 1 hour and so on.

I am using sscanf to break down the parameters, but can't seem to find out how to make it detect the length.

Any help would be appreciated.

Thanks,
CM707


Re: Ban Length CMD - arlindi - 14.03.2015

MySQL or INI


Re: Ban Length CMD - XXCrazyMan707XX - 14.03.2015

Quote:
Originally Posted by arlindi
Посмотреть сообщение
MySQL or INI
Just curious, did you even read the question?


Re: Ban Length CMD - Djole1337 - 14.03.2015

pawn Код:
CMD:ban(playerid, params[]) {
    new banId, banLen[12], banX, banT, banTimestamp;

    if (sscanf(params, "us[12]", banId, banLen))
        return SendClientMessage(playerid, -1, "Usage: /ban [id/name] Xy/Xm/Xd/Xh/Xm - X = number");

    if (!IsPlayerConnected(banId))
        return SendClientMessage(playerid, -1, "Invalid player.");

    if (!(banX = strval(banLen)))
        return SendClientMessage(playerid, -1, "Usage: /ban [id/name] Xy/Xm/Xd/Xh/Xm - X = number");

    for (new i = -1; banLen[++ i] != '\0' ;) {
        switch (banLen[i]) {
            case 'y', 'm', 'd', 'h': {
                banT = ((banLen[i] == 'y') ? 31536000 : ((banLen[i] == 'm') ? 2592000 : ((banLen[i] == 'd') ? 86400 : ((banLen[i] == 'h') ? 3600 : 60))));
                printf("debug: LOOP\r\n");
                break;
            }
        }
    }

    if (!banT)
        return SendClientMessage(playerid, -1, "Usage: /ban [id/name] Xy/Xm/Xd/Xh/Xm - X = number");

    banTimestamp = gettime() + (banT * banX);

    printf("debug: TS: %d | banT: %d | banX: %d\r\n", banTimestamp, banT, banX);

    // ban them
    // ban length should be banTimestamp
    // OnPlayerConnect fetch banTimestamp and compare like
    // if (banTimestamp <= gettime())
    // if so then unban them
    // else kick because they're still banned
     return 1;
}