ID:581173
 
(See the best response by Lugia319.)
I would like a Universal Countdown timer implemented into my game.

Now i am familiar without to set up something that counts down and resets upon reaching zero, however what I do not know how to do is make it so that upon sever creation the counter will start up, and continue to do so even if players are offline, and having all players effected by this, EVEN if the player is offline.

Obviously this means that I would have to implement saving that is not saved to the users computer, so it can be updated. Then having that information accessed and loaded upon player log in.

So as an example, if i have a timer that reaches zero, it will effect all players who are currently in the game, even if offline.

The problem I'm having is, that I know what I want to do, but I don't know what i need to do.

Advice?


EDIT: And upon server shutdown or crash it would save what the count was for the timer. Basically when timer reaches zero, count +1.
Best response
If you can save players, you can save global variables as well. If all else fails, you can import/export from a text file to handle the count thing.

The count variable should handle everything. Store a count variable on the player. If the count on the player is different from that of the world, then you know that the time passed. Example:

Player A logs in, starts with count zero. World is at count 4.

mob
var
ICount = 4 // Initial count - num (Count when player logged in)
PCount = 0 // Player count - num


Player A logs out, logs in after 2 counts have passed. World count is now 6. How do we handle the player count varible? Simples.

mob.PCount = Count - ICount // 6 - 4 = 2

The player's count is the difference in the two count variables. The world count (which started at 4) and the ICount variable (which keeps track of which count the player joined on. The difference is the total of how many counts has passed)

Oh, and to make it start when the world starts,

world 
New() // When the world is started
..() // Normal Biz
spawn(0) Countdown() // Start the GLOBAL countdown proc
But if my countdown proc is assigning a count +1 every...lets say...10 mins, or whatever - How is that measured towards the player?

I am assuming that upon log in, I merely call a CountCheck() ? Right?


Also saving this variable (the world count) would have to be done so on the hosts computer - or where else can I save it?

The player's ICount is used to keep track of the count the player started the game with. I make the assumption that count is always increasing, for both world and player. So yes, you'd do some sort of check to see what the difference between the count they started playing and the count the world is on. That difference is the count you desire. You don't necessarily need a proc, as it's really only 1 line of code (unless there's more going into it).

If you mean that the world is still running and you can't figure out the obvious "Add 1 to the count of all players in world when countdown reaches 0" then I don't know what to tell you.

This variable is best stored on the host, for the sake of simplicity.
Well i'm planning on adding more for example more counts that have gone by since the last login the more others vars are effected.