09.04.2013, 20:43
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?
This is the ConvertTime stock i use (not made by me, just adapted)
Thank you.
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;
}
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;
}