Getting time

luan122

New member
Messages
38
Points
0
I want to get the total time that player is online in the server, so I have this script:
 

OnPCLoginEvent:
@login_time = gettimetick(2);
end;
OnPCLogoutEvent:
query_sql("UPDATE login SET online_time = online_time + "+( gettimetick(2) - @login_time )+" WHERE account_id = "+getcharid(3));
end;


What I want to know is if the way I'm sum it is correct and how can I convert the final value in time as h:m:s I tried to find it but didn't

Thanks!

 
What I want to know is if the way I'm sum it is correct





 
Ok if it works...

 I convert the final value in time as h:m:s I tried to find it but didn't





 


You don't at this point ...

You do it when you retrieve using something like this

Select @Days = (online_time / 60 / 60 / 24) FROM ... WHERE...




UPD:

Disregard my last, don't perform any calculations at select just

do a Simple select into your script

Select online_time FROM ... WHERE...


then inside your script convert this logic into Herc scripting

Code:
function GetTimeDiff($online_time) 
{
    $how_log_ago = '';
    $minutes = (int)($online_time / 60);
    $hours = (int)($minutes / 60);
    $days = (int)($hours / 24);
    if ($days >= 1) {
      $how_log_ago = $days . ' day' . ($days != 1 ? 's' : '');
    } else if ($hours >= 1) {
      $how_log_ago = $hours . ' hour' . ($hours != 1 ? 's' : '');
    } else if ($minutes >= 1) {
      $how_log_ago = $minutes . ' minute' . ($minutes != 1 ? 's' : '');
    } else {
      $how_log_ago = $online_time . ' second' . ($online_time != 1 ? 's' : '');
    }
    return $how_log_ago;
}
If you implement 

it should give you XX day XX hour XX minute XX second

 
Last edited by a moderator:
in php the exactly function gave me back this information: 34669 days i think something is wrong in the proccess, not sure if is when I save or when I retrieve... the value I have in db is 2995424936.

 
well.....

2995424936 secs is 34669 days



2995424936 / 60 / 60 / 24 = 34669

Maybe it's miliseconds? I'm not that familiar with scripting language..

 
even adding / 1000 it gave me 34 days that isn't correct since I didn't expend those days playing

 
in php the exactly function gave me back this information: 34669 days i think something is wrong in the proccess, not sure if is when I save or when I retrieve... the value I have in db is 2995424936.
Something's wrong with your db value I guess.

getting tickets(2) doesn't return millisecond, and having that high time is not possible. Maybe somewhere you inserted some high value in online_time field.

 
Something's wrong with your db value I guess.

getting tickets(2) doesn't return millisecond, and having that high time is not possible. Maybe somewhere you inserted some high value in online_time field.
Yepe i did a mistake I did it from the start and it comes a true value in seconds, thank you all!

 
Back
Top