Jump to content

hpRegen-script


feelay

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.