24.02.2015, 15:57
If you intend to let staff set the ban time, here's a short snippet for quickly grabbing an English string and converting it to seconds. It's a rather crude and basic parser but it does a decent job. Interprets (value) (unit) such as "1 week", "3 days", "1 day", etc:
pawn Код:
GetDurationFromString(string[])
{
new
value,
type[16];
if(sscanf(string, "ds[16]", value, type))
return -1;
if(value <= 0)
return -1;
if(!strcmp(type, "day", true, 3)) // only check 3 chars, technically "days" works, so does "daytona"...
return value * 86400;
if(!strcmp(type, "week", true, 4))
return value * 604800;
if(!strcmp(type, "month", true, 5))
return value * 2628000;
return -1;
}