Giving a user a turn every 15 minutes
Posted: Sun Jun 04, 2006 6:22 pm
I can't figure out how to give a user every 15 minutes. This is a web based game im working on and I only want to give them a maximime of 100 turns so they cant stack turns.
I came up with this. LastTurnUpdate starts off with time() that you created your character
so then next turn is within 15 minutes. if its greater then 1 since it allows decimals, and if turns is less then 100, give them the turns.
The next part im stuck on. adding back the LastTurnUpdate so its ready to do the same thing again.
I came up with this. LastTurnUpdate starts off with time() that you created your character
so then next turn is within 15 minutes. if its greater then 1 since it allows decimals, and if turns is less then 100, give them the turns.
The next part im stuck on. adding back the LastTurnUpdate so its ready to do the same thing again.
Code: Select all
//figure out when user's next turn update is
$date1 = $row['LastTurnUpdate'];
$date2 = time();
$turn = ($date2 - $date1) / (60 * 15);
//get turns. if new turn
if ($turn > 1)
{
if ($row['Turns'] < 100) //if turns is less then 100. i want to limit turns to 100
{
if ($row['Turns'] + (integer) ($turn / 15) > 100) //if current turns and new turns greater then 100
{
$turns = 100;
}
else //if currecnt turns and new turns lesser ten 100
{
$turns + (integer) ($turn / 15);
}
}
}
//update LastTurnUpdate in sql database
$next_last_turn_update = $row['LastTurnUpdate'] * (60 * 15);
mysql_query ("UPDATE Naruto_Chars SET LastTurnUpdate='$next_last_turn_update', turns='$turns' WHERE user_id='$user_id' AND i = $id") or die(mysql_error());