Hijirikawa Posted August 17, 2016 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
0 nitrous Posted August 18, 2016 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
0 nitrous Posted August 17, 2016 Posted August 17, 2016 Just use gettimetick(2) and calculate the difference. Quote
0 Hijirikawa Posted August 17, 2016 Author 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
0 nitrous Posted August 17, 2016 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
0 Hijirikawa Posted August 18, 2016 Author 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
0 Emistry Posted August 18, 2016 Posted August 18, 2016 exact login time ( gettimetick(2) ) minus last saved logout time ( gettimetick(2) ) Quote
0 Hijirikawa Posted August 18, 2016 Author 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
0 nitrous Posted August 18, 2016 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
0 Hijirikawa Posted August 19, 2016 Author 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
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.
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.