luan122 3 Posted June 20, 2017 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
0 Habilis 119 Posted June 20, 2017 (edited) 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 June 20, 2017 by Habilis Share this post Link to post Share on other sites
0 luan122 3 Posted June 20, 2017 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 Habilis 119 Posted June 20, 2017 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 luan122 3 Posted June 20, 2017 even adding / 1000 it gave me 34 days that isn't correct since I didn't expend those days playing Share this post Link to post Share on other sites
0 Dastgir 1246 Posted June 21, 2017 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 luan122 3 Posted June 21, 2017 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
I want to get the total time that player is online in the server, so I have this script:
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