24.02.2016, 07:05
I tried rearranging the code and making some unnecessary arrays smaller, and came to this:
The code abruptly ends before the INI_WriteInt, mainly because the integer you are trying to save is too large. I just ran the code and I got this integer:
That was a 1 day ban. (Which reminds me, you should also add checks to see whether day is below 1...)
So, as annoying as it is, you should find an alternative method to 'gettime' and then adding on the seconds.
Here's my version of the code:
pawn Код:
CMD:tempban(playerid, params[])
{
if(pInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You're not authorized to use this command.");
new
id[24],
days,
reason[60]
;
if(sscanf(params, "s[24]is[60]", id, days, reason)) return SCM(playerid, -1, "USAGE: /tempban [player name] [days] [reason]");
new filestring[40];
format(filestring, sizeof(filestring), "/Users/%s.ini", id);
if(!fexist(filestring)) return SCM(playerid, COLOR_RED, "This username doesnt exist! ");
new
exp = gettime() + (86400 * days),
INI:File = INI_Open(filestring),
banner[144]
;
INI_SetTag(File, "userdata");
INI_WriteInt(File, "pBanned", 1);
// Code ends here, returns error.
INI_WriteInt(File, "pBannedExp", exp);
INI_Close(File);
format(banner, sizeof(banner), "You have banned %s from the server for %d days.", id, days);
SCM(playerid, COLOR_RED, banner);
format(banner, sizeof(banner), "%s has been temporarily banned by %d %d for %d days | Reason: %s", id, AdminRank(playerid), RemoveUnderScore(playerid), days, reason);
SCMToAll(COLOR_RED, banner);
return 1;
}
Код:
exp = 1456387343
So, as annoying as it is, you should find an alternative method to 'gettime' and then adding on the seconds.
Here's my version of the code:
pawn Код:
CMD:tempban(playerid, params[])
{
if(pInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You're not authorized to use this command.");
new
id[24],
days,
reason[60]
;
if(sscanf(params, "s[24]is[60]", id, days, reason)) return SCM(playerid, -1, "USAGE: /tempban [player name] [days] [reason]");
if(days < 1) return SCM(playerid, COLOR_RED, "Ban duration needs to be at least 1 day or more.");
new filestring[40];
format(filestring, sizeof(filestring), "/Users/%s.ini", id);
if(!fexist(filestring)) return SCM(playerid, COLOR_RED, "This username doesn't exist! ");
new
exp = gettime() + (86400 * days),
INI:File = INI_Open(filestring),
banner[144]
;
INI_SetTag(File, "userdata");
INI_WriteInt(File, "pBanned", 1);
// WriteInt and gettime() do not mix well, mainly because gettime returns such a large integer. Alternative methods will need to be used.
INI_WriteInt(File, "pBannedExp", exp);
INI_Close(File);
format(banner, sizeof(banner), "You have banned %s from the server for %d days.", id, days);
SCM(playerid, COLOR_RED, banner);
format(banner, sizeof(banner), "%s has been temporarily banned by %d %d for %d days | Reason: %s", id, AdminRank(playerid), RemoveUnderScore(playerid), days, reason);
SCMToAll(COLOR_RED, banner);
return 1;
}

