Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

GetTickCount on logout


Emy
 Share

Recommended Posts

Hello, I'm stuck with this and I need some advice.
I've made it so NPC's can give stuff to players, but I need them to only be able to give them out after a certain amount of time. For example, if you got your item, you have to wait 10min to get another one.

It works fine except when you logout or exit the game, the tick resets and you can get another item even if those 10min haven't passed. I used GetTickCount and it's serverside. Any help?
Link to comment
Share on other sites

I can only think about adding a variable to PlayerRec that will store the Tick value. As the timer is ticking away, the tick value will be saved in the said variable and if the player logs out and then logs back in, the timer will resume using the value from that variable. Hope you understand :cheesy:
Link to comment
Share on other sites

@Couture:

> That'd make sense, I actually tried it before, but it didn't work. I think it was cause I had the Tick so low then. So I tried it again and it works now, thanks :D

Aha, no problem :cheesy:
Link to comment
Share on other sites

Don't use GetTickCount for this. GetTickCount keeps track of the amount of ticks, since the start-up of an application. Therefore it will be reset, every time the server is rebooted.

Instead of using GetTickCount, you should use [GetFileTime](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724320%28v=vs.85%29.aspx) and use the time of when the file was last accessed (just make sure your application touches it, when the player actually logs out).

Yours faithfully
  S.J.R. van Schaik.
Link to comment
Share on other sites

or you can make something like 'itemCount as long' in playerRec,set this variable as how much time you want,like itemCount=10\. Go to serverLoop,create a new timer variable 'trm60000' < 1min,then put when trm60000 is active,itemcount=ItemCount-1.

hope you understand what I just say
Link to comment
Share on other sites

@Sawamura:

> or you can make something like 'itemCount as long' in playerRec,set this variable as how much time you want,like itemCount=10\. Go to serverLoop,create a new timer variable 'trm60000' < 1min,then put when trm60000 is active,itemcount=ItemCount-1.
>
> hope you understand what I just say

Why would you do something the operating system already does for you, and in a much better manner than you are proposing? Additionally, you just described the same solution as before, which isn't a solution. Just use the method I proposed.

Yours faithfully
  S.J.R. van Schaik.
Link to comment
Share on other sites

If I, for example, wanted to make this so this variable in playerrec resets at midnight, how should I do it so it updates all the accounts? I know that SavePlayer updates players that are online, but how do you update them all? Is there a variable like MAX_PLAYERS?
Link to comment
Share on other sites

@Couture:

> If I, for example, wanted to make this so this variable in playerrec resets at midnight, how should I do it so it updates all the accounts? I know that SavePlayer updates players that are online, but how do you update them all? Is there a variable like MAX_PLAYERS?

You don't. By doing exactly that you are having a lot of disk access going on, thus you will lose a lot of performance (since disk access is generally horribly slow).

What you do is this: if a player signs in, you check the date and time of modification for the file where his/her account is stored (using [GetFileTime](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724320%28v=vs.85%29.aspx), like I've mentioned before). Then you can compare that date and time with the current date and time to figure out what events are to be applied to that account. This can be done for both re-occurring events (e.g. every day at midnight) and once-in-a-lifetime events (e.g. 00:00AM, 1st of January, 2013). Since the player has signed in, the account will have to be loaded into memory, where the events that have occurred would enforce changes to be applied (in memory, which is faster than the disk; additionally you will only have to update players that have actually logged in, rather than all the players for every event). When the player signs out, the account information will be written to the disk, in which case those changes will be applied as well.

Yours faithfully
  S.J.R. van Schaik.
Link to comment
Share on other sites

You're so right, I didn't even think of that. Thank you for that great respond, it helps a lot!

Edit: Oh, a question: When you got the modified date and today's date, how would you compare these to see if the date have passed e.g. every day at midnight? I'm stuck and I can only figure out how to get how much time has passed, not if it actually have passed this time.

Appreciate all the help!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...