<?php
//Перс
$be = mysql_fetch_array(mysql_query("SELECT * FROM `regenerator` WHERE `id_user` = '$user[id]' LIMIT 1"));
$be_count = mysql_result(mysql_query("SELECT COUNT(*) FROM `regenerator` WHERE `id_user` = '$user[id]'"),0);
if($be_count == 0){
mysql_query("INSERT INTO `regenerator` SET `id_user` = '$user[id]', `last` = '".time()."'");
}
$k_point = intval((time()-$be['last'])/3);
$newhealth=$user['health']+(1*$k_point);
$newmana=$user['mana']+(1*$k_point);
if($newhealth > $user['max_health']*2)$newhealth = $user['max_health']*2;
if($newmana > $user['max_mana'])$newmana = $user['max_mana'];
if($k_point >= 1){
mysql_query("UPDATE `user` SET `health` = '$newhealth', `mana` = '$newmana' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("UPDATE `regenerator` SET `last` = '".time()."' WHERE `id_user` = '$user[id]' LIMIT 1");
}
?>