<?php

		$location = "$location_user";
$query_loc = $pdo->query("select count, count_now, habar_ot, habar_do from location where location_name = '$location' limit 1");
$row_loc = $query_loc->fetch();
$count_loc = filter($row_loc['count']);
$count_now_loc = filter($row_loc['count_now']);
		$new_count_now_loc = ($count_now_loc + $attack_user);
		if ($new_count_now_loc >= $count_loc) {
$pdo->exec("update location set count_now = 0 where location_name = '$location' limit 1");
$query_h = $pdo->query("select id, habar, activ from users where location = '$location' and last_active > NOW() - (60*5) and hp != 0 and ban != 1 ORDER BY `activ` DESC limit 1");
$row_h = $query_h->fetch();
$id_user_hab = abs(intval($row_h['id']));
$habar = abs(intval($row_h['habar']));
$activ = intval($row_h['activ']);
		  $activ = ($activ/2);
$habar_ot= filter($row_loc['habar_ot']);
$habar_do= filter($row_loc['habar_do']);
		  $habar_up = rand($habar_ot,$habar_do);
		  $habar = ($habar + $habar_up);
$pdo->exec("insert into log (`time`, `user_id`, `sboitie`, `thing` , `yron`, `location`) values (NOW(), '$id_user_hab', 4 , '$habar_up', '0', '$location')");
$pdo->exec("update users set habar = '$habar', activ = '$activ' where id = '$id_user_hab' limit 1");
		}
		else {
$pdo->exec("update location set count_now = '$new_count_now_loc' where location_name = '$location'");
		}
?>