Two string (time) compare and calculate how much time passed
#1

Heelloo every1!

I have been trying to make a script, witch calculates how much time passed since player last logged in.
So, I have this datetime script I made, 1min = 5005ms

As the minutes goes when reaches 60, hour goes plus, but minutes resets. And so on. The same goes with days, months, years.

It is pretty simple, as you can see,
I am not goot at maths, so when I am trying to make this script, it makes a lot of trouble.

Firstly I looked all over the internet about these time things and their calculations. Also, tried to understand in PHP, witch made more sense, but when I got to pawn and started to understand a lot of different script, I really fucked up my brain.

So, found this script made by Y-Less, called mktime. I would be grateful if someone could explain me, how exactly this script works and much love if could help, together make that - time passed since - scrpt.

Thankyou!

PS: the script by y-less
PHP Code:
mktime(hour,minute,second,day,month,year)
{
    new 
timestamp2;
    
timestamp2 second + (minute 60) + (hour 3600);
    new 
days_of_month[12];
    if ( ((
year == 0) && (year 100 != 0)) || (year 400 == 0) ) {
            
days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
        
} else {
            
days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
        
}
    new 
days_this_year 0;
    
days_this_year day;
    if(
month 1) { // No January Calculation, because its always the 0 past months
        
for(new i=0i<month-1;i++) {
            
days_this_year += days_of_month[i];
        }
    }
    
timestamp2 += days_this_year 86400;
    for(new 
j=1970;j<year;j++) {
        
timestamp2 += 31536000;
        if ( ((
year == 0) && (year 100 != 0)) || (year 400 == 0) )  timestamp2 += 86400// Schaltjahr + 1 Tag
    
}
    return 
timestamp2;

Reply
#2

okey to make t easier to explain:
PHP Code:
TimePassedSince(playeriddatetime[])
{
    new 
str[128];
    
format(strsizeof(str), "Since last login you have missed %02d days %02d months %02d years"CauculateTime(datetimeAccount[playerid][aServerDate]));
    return 
str;

Reply
#3

I don't think you could use that for this purpose,

You can save the player 'last time' as unix time ( gettime() ) under OnPlayerDisconnect. When they connect again, compare the saved time with the actual time (unix) and send that info to the player. You would want to make a function for this in order to make it look nicer (like not just seconds but to separate seconds, hours, days, etc)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)