there is a better way to do this then counting every second.
the only problem is it wouldnt be able to tell you your exact amount of time for your current log in. It would however easily be able to tell you the length of time you where online for your previous log in and your total online time over the life of the character
you would need to give each player 3 storage values for now lets call the storage values "TOTALONLINETIME", "LASTVISITLENGTH", "LOGINTIME". Every time you log in it checks the time of your last log out and adds the difference.
- you log in at 1200 put that value in "LOGINTIME"
- you log out at 1800 take that time and subtract "LOGINTIME" from it It would be 6hours -> add 6hrs to "TOTALONLINETIME" and in "LASTVISITLENGTH" put 6hours
- you log in at 2400 put that value in "LOGINTIME"
- you log out the next day at 1000 -> add 10hrs a total of 16hrs now is stored in "TOTALONLINETIME", "LASTVISITLENGTH" would be changed to 10 hours.
- etc...
I have already made it 3 days ago.
As I mentioned in my sample:
You have been online for
3 seconds since you logged in. You played for 2708 seconds before.
Your total played time is 2711 seconds.
It is telling me the total "live" played time. I do not count my time. I dont understand what you said but I think I have something similar:
In login I just write:
Lua:
doCreatureSetStorage(cid, 1236, os.time())
in logout I just write:
Lua:
doCreatureSetStorage(cid, 1237, (getCreatureStorage(cid, 1237) + (os.time()-getCreatureStorage(cid, 1236))))
And talkaction which allows you to check your played time:
Lua:
doCreatureSay(cid, "You have been online for "..(os.time()-getCreatureStorage(cid, 1236)).." seconds since you logged in. You played for "..getCreatureStorage(cid, 1237).." seconds before. Your total played time is "..getCreatureStorage(cid, 1237)+(os.time()-getCreatureStorage(cid, 1236)).." seconds.")
Its simple math.
So you are wrong. It is easy to find out exact amount of time for your current log in. I did it without any hazzle at all.
And by the way, im only using 2 storagevalues.
Start recording and total.
login script will replace everything in "start recording" with current os.time.
When doing talkaction, /played etc. It compare start recording value with current os.time, and fetch the seconds of your currently online played time.
On logout, it does the same, but instead of telling you it, it saves it to the "total" storage.
If you want live total played time, you first fetch currently online played time, and + it with total storage. Result is total before you logged in + while you are logged in.
I am soon going to modify my save script to take backups of played time in-case server crash and it dosnt get to save characters played time which it does in the logout script. This will require 1 additional storage and slight modification to the logout script.