<?php
$q = mysql_num_rows(mysql_query("SELECT * FROM `regen` WHERE `user`='$uid'"));

if($q == 0){
    
    mysql_query("INSERT INTO `regen` SET `user`='$uid',`time`='".time()."'");
    
}
    
    $be=mysql_fetch_array(mysql_query("SELECT * FROM `regen` WHERE `user` = '$uid' LIMIT 1"));

    $k_point=intval((time()-$be['time'])/3);
    if($k_point>=1){
    if($in_battle==0 and $inpk==0 and $inar==0){
    $newhp=$user['hp']+(5*$k_point);
    if($newhp>$user['hpall']){$newhp=$user['hpall'];}
    $date = time();
    mysql_query("UPDATE `users` SET `hp` = '$newhp' WHERE `id` = '$uid' LIMIT 1");
    mysql_query("UPDATE `regen` SET `time` = '$date' WHERE `user` = '$uid' LIMIT 1");}}
?>