Giving a user a turn every 15 minutes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Giving a user a turn every 15 minutes

Post 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());
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

anybody?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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);
Post Reply