Tempban command problem
#1

Hello, i've just coded this simple tempban command but i have a problem. I wanna tempban a player per number of DAYS, but if i use this commands, the player will be banned for a specified time of SECONDS. How to fix that?

pawn Код:
CMD:tempban(playerid,params[])
{
    if(pInfo[playerid][Admin] >= 5)
    {
          new id, reason[250];
          new aName[MAX_PLAYER_NAME];
          new pName[MAX_PLAYER_NAME];
          new year,month,day,hour,minuite,second,Hours,BanTime,d,h,m,Temp;
          if(sscanf(params, "uis[250]", id, Hours, reason)) return SendClientMessage(playerid, -1, "{F70505}Usage: {FFFFFF}/tempban <playerid> <days> <reason>");
          if(!IsPlayerConnected(id)) return SCM(playerid,red,"Invalid player id.");
          GetPlayerName(playerid, aName, sizeof(aName));
          GetPlayerName(id, pName, sizeof(pName));
          getdate(year, month, day);
          gettime(hour,minuite,second);
          BanTime = gettime() + (hour*60*86400);
          pInfo[id][TempBan] = BanTime;
          new tbans[400];
          new echo[400];
          new umad[250];
          Temp = BanTime - gettime();
          format(tbans,sizeof(tbans),"** %s (%d) has been temporarily banned by Admin %s (%d) for %s | Reason: %s (%d/%d/%d | %d:%d)",pName,id,aName,playerid,ConvertTime(Temp,m,h,d),reason,day,month,year,hour,minuite);
          format(echo,sizeof(echo),"0,4** %s (%d) has been temporarily banned by Admin %s (%d) for %s | Reason: %s (%d/%d/%d | %d:%d)",pName,id,aName,playerid,ConvertTime(Temp,m,h,d),reason,day,month,year,hour,minuite);
          SCMTA(pink,tbans);
          IRC_Say(gGroupID, IRC_CHANNEL, echo);
          IRC_Say(gGroupID, IRC_ACHANNEL, echo);
          Temp = BanTime - gettime();
          format(umad,sizeof(umad),"Admin %s (%d) has temp banned you for %s - Reason |: %s", aName,playerid,ConvertTime(Temp,m,h,d),reason);
          SCM(id,pink,umad);
          KickTimer[id] = SetTimerEx("KickPlayer",100,false,"d",id);
    }
    return 1;
}
This is the ConvertTime stock i use (not made by me, just adapted)

