Jump to content
  • 0

Player logout time


Hijirikawa

Question


  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

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

  • 0

  • Group:  Developer
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  141
  • Reputation:   45
  • Joined:  08/14/12
  • Last Seen:  

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.

Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  141
  • Reputation:   45
  • Joined:  08/14/12
  • Last Seen:  

Just use gettimetick(2) and calculate the difference.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

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?

Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  141
  • Reputation:   45
  • Joined:  08/14/12
  • Last Seen:  

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]

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

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)?

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2346
  • Joined:  10/28/11
  • Last Seen:  

exact login time ( gettimetick(2) ) minus last saved logout time ( gettimetick(2) )

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

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;
Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  141
  • Reputation:   45
  • Joined:  08/14/12
  • Last Seen:  

Youre using the wrong timetick; you need to use gettimetick(2), and you need use the logic I used in my above post

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

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;
Link to comment
Share on other sites

  • 0

  • Group:  Developer
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  141
  • Reputation:   45
  • Joined:  08/14/12
  • Last Seen:  

Yup, that'll work

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  19
  • Topics Per Day:  0.01
  • Content Count:  193
  • Reputation:   41
  • Joined:  07/21/16
  • Last Seen:  

Alright, thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...