SA-MP Forums Archive
Calculations. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Calculations. (/showthread.php?tid=616018)



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], daystimeip[16];
    
GetPlayerIp(playeridip16);
    
mysql_format(1banquerysizeof(banquery), "SELECT `unban_time` FROM `TBanData` WHERE `ip` = '%s'"ip);
    new 
Cache:cacheid mysql_query(1banquery);
    
    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(stringsizeof(string), "You're banned from this server... for %d days"days);
            
SendClientMessage(playerid, -1string);
        }
    }
    
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], minuteshoursnewseconds seconds;  
    while(
newseconds>=60){newseconds-=60,minutes++;}  
    while(
minutes>=60){minutes-=60,hours++;}  
    
format(stringsizeof(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], minuteshoursdaysnewseconds seconds;  
    while(
newseconds>=60){newseconds-=60,minutes++;}  
    while(
minutes>=60){minutes-=60,hours++;}  
    while(
hours>=24){hours-=24,days++;}  
    
format(stringsizeof(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;