Jump to content
  • 0
luan122

Getting time

Question

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!

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
47 minutes ago, luan122 said:

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

 

Ok if it works...

47 minutes ago, luan122 said:

 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

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

 

Edited by Habilis

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

well.....

2995424936 secs is 34669 days

2995424936 / 60 / 60 / 24 = 34669

 

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

 

 

Share this post


Link to post
Share on other sites
  • 0
10 hours ago, luan122 said:

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.

Share this post


Link to post
Share on other sites
  • 0
13 hours ago, Dastgir said:

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!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.