Jump to content
  • 0

Total time online of a player saved in db


Question

Posted

Is there any chanse to k now the total time online like a timer that starts when someone login, and stop when someone be afk, or vending or logout or something like these?

I think i can made the stoped part, but i really dont know how inicialize the timer

Do anyone have any clue about this?

Thanks a lot n_n

9 answers to this question

Recommended Posts

Posted

You can start by save the login time tick in a variable, just like this:

OnPcLoginEvent:
set tick, gettimetick(2);

When the player logs out, you can subtract the setted tick with an actual tick, then sum it with the value on DB, just like this:

OnPcLogoutEvent:
set time, gettimetick(2) - tick;

This will give you the time (in seconds) that the player were online. I'll let the queries part up to you! ;)

  • Upvote 2
Posted

should be like this...

OnPCLoginEvent:
@login_time = gettimetick(2);
end;
OnPCLogoutEvent:
#online_time += ( gettimetick(2) - @login_time );
end;

@login_time will be deleted after "end;"

And, yes, it would be a better idea to store it on an account variable.

  • Upvote 1
Posted

yes...because we dont need to save it permanently....

we only need a permanent variable to store total online time..not the "different" between login time and logout time..

your method that shown in above...

the "time" variable will be reset and assigned with new value everytime they login and logout....

  • Upvote 1
Posted (edited)

I did it that way because she said to store it on Database. I was expecting her to make a query that updates the old value plus the new "time" value, so there woudn't be problems on reseting the variable everytime the players logon again.

As I said, "I'll let the queries part up to you!"...

Edited by Schrwaizer
  • Upvote 1
Posted

Emistry's script does exactly the same to what your script does, but in a cleaner fashion. "@login_time" is your "tick", and since "Tick" 's value will change again upon login, it is pointless to have it as a permanent variable stored in the database. The Variable Emistry used, isn't deleted upon 'end' but upon server restart.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...