06.10.2013, 12:24
I use the timec function for bans. Here's an example, I use a slightly modified version of it so I only return the days left.
In your case, you could use something like:
pawn Код:
format(query,sizeof(query),"SELECT * FROM `bans` WHERE `owner` = '%s' OR `ip` = '%s' AND`time` > '%d'",GetName(playerid),realIP[playerid],gettime());
result = db_query(database,query);
if(db_num_rows(result))
{
new id,name[24],ip[16];
db_get_field_assoc(result,"id",ip,sizeof(ip)); id = strval(ip);
db_get_field_assoc(result,"owner",name,sizeof(name));
db_get_field_assoc(result,"ip",ip,sizeof(ip));
db_get_field_assoc(result,"reason",reason,sizeof(reason));
db_get_field_assoc(result,"time",string,sizeof(string)); time = strval(string);
format(string,sizeof(string),"You're banned.\n\nBan ID: %d\nBanned name: %s\nBanned IP: %s\nBan expires: %s",id,name,ip,timec(time));
ShowPlayerDialog(playerid,1,DIALOG_STYLE_MSGBOX,"Banned..",string,"Close","");
KickEx(playerid);
return db_free_result(result);
}
stock timec(timestamp,compare = -1)
{
if (compare == -1)
{
compare = gettime();
}
new n,Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,returnstr[32];
if (d < 60)
{
format(returnstr,sizeof(returnstr),"< 1 minute");
return returnstr;
}
else if (d < 3600)
{ // 3600 = 1 hour
n = floatround(floatdiv(d,60.0),floatround_floor);
format(returnstr,sizeof(returnstr),"minute");
}
else if (d < 86400)
{ // 86400 = 1 day
n = floatround(floatdiv(d,3600.0),floatround_floor);
format(returnstr,sizeof(returnstr),"hour");
}
else
{ // 2592000 = 1 month
n = floatround(floatdiv(d,86400.0),floatround_floor);
format(returnstr,sizeof(returnstr),"day");
}
if (n == 1)
{
format(returnstr,sizeof(returnstr),"1 %s",returnstr);
}
else
{
format(returnstr,sizeof(returnstr),"%d %ss",n,returnstr);
}
return returnstr;
}
pawn Код:
CMD:vip(playerid,params[])
{
new vip = GetPVarInt(playerid,"VIP"),string[124];
if(vip < gettime()) format(string,sizeof(string),"You're not a vip.");
else format(string,sizeof(string),"You're vip for the next %s",timec(vip));
SendClientMessage(playerid,-1,string);
return 1;
}