Page 1 of 1

Giving a user a turn every 15 minutes

Posted: Sun Jun 04, 2006 6:22 pm
by psychotomus
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.

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());

Posted: Sun Jun 11, 2006 12:22 pm
by psychotomus
anybody?

Posted: Sun Jun 11, 2006 1:01 pm
by John Cartwright
I assume $row['LastTurnUpdate'] field is a unix timestamp, and if that's the case you want to add (60 * 15) the the current time. You'll also notice instead of adding 15 minutes to the last turn, which would force people to move WITHIN 15 minutes, and not be able to move every 15 minutes, you should add 15 minutes to the current time.

Good:

Code: Select all

$next_last_turn_update = time() + (60 * 15);
Bad:

Code: Select all

$next_last_turn_update = $row['LastTurnUpdate'] * (60 * 15);