Calculations. - iLearner - 30.08.2016
Hello,
I have made a small temp ban system, what it actually dies is ask admin the number of days.
and i am taking those days like this:
hours= 24/days;
secs = hours*3600;
unbants = gettime() + secs;
In unban_time field i set it the value to unbants(and we're ok until here).
but when the player tries to join while banned, i want to show him how many days are left until he'll stay banned...
and this is what i do:
PHP код:
public TempBanChecking(playerid)
{
new banquery[180], days, time, ip[16];
GetPlayerIp(playerid, ip, 16);
mysql_format(1, banquery, sizeof(banquery), "SELECT `unban_time` FROM `TBanData` WHERE `ip` = '%s'", ip);
new Cache:cacheid = mysql_query(1, banquery);
if(cache_num_rows() != 0) //if an unban time was found with their ip address
{
new unbantimestamp = cache_get_field_content_int(0, "unban_time");// = mysql_fetch_int(); //get the timestamp from the database
new string[128];
mins =(unbantimestamp - gettime())/60;
hours = mins/60;
days = hours/24;
//format(string, sizeof(string), "[DEBUG]An unban timer was found! %d > %d",unbantimestamp, time);
//SendClientMessageToAll(COLOR_WHITE, string);
if(unbantimestamp > time) //if the unban time hasn't been reached yet
{
format(string, sizeof(string), "You're banned from this server... for %d days", days);
SendClientMessage(playerid, -1, string);
}
}
cache_delete(cacheid);
}
but those days are showed like a huge number... so what did i do wrong in maths... ?
for example a 3 days ban is: 1472088830
Re: Calculations. -
AndySedeyn - 30.08.2016
Your calculations are wrong. An hour divided by 60 is equal to 1 minute because there are 60 minutes in an hour. Knowing that, you know that a minute divided by 60 can never be an hour, so it has to be something smaller. In this case: 1 minute divided by 60 is equal to 1 second because there are 60 seconds in 1 minute.
Re: Calculations. - iLearner - 30.08.2016
Could you post the right calculations to convert it into days?
Re: Calculations. -
Shinja - 30.08.2016
PHP код:
SecondToTime(seconds)
{
new string[40], minutes, hours, newseconds = seconds;
while(newseconds>=60){newseconds-=60,minutes++;}
while(minutes>=60){minutes-=60,hours++;}
format(string, sizeof(string), "%02dHour%s : %02dMinute%s : %02dSecond%s", hours, (hours > 1)?("s"):(""), minutes, (minutes>1)?("s"):(""), newseconds, (newseconds>1)?("s"):(""));
//debug printf("[converter] %d seconds are %02d hours and %02d minutes and %02d seconds", seconds, hours, minutes, newseconds);
return string;
}
Re: Calculations. - iLearner - 30.08.2016
Seconds to days...
Re: Calculations. -
Shinja - 30.08.2016
PHP код:
SecondToTime(seconds)
{
new string[40], minutes, hours, days, newseconds = seconds;
while(newseconds>=60){newseconds-=60,minutes++;}
while(minutes>=60){minutes-=60,hours++;}
while(hours>=24){hours-=24,days++;}
format(string, sizeof(string), "%d Day%s : %02dHour%s : %02dMinute%s : %02dSecond%s", days, (days > 1) ? ("s"):(""), hours, (hours > 1)?("s"):(""), minutes, (minutes>1)?("s"):(""), newseconds, (newseconds>1)?("s"):(""));
//debug printf("[converter] %d seconds are %d days and %02d hours and %02d minutes and %02d seconds", seconds, hours, minutes, newseconds);
return string;
}