Forum Moderators: coopster

Message Too Old, No Replies

Replicating a timing system

         

dkin

4:29 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



I am trying to replicate a countdown system such as the on on the kingsofchaos.com site, every 1/2 hour a point is given to every player, how would I go about doin this?

Salsa

6:03 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



This is just off the top of my head, but without running a chron job every half hour, you could store a half-hour value for the previous points update in a database, or, probably better, just a simple, counter type file. Then, whenever there is any activity by a memeber, you'd compare the current half-hour value with the previous half-hour value and make the wanted updates, like:

$current_half_hour = floor(mktime()/1800); 
//mktime() returns the number of seconds since 1/1/1970.
//the above would return the number of full half-hours since 1/1/1970
$previous_half_hour = // get the previous value from db or file
if ($current_half_hour > $previous_half_hour) {
$add_points = $current_half_hour - $previous_half_hour;
$sql = "UPDATE users SET points = points + $add_points";
//run the above query on the presumed user database
$previous_half_hour += $add_points; //update counter record with new value
}

Warning: make sure you preset the counter record with the value for the current half hour (or somewhat earlier if you want to make the points retroactive to some date). If it starts at zero, you'll give everyone about 600,000 points the first time around!

I hope this helps