Hijirikawa Posted August 17, 2016 Group: Members Topic Count: 19 Topics Per Day: 0.01 Content Count: 193 Reputation: 42 Joined: 07/21/16 Last Seen: August 7, 2019 Share Posted August 17, 2016 I'm trying to make a script, but I need the formula on how to calculate the player's logout time efficiently. Can anyone help me with this one? Thanks. Quote Link to comment Share on other sites More sharing options...
0 nitrous Posted August 18, 2016 Group: Developer Topic Count: 4 Topics Per Day: 0.00 Content Count: 141 Reputation: 46 Joined: 08/14/12 Last Seen: Saturday at 07:07 AM Share Posted August 18, 2016 Gettimetick(2) is the number of seconds since the unix epoch (Jan 1st 1970). When you log out, "set LogOutTick, gettimetick(2)". For example, let's say 1000000. When you log in, "set LogInTick, gettimetick(2)". For example, let's say 1100000. So "LogInTick - LogOutTick" is 1100000 - 1000000 = 100000. The player has been offline for 100000 seconds. Quote Link to comment Share on other sites More sharing options...
0 nitrous Posted August 17, 2016 Group: Developer Topic Count: 4 Topics Per Day: 0.00 Content Count: 141 Reputation: 46 Joined: 08/14/12 Last Seen: Saturday at 07:07 AM Share Posted August 17, 2016 Just use gettimetick(2) and calculate the difference. Quote Link to comment Share on other sites More sharing options...
0 Hijirikawa Posted August 17, 2016 Group: Members Topic Count: 19 Topics Per Day: 0.01 Content Count: 193 Reputation: 42 Joined: 07/21/16 Last Seen: August 7, 2019 Author Share Posted August 17, 2016 how would the calculation be? The description says it counts the second since start of current day. However, what if, for instance the player played at 01:00 server time, and then log back in the next day at 12:00, would it not result in a negative number? Quote Link to comment Share on other sites More sharing options...
0 nitrous Posted August 17, 2016 Group: Developer Topic Count: 4 Topics Per Day: 0.00 Content Count: 141 Reputation: 46 Joined: 08/14/12 Last Seen: Saturday at 07:07 AM Share Posted August 17, 2016 https://github.com/rathena/rathena/blob/master/doc/script_commands.txt#L2959-L2968 gettimetick(2) returns the epoch time So on logout, you store the timetick [logouttime]. On login, you get the timetick [logintime], then the offline time is [logintime - logouttime] Quote Link to comment Share on other sites More sharing options...
0 Hijirikawa Posted August 18, 2016 Group: Members Topic Count: 19 Topics Per Day: 0.01 Content Count: 193 Reputation: 42 Joined: 07/21/16 Last Seen: August 7, 2019 Author Share Posted August 18, 2016 Sorry I'm still confused, but if the formula would be logintime - logouttime, wouldn't there be a chance of it being negative if we use gettimetick(2)? Quote Link to comment Share on other sites More sharing options...
0 Emistry Posted August 18, 2016 Group: Forum Moderator Topic Count: 93 Topics Per Day: 0.02 Content Count: 10018 Reputation: 2369 Joined: 10/28/11 Last Seen: 59 minutes ago Share Posted August 18, 2016 exact login time ( gettimetick(2) ) minus last saved logout time ( gettimetick(2) ) Quote Link to comment Share on other sites More sharing options...
0 Hijirikawa Posted August 18, 2016 Group: Members Topic Count: 19 Topics Per Day: 0.01 Content Count: 193 Reputation: 42 Joined: 07/21/16 Last Seen: August 7, 2019 Author Share Posted August 18, 2016 I see now, thanks.Now, for instance, limit is 24 hours, then I should do this? OnPCLogoutEvent: set checkday,gettimetick(1); end; OnPCLoginEvent: if(gettimetick(1) >= checkday) dispbottom "You have been away for more than 1 day"; end; Quote Link to comment Share on other sites More sharing options...
0 nitrous Posted August 18, 2016 Group: Developer Topic Count: 4 Topics Per Day: 0.00 Content Count: 141 Reputation: 46 Joined: 08/14/12 Last Seen: Saturday at 07:07 AM Share Posted August 18, 2016 Youre using the wrong timetick; you need to use gettimetick(2), and you need use the logic I used in my above post Quote Link to comment Share on other sites More sharing options...
0 Hijirikawa Posted August 19, 2016 Group: Members Topic Count: 19 Topics Per Day: 0.01 Content Count: 193 Reputation: 42 Joined: 07/21/16 Last Seen: August 7, 2019 Author Share Posted August 19, 2016 How about this? OnPCLogoutEvent: set checkday,gettimetick(2) + 84600; //logout time + 24 hours end; OnPCLoginEvent: if(gettimetick(2) >= checkday) dispbottom "You have been away for more than 1 day"; end; Quote Link to comment Share on other sites More sharing options...
0 nitrous Posted August 19, 2016 Group: Developer Topic Count: 4 Topics Per Day: 0.00 Content Count: 141 Reputation: 46 Joined: 08/14/12 Last Seen: Saturday at 07:07 AM Share Posted August 19, 2016 Yup, that'll work 1 Quote Link to comment Share on other sites More sharing options...
0 Hijirikawa Posted August 19, 2016 Group: Members Topic Count: 19 Topics Per Day: 0.01 Content Count: 193 Reputation: 42 Joined: 07/21/16 Last Seen: August 7, 2019 Author Share Posted August 19, 2016 Alright, thanks. Quote Link to comment Share on other sites More sharing options...
Question
Hijirikawa
I'm trying to make a script, but I need the formula on how to calculate the player's logout time efficiently. Can anyone help me with this one? Thanks.
Link to comment
Share on other sites
11 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.