pawn Код:
stock ConvertTime(&cts, &ctm=-1,&cth=-1,&ctd=-1,&ctw=-1,&ctmo=-1,&cty=-1)
{
    #define PLUR(%0,%1,%2) (%0),((%0) == 1)?((#%1)):((#%2))

    #define CTM_cty 31536000
    #define CTM_ctmo 2628000
    #define CTM_ctw 604800
    #define CTM_ctd 86400
    #define CTM_cth 3600
    #define CTM_ctm 60

    #define CT(%0) %0 = cts / CTM_%0; cts %= CTM_%0

    new strii[128];

    if(cty != -1 && (cts/CTM_cty))
    {
        CT(cty); CT(ctmo); CT(ctw); CT(ctd); CT(cth); CT(ctm);
        format(strii, sizeof(strii), "%d %s, %d %s, %d %s, %d %s, %d %s, %d %s, and %d %s",PLUR(cty,"year","years"),PLUR(ctmo,"month","months"),PLUR(ctw,"week","weeks"),PLUR(ctd,"day","days"),PLUR(cth,"hour","hours"),PLUR(ctm,"minute","minutes"),PLUR(cts,"second","seconds"));
        return strii;
    }
    if(ctmo != -1 && (cts/CTM_ctmo))
    {
        cty = 0; CT(ctmo); CT(ctw); CT(ctd); CT(cth); CT(ctm);
        format(strii, sizeof(strii), "%d %s, %d %s, %d %s, %d %s, %d %s, and %d %s",PLUR(ctmo,"month","months"),PLUR(ctw,"week","weeks"),PLUR(ctd,"day","days"),PLUR(cth,"hour","hours"),PLUR(ctm,"minute","minutes"),PLUR(cts,"second","seconds"));
        return strii;
    }
    if(ctw != -1 && (cts/CTM_ctw))
    {
        cty = 0; ctmo = 0; CT(ctw); CT(ctd); CT(cth); CT(ctm);
        format(strii, sizeof(strii), "%d %s, %d %s, %d %s, %d %s, and %d %s",PLUR(ctw,"week","weeks"),PLUR(ctd,"day","days"),PLUR(cth,"hour","hours"),PLUR(ctm,"minute","minutes"),PLUR(cts,"second","seconds"));
        return strii;
    }
    if(ctd != -1 && (cts/CTM_ctd))
    {
        cty = 0; ctmo = 0; ctw = 0; CT(ctd); CT(cth); CT(ctm);
        format(strii, sizeof(strii), "%d %s, %d %s, %d %s, and %d %s",PLUR(ctd,"day","days"),PLUR(cth,"hour","hours"),PLUR(ctm,"minute","minutes"),PLUR(cts,"second","seconds"));
        return strii;
    }
    if(cth != -1 && (cts/CTM_cth))
    {
        cty = 0; ctmo = 0; ctw = 0; ctd = 0; CT(cth); CT(ctm);
        format(strii, sizeof(strii), "%d %s, %d %s, and %d %s",PLUR(cth,"hour","hours"),PLUR(ctm,"minute","minutes"),PLUR(cts,"second","seconds"));
        return strii;
    }
    if(ctm != -1 && (cts/CTM_ctm))
    {
        cty = 0; ctmo = 0; ctw = 0; ctd = 0; cth = 0; CT(ctm);
        format(strii, sizeof(strii), "%d %s, and %d %s",PLUR(ctm,"minute","minutes"),PLUR(cts,"second","seconds"));
        return strii;
    }
    cty = 0; ctmo = 0; ctw = 0; ctd = 0; cth = 0; ctm = 0;
    format(strii, sizeof(strii), "%d %s", PLUR(cts,"second","seconds"));
    return strii;
}
Thank you.
Reply
#2

Dear Logitech90,


If you wanna specify only days for tempbans, then the code could be alot more "slim", compared to what you posted. Though, i never ever tested or even compiled it, i still think, it'd look like the followings:

pawn Код:
CMD:tempban(playerid, params[])
{
    if(pInfo[playerid][Admin] >= 5)
    {
        new id, reason[128], aName[MAX_PLAYER_NAME], pName[MAX_PLAYER_NAME];
        new days, year, month, day, hour, minute;
       
        if(sscanf(params, "uis[250]", id, days, reason)) return SendClientMessage(playerid, -1, "{F70505}Usage: {FFFFFF}/tempban <playerid> <days> <reason>");
        if(!IsPlayerConnected(id)) return SendClientMessage(playerid, red, "Invalid player ID.");

        GetPlayerName(playerid, aName, sizeof(aName));
        GetPlayerName(id, pName, sizeof(pName));
        pInfo[id][TempBan] = (gettime() + (86400*days));
        getdate(year, month, day);
        gettime(hour, minute);
       
        new tBans[256], echo[256], banmsg[128];
        format(tBans, sizeof(tBans), "** %s (%d) has been temporarily banned by Admin %s (%d) for %d days | Reason: %s (%02d/%02d/%04d | %02d:%02d)", pName, id, aName, playerid, days, reason, day, month, year, hour, minute);
        format(echo, sizeof(echo), "0,4** %s (%d) has been temporarily banned by Admin %s (%d) for %d days | Reason: %s (%02d/%02d/%04d | %02d:%02d)", pName, id, aName, playerid, days, reason, day, month, year, hour, minute);
        format(banmsg, sizeof(banmsg), "Admin %s (%d) has temp banned you for %d days | Reason: %s", aName, playerid, days, reason);
       
        SendClientMessageToAll(pink, tBans);
        IRC_Say(gGroupID, IRC_CHANNEL, echo);
        IRC_Say(gGroupID, IRC_ACHANNEL, echo);
        SendClientMessage(id, pink, banmsg);
       
        KickTimer[id] = SetTimerEx("KickPlayer", 100, false, "d", id);
    }
    return 1;
}
As you can see, there's no need for any additional extra stocks for it also. Hope, it'll do the desired job for you.


Kind regards,
T101
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)