feelay Posted February 15, 2008 Share Posted February 15, 2008 Hey. This script is almost done, but something is stopping the value from updating.What I am trying to do is: I want the script to make the users HP update every minute. Here is the code: <?php $frequency = 60; $increment = 10; $current_time = time(); $last_update_time = mysql_result(mysql_query("SELECT `value` FROM `configuration` WHERE `name` = 'last_update'"), 0); $time_difference = $current_time - $last_update_time; $hours_passed = $time_difference / $frequency; $full_hours_passed = floor($hours_passed); $remaining_seconds = $time_difference % $frequency; if($full_hours_passed > 0){ $new_update_time = $current_time - $remaining_seconds; $hp_increase = $full_hours_passed * $increment; mysql_query("UPDATE `characters` SET `temphealth` = CASE WHEN `temphealth` + $hp_increase <= `maxhp` THEN `temphealth` + $hp_increase ELSE `maxhp` END WHERE `temphealth` > `maxhp`"); mysql_query("UPDATE `configuration` SET `value` = $new_update_time WHERE `name` = 'last_update'"); } if(isset($_SESSION['session..'])){ echo $current_time." current_time<br> ".$last_update_time." last_update_time<br>".$time_difference." time_difference <br>".$hours_passed." hours_passed<br> ".$full_hours_passed." full_hours_passed<br> ".$remaining_seconds." remaining_seconds<br> ".$new_update_time." new_update_time<br> ".$hp_increase." hp_increase<br>".$frequency." frequency<br> ".$increment." increment<br><br><br><br>";} ?> And here is the value for every Variable at 2 different times: 1203101853 current_time 1203101821 last_update_time 32 time_difference 0.533333333333 hours_passed 0 full_hours_passed 32 remaining_seconds new_update_time hp_increase 60 frequency 10 increment 1203101853 current_time 1203101821 last_update_time 32 time_difference 0.533333333333 hours_passed 0 full_hours_passed 32 remaining_seconds new_update_time hp_increase 60 frequency 10 increment The values changes all the time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.