Вход Регистрация
Файл: public_html/pvp.php
Строк: 474
<?php

// Для работы скрипта делаем следующие запросы в БД
// ALTER TABLE `users` ADD `pvp_rating` INT(11) NOT NULL DEFAULT '0'

$basepath dirname (__FILE__);

require_once 
$basepath "/system/common.php";

require_once 
$basepath "/system/functions.php";

require_once 
$basepath "/system/user.php";
// require login
if (!isset ($user)) { header("location: /"); exit; }


// конфигурации

// имя колонки "золото" в таблице "users"
$_table_users_column_gold     "g";
// имя колонки "серебро" в таблице "users"
$_table_users_column_silver "s";


// название мероприятия
$_event_name "PvP Хаотичный Бой";
// задержка между битвами
$_event_delay60 2// 5 минут, чтобы игроки видели результат предыдущего сражения
// цена создания мероприятия  (в золоте)
$_event_price 10;
// время ожидания меорприятия (мсек)
$_event_wait 60 5// 5 минут
// время мероприятия
$_event_time 60 5// 10 минут
// награда победившей команде
$_event_win_team_reward 1500;
// награда победившей команде (убитым)
$_event_win_team_reward_dead 400;
// задержка в атаке
$_event_attack_delay 2;
// максимальное кол-во героев в мероприятии
$_event_max_size 24;
// сколько рейтинга даем победившей команде
$_event_win_team_rating=1;
// рейтинг подебившей команде игрокам, которые были убиты в ходе сражения
$_event_win_team_rating_dead=0.2;

$title $_event_name;
require_once 
$basepath "/system/h.php";

?>

<style>
body
{

font-size:12px;
}
a
{
color:#F0D790;
}
.btn {
background:#404349;
color:#ffffff;
font-size:10px;
display:inline-block;
padding:2px 5px 2px 5px;
border:1px solid #101010;
border-radius:1px;
margin:1px 1px 1px 0px;
}
a.btn {
text-decoration:none;
}
ul.list,
ul.menu {
list-style:none;
padding:0px;
margin:0px;
}

ul.list li,
ul.menu li {
background:url('/images/body.png') #202020;
border-bottom:1px dotted #505050;
}
ul.menu li {
padding:5px 5px;
}
ul.list li:last-child,
ul.menu li:last-child {
border-bottom:none;
}
ul.list li:hover {
background:#303030;
}
ul.list li a {
display:inline-block;
padding:5px 5px;
text-decoration:none;
}
.pvp_fon
    {background: #000 url('https://fs.elem.mobi//img/back-orcs2.jpg') top center no-repeat;  }

</style>
<?
        
if(isset($_SESSION['soz'])){
echo 
smiles($_SESSION['soz']);
unset(
$_SESSION['soz']);
}
?>

<?php
if (mysql_num_rows (mysql_query ("SELECT * FROM `pvp_event`"))!=0) {
$e mysql_fetch_array (mysql_query ("SELECT * FROM `pvp_event` ORDER BY `id` DESC LIMIT 1"));

$team0 mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='0')"));
$team0_live mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='0') AND (`hp`!='0')"));
$team0_dead mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='0') AND (`hp`='0')"));
$team1 mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='1')"));
$team1_live mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='1') AND (`hp`!='0')"));
$team1_dead mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='1') AND (`hp`='0')"));

// старт мероприятия
if ($e['start']==and $e['time']<=time ()) {
mysql_query ("UPDATE `pvp_event` SET `start`='1',`time`='" . (time () + $_event_time). "' WHERE (`id`='$e[id]')");
                    
header ("location: /pvp.php");
exit;
}

if (
$e['start']==and ($team0+$team1)==0) {
mysql_query ("DELETE FROM `pvp_event` WHERE (`id`='$e[id]')");
header ("location: /pvp.php");
exit;
}
// если бой начался и не набралось достаточное кол-во человек, т.е в мероприятии 1 человек..
if ($e['start']==and $e['end']==and ($team0+$team1)==1) {
mysql_query ("DELETE FROM `pvp_event` WHERE (`id`='$e[id]')");
mysql_query ("DELETE FROM `pvp_memb`  WHERE (`id_event`='$e[id]')");
header ("location: /pvp.php");
exit;
}


// если заканчивается время мероприятия
if ($e['start']==and $e['end']==and $e['time']<=time () or $e['start']==and $e['end']==and $team0==$team0_dead or $e['start']==and $e['end']==and $team1==$team1_dead) {
if (
$team0_live>$team1_live) { // если по окончанию времени у синей тимы осталось больше живих
$q mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='0')");
while (
$_m mysql_fetch_array ($q)) {
if (
$_m['hp']!=0) { // если герой не умер в процессе битвы
//// логирование /////////
mysql_query("INSERT INTO `log_g` SET `user`='".$user['id']."',`g_do`='".$user['g']."',`g_posle`='".($user['g']+$_event_win_team_reward)."', `text`='награда pvp', `time`='".time()."'");
//////////////////////////
mysql_query ("UPDATE `users` SET `$_table_users_column_gold`=`$_table_users_column_gold`+$_event_win_team_reward WHERE (`id`='$_m[id_user]')");
mysql_query ("UPDATE `users` SET `pvp_rating`=`pvp_rating`+$_event_win_team_rating WHERE (`id`='$_m[id_user]')");

}
else {
//// логирование /////////
mysql_query("INSERT INTO `log_g` SET `user`='".$user['id']."',`g_do`='".$user['g']."',`g_posle`='".($user['g']+$_event_win_team_reward_dead)."', `text`='награда pvp', `time`='".time()."'");
//////////////////////////
mysql_query ("UPDATE `users` SET `$_table_users_column_gold`=`$_table_users_column_gold`+$_event_win_team_reward_dead WHERE (`id`='$_m[id_user]')");
mysql_query ("UPDATE `users` SET `pvp_rating`=`pvp_rating`+$_event_win_team_rating_dead WHERE (`id`='$_m[id_user]')");
}
}
}
elseif (
$team1_live>$team0_live) { // если по окончанию времени у красной команды больше живих
$q mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`team`='1')");
while (
$_m mysql_fetch_array ($q)) {
if (
$_m['hp']!=0) { // если герой не умер в процессе битвы
//// логирование /////////
mysql_query("INSERT INTO `log_g` SET `user`='".$user['id']."',`g_do`='".$user['g']."',`g_posle`='".($user['g']+$_event_win_team_reward)."', `text`='награда pvp', `time`='".time()."'");
//////////////////////////
mysql_query ("UPDATE `users` SET `$_table_users_column_gold`=`$_table_users_column_gold`+$_event_win_team_reward WHERE (`id`='$_m[id_user]')");
mysql_query ("UPDATE `users` SET `pvp_rating`=`pvp_rating`+$_event_win_team_rating WHERE (`id`='$_m[id_user]')");
}
else {
//// логирование /////////
mysql_query("INSERT INTO `log_g` SET `user`='".$user['id']."',`g_do`='".$user['g']."',`g_posle`='".($user['g']+$_event_win_team_reward_dead)."', `text`='награда pvp', `time`='".time()."'");
//////////////////////////
mysql_query ("UPDATE `users` SET `$_table_users_column_gold`=`$_table_users_column_gold`+$_event_win_team_reward_dead WHERE (`id`='$_m[id_user]')");
mysql_query ("UPDATE `users` SET `pvp_rating`=`pvp_rating`+$_event_win_team_rating_dead WHERE (`id`='$_m[id_user]')");
}
}
}
else { 
// ничья, никому нихуя не достанится или достанится, но чутка)
}

mysql_query ("UPDATE `pvp_event` SET `end`='1' WHERE (`id`='$e[id]')");
                    
header ("location: /pvp.php");
exit;
}





// test

// если битва началась и мы в ней учавствуем
$q mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`id_user`='$user[id]')");
if (
$e['start'] == and $e['end']==and mysql_num_rows ($q)!=0) {
$m mysql_fetch_array ($q);
// если хп на нуле, мы убиты
if ($m['hp']==0) {

?>
<div class="pvp_fon">
<div style='text-align:center;'>
<span style='color:#909090;'>Вы убиты.</span><br/>
<br/>
<span style='color:#9090c0;font-size:16px;font-weight:bold;'><?=$team0_live?></span> vs <span style='color:#c09090;font-size:16px;font-weight:bold;'><?=$team1_live?></span>
<br/>
<br/>

Битва закончится через <?=_time (ceil (($e['time']-time ())))?><br>
<a href='/pvp.php' class='btn22'>Обновить</a>
</div><div>
<?php
$q 
mysql_query ("SELECT * FROM `pvp_log` WHERE (`id_event`='$e[id]') ORDER BY `id` DESC LIMIT 10");
while (
$log mysql_fetch_array ($q)) {
?>

<?=$log['text']?><br/>

<?php
}
?>
</li>
<?php
}
else {
// смена противника (таргетинг)
$_GET['target'] = isset ($_GET['target']) ? intval ($_GET['target']) : 0;
if (
$_GET['target']!=0) {
$_opponent mysql_fetch_array (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id`='$_GET[target]')"));
if (
$_opponent['team']!=$m['target'] || $_opponent['hp']!=0) {
mysql_query ("UPDATE `pvp_memb` SET `last_opponent`='$_GET[target]' WHERE (`id`='$m[id]')");


}
header ("location: /pvp.php");
}



?>
<div class="pvp_fon">
<?=_time (ceil (($e['time']-time ())))?><br>
<span style='float:left;'><img src='/images/icon/health.png' alt=''/> <?=$m['hp']?></span>

<div class="the">
<center>
<?=($m['team']==0?"Синяя":"Красная")?> команда (ваша):
</center>
<br/>
<?php
$q 
mysql_query ("SELECT `users`.`login`, `pvp_memb`.* FROM `pvp_memb` LEFT JOIN `users` ON `users`.`id`=`pvp_memb`.`id_user` WHERE (`pvp_memb`.`id_event`='$e[id]') AND (`pvp_memb`.`team`='$m[team]') AND (`pvp_memb`.`id_user`!='$m[id_user]')");
if (
mysql_num_rows ($q)!=0) {
while (
$_m mysql_fetch_array ($q)) {
?>
<?=$_m
['login']?>
<?=
($_m['hp']==" (Убит)":"<img src='/images/icon/health.png' alt=''/> " $_m['hp'])?>
<hr>
<?php
}
}
else {
?>
Выберайте противника!
<?
}
?>
<br/>

<font color="lime">
<?=($m['team']==0?"Красная":"Синяя")?> команда:
</font><br/>
<?php
$q 
mysql_query ("SELECT `users`.`login`, `pvp_memb`.* FROM `pvp_memb` LEFT JOIN `users` ON `users`.`id`=`pvp_memb`.`id_user` WHERE (`pvp_memb`.`id_event`='$e[id]') AND (`pvp_memb`.`team`!='$m[team]')");
if (
mysql_num_rows ($q)!=0) {
while (
$_m mysql_fetch_array ($q)) {
if (
$_m['hp']==0) {
?>
<?=$_m
['login']?></font color="red"> (Убит)</font>
<?php
}
else {
if (
$_m['id']==$m['last_opponent']) {
?>
<b><?=$_m['login']?></b>
<?php
}
else {
?>
<a href='/pvp.php?target=<?=$_m['id']?>'><u><?=$_m['login']?></u></a>
<?php
}
?>

<img src='/images/icon/health.png' alt=''/> <?=$_m['hp']?>
<?php
}
?>
<br/>
<?php
}

}
else {
?>
Удачи!
<?
}
?>

</div>
<div style='text-align:center;'>
<?php
if ($m['last_opponent']==0) {
?>
<div class="content">
Выберите противника!<br/>
Нажмите на имя игрока противоположной команды.

<?php
                
}
                else {
                                
                                                           
                                
$opponent mysql_fetch_array (mysql_query ("SELECT `users`.`login`, `users`.`str`,`users`.`vit`,`users`.`agi`,`users`.`def`,`pvp_memb`.`hp` FROM `pvp_memb` LEFT JOIN `users` ON `users`.`id`=`pvp_memb`.`id_user` WHERE (`pvp_memb`.`id`='$m[last_opponent]')"));
                                
                                
                                if (
$opponent['hp']==0) {
                                
?>
                Ваш противник убит!<br>

<?php
                                
}
                                else {

                                if ((
time () - $m['last_attack'])<$_event_attack_delay) {
?>

            До удара <?=ceil($_event_attack_delay - (time () - $m['last_attack']))?> сек
                <br/>
                <br><a href='/pvp.php' class='btn22'>Обновить</a><br>
<?
        
if(isset($_SESSION['att'])){
echo 
smiles($_SESSION['att']);
unset(
$_SESSION['att']);
}
?>
<?php                                
                                
}
                                else {
                        
                                                
$_GET['attack'] = isset ($_GET['attack']) ? intval ($_GET['attack']) : 0;
                                                if (
$_GET['attack']==1) {
                                                                

                                                                
// current damage
                                                                
$dmg 0;
                                                        
                                                                

                                                                
// ablitities
                                                                // 0 - don't active, 1 - active
                                                                
$ability_1 0;
                                                                
$ability_2 0;
                                                                
$ability_3 0;
                                                                
$ability_4 0;
                                                                
                                                                        
                                                                        if (
$user['ability_1']!=0) {
                                                                        
                                                                                
$ability_1_b 20 + ($user['ability_1']*5) - 5;
                                                                                
$ability_1_c 5     + ($user['ability_1']*3) - 3;

                                                                                if (
mt_rand(0100) <= $ability_1_c)
                                                                                        
$ability_1 1;
                                                                        
                                                                        }
                                                                        
                                                                        

                                                                        if (
$user['ability_2']!=0) {
                                                                        
                                                                                
$ability_2_b 20 + ($user['ability_2']*5) - 5;
                                                                                
$ability_2_c 5     + ($user['ability_2']*3) - 3;

                                                                                if (
mt_rand(0100) <= $ability_2_c)
                                                                                        
$ability_2 1;
                                                                        
                                                                        }

                                                                        

                                                                        if (
$user['ability_3']!=0) {
                                                                        
                                                                                
$ability_2_b   + ($user['ability_3']*3) - 3;
                                                                                
$ability_2_c   + ($user['ability_3']*2) - 2;
                                                                                
$ability_2_c_c 20+ ($user['ability_3']*5) - 5;


                                                                                if (
mt_rand(0100) <= $ability_3_c)
                                                                                        
$ability_3 1;
                                                                        
                                                                        }
                                                                        


                                                                        if (
$user['ability_4']!=0) {
                                                                        
                                                                                
$ability_2_b 20 + ($user['ability_4']*2) - 2;
                                                                                
$ability_2_c 5     + ($user['ability_4']*5) - 5;

                                                                                if (
mt_rand(0100) <= $ability_4_c)
                                                                                        
$ability_4 1;
                                                                        
                                                                        }
                                                                        
                                                                        
                                                                        

                                                                        
$dmg += ceil (rand(($user['str']/6), ($user['str']/4)));
                                                                        
                                                                        if (
$ability_1==1) {
                                                                                
$dmg += ceil (($dmg 100) * $ability_1_b);
                                                                        }

                                                                        
$dmg -= ceil (rand(($opponent['def']/12), ($opponent['def']/7)));        
                                                                        
                                                                        if (
$dmg 0)
                                                                                
$dmg 0;

                                                                        
$crit $ability_1==1?((rand (1,2)*($user['agi']/100)+$ability_3_c_c)-(rand (1,2)*($opponent['agi']/100))):((rand (1,2)*($user['agi']/100))-(rand (1,2)*($opponent['agi']/100)));
                                                                        
                                                                        if (
mt_rand(0100) <= $crit) {   
                                                                        
                                                                                
$dmg *= 2;

                                                                                if(
$ability_3 == 1) {                             
                                                                                        
$dmg += ceil (($dmg/100)*$ability_3_b);                                
                                                                                }    
                                                                        
                                                                        }

                                                                        
$dodge = ((rand (1,2)*($opponent['agi']/100))-(rand (1,2)*($user['agi']/100)));
                                                        
                                                                        if(
mt_rand(0100) <= $dodge)
                                                                                
$dmg 0;
                                                                
                                                                        
                                                                        
                                                                        if (
$dmg>$opponent['hp']) {
                                                                                        
$dmg $opponent['hp'];
                                                                        
                                                                                        
mysql_query ("INSERT INTO `pvp_log` (`id_event`,`text`) VALUES ('$e[id]','$user[login] <font color='red'>убил</font> $opponent[login]')");

                                                                        }


                                                        
mysql_query ("UPDATE `pvp_memb` SET `hp`=`hp`-$dmg WHERE (`id`='$m[last_opponent]')");
                                                                
mysql_query ("UPDATE `pvp_memb` SET `last_attack`=" time () . " WHERE (`id`='$m[id]')");
        
 
$_SESSION['att'] = '<center> <font color="lime"><img src="/images/icon/ok.png"> Вы нанесли '.$opponent[login].' '.$dmg.' урона!</font></center>';                                                  ?>
<?
if(isset($_SESSION['at'])){
echo 
smiles($_SESSION['at']);
unset(
$_SESSION['at']);
}
?>

                                                <div style='text-align:center;'>
                                                <?php
                                                
                                                                
if ($dmg==0) {
                                                
                                                                                
mysql_query ("INSERT INTO `pvp_log` (`id_event`,`text`) VALUES ('$e[id]','$user[login] попытался ударить $opponent[login]')");

                                                
?>
                                                            
                                                <?php                
        

}                                                                                                                        else {

                                                                            
mysql_query ("INSERT INTO `pvp_log` (`id_event`,`text`) VALUES ('$e[id]','$user[login] <font color='red'>нанес $opponent[login]</font> $dmg урона')");


 
$_SESSION['at'] = '<center> <font color="red"><img src="/images/icon/error.png"> Вы промахнулись по '.$opponent[login].'!</font></center>';     


    
header('location:?');    


                                        
?>
                                                                
                                                <?php
                                                        
}
                                                
?>
                                                
                                                <?php
                                                                
if ($ability_1!=|| $ability_2!=|| $ability_3!=$ability_4!=0) {
?>
                                                        <div class='separator'></div>

<?php
                                                                        
if($ability_1==1) {
                                                
?>
                                                        <img src='/images/ability/1.<?=$user['ability_1_quality']?>.png' style='width:25px;height:25px;' alt=''/>
                                                <?php
                                                                        
}
                                                                        if(
$ability_2==1) {
                                                
?>
                                                        <img src='/images/ability/2.<?=$user['ability_2_quality']?>.png' style='width:25px;height:25px;' alt=''/>
                                                <?php
                                                                        
}
                                                                        if(
$ability_3==1) {
                                                
?>
                                                        <img src='/images/ability/3.<?=$user['ability_3_quality']?>.png' style='width:25px;height:25px;' alt=''/>
                                                <?php
                                                                        
}
                                                                        if(
$ability_4==1) {
                                                
?>
                                                        <img src='/images/ability/4.<?=$user['ability_4_quality']?>.png' style='width:25px;height:25px;' alt=''/>
                                                <?php
                                                                        
}
                                                                }
                                                
?>
                                                </div>

                                                <?php
                                                                
                                                
}
                                                
?><br>
                <a class="btn22" href='/pvp.php?attack=1' class='btn22'>Атаковать</a><br>
<?php


                                
}
                
                                }
                }
                
                
?>    
                
<?php
                                $q 
mysql_query ("SELECT * FROM `pvp_log` WHERE (`id_event`='$e[id]') ORDER BY `id` DESC LIMIT 10");
                                while (
$log mysql_fetch_array ($q)) {
?></center>
<font color="orange">
<?=$log['text']?>
</font>
<br/>

<?php
                                
}
?>
                </li>

<?php                        }
                
                }
                else {

?>


                <div class='pvp_fon'><div style='text-align:center;'><?=$_event_name?></div>
                <div style='text-align:center;'>

<?php                        
                                
// если битва уже закончена и нет другой..
                                
if ($e['start']==and $e['end']==1) {

                                                if ((
time() - $e['time'])>$_event_delay) {
                                
                                                
$_GET['create'] = isset ($_GET['create']) ? intval ($_GET['create']) : 0;
                                                if (
$_GET['create']==1) {
                                                                                
mysql_query ("INSERT INTO `pvp_event` (`start`,`end`, `time`) VALUES ('0', '0', '" . (time ()+$_event_wait). "')");
                                                                                
header ("location: /pvp.php");
                                                }

?>
                                <a href='/pvp.php?create=1' class='btn22'>Создать битву</a>
                </div>
                <li style='font-size:10px;'>
                                В битве учавствуют максимум 24 человека поделенные на 2 команды.
                                Победившая команда и все выжившые герои получают по <img src='/images/icon/gold.png' alt=''/> <?=$_event_win_team_reward?> золота, убитые герои получают <img src='/images/icon/gold.png' alt=''/> <?=$_event_win_team_reward_dead?> золота, проигравшая команда не получает ничего.<br/>


<?php

                                                
}
                                                else {
                                                
?>
                            <h3>Результаты предыдущей битвы</h3>
<?php                                                

                                        
if ($team0_live>$team1_live) { // если по окончанию времени у синей тимы осталось больше живих
?>
                            Победила <span style='color:#9090c0;font-size:16px;'>синяя команда</span>
                            <br/>
<?php
                                                $q 
mysql_query ("SELECT `users`.`login`, `pvp_memb`.* FROM `pvp_memb` LEFT JOIN `users` ON `users`.`id`=`pvp_memb`.`id_user` WHERE (`pvp_memb`.`id_event`='$e[id]') AND (`pvp_memb`.`team`='0')");
                                                while (
$_m mysql_fetch_array ($q)) {
                            
$reward $_m['hp']!=$_event_win_team_reward $_event_win_team_reward_dead;
                            
$rating $_m['hp']!=$_event_win_team_rating $_event_win_team_rating_dead;

?>
                            <a href='/user/<?=$_m['id_user']?>'><u><?=$_m['login']?></u></a> <img src='/images/icon/gold.png' alt=''/> <?=$reward?> (<font color='lime'>+<?=$rating?></font> к рейтингу)
                            <br/>
<?php
                                                
}
                                }
                                elseif (
$team1_live>$team0_live) { // если по окончанию времени у красной команды больше живих

?>
                            Победила <span style='color:#c09090;font-size:16px;'>красная команда</span>
                            <br/>                
<?php
                                                $q 
mysql_query ("SELECT `users`.`login`, `pvp_memb`.* FROM `pvp_memb` LEFT JOIN `users` ON `users`.`id`=`pvp_memb`.`id_user` WHERE (`pvp_memb`.`id_event`='$e[id]') AND (`pvp_memb`.`team`='1')");
                                                while (
$_m mysql_fetch_array ($q)) {
                            
$reward $_m['hp']!=$_event_win_team_reward $_event_win_team_reward_dead;
                            
$rating $_m['hp']!=$_event_win_team_rating $_event_win_team_rating_dead;
?>
                            <a href='/user/<?=$_m['id_user']?>'><u><?=$_m['login']?></u></a> <img src='/images/icon/gold.png' alt=''/> <?=$reward?> (<font color='lime'>+<?=$rating?></font> к рейтингу)
                            <br/>
<?php
                                                
}
                                                
                                }
                                else {
?>
                            <span style='color:#909090;font-size:16px;'>Ничья</span>
                            <br/>
<?php
                                
}

?>

                <br/>
                <font color='#8C0740'>Следующая битва через</font> <font color='lime'><?=_time ($_event_delay - (time() - $e['time']))?></font>
                <br/>
                <a class="btn22" href='/pvp.php' class='btn22'>Обновить</a>

<?php
                                                
                                                
                                                
}

                                }
                                else {    

                            

                                
// если битва началась, но мы в ней не учавствуем
                                
if ($e['start']==1) {
?>
                                Битва в самом разгаре..<br/>
                                <?=$team0_live?> vs <?=$team1_live?>
                                <br/>
                                Битва закончится через <?=_time (ceil (($e['time']-time ())))?>
<?php                                                
                                                
                                
}
                                else {
                                                if (
mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`id_user`='$user[id]')"))!=0) {
                                                
                                                
                                                
$_GET['exit'] = isset ($_GET['exit']) ? intval ($_GET['exit']) : 0;
                                                if (
$_GET['exit']==1) {
                                                                
                                                                
mysql_query ("DELETE FROM `pvp_memb` WHERE (`id_event`='$e[id]') AND (`id_user`='$user[id]')");
                                                                
                                                                
header ("location: /pvp.php");
                                                                exit;
                                                }
?>

                                <span style='color:#9090c0;font-size:16px;font-weight:bold;'><?=$team0?></span> <img src='/images/icon/vs.png'> <span style='color:#c09090;font-size:16px;font-weight:bold;'><?=$team1?></span>
                                <br/>
                                <font color='#A64949'>Битва начнется через</font> <font color='lime'><?=_time (ceil (($e['time']-time ())))?></font><br/>
                                <br/>
                                <a class="btn22" href='/pvp.php?exit=1' class='btn22'>Выйти</a>
                                <a class="btn22" href='/pvp.php?' class='btn22'>Обновить</a>
<?php                                                
                                                
}
                                                else {
                                                                
// такс..))
                                                                
$_GET['register'] = isset ($_GET['register']) ? intval ($_GET['register']) : 0;
                                                                if (
$_GET['register']==1) {
                                                                                if (
$user[$_table_users_column_gold]<$_event_price) {
                                                                                                
// this handle error with gold (не хватает золота)
                                                                                
}
                                                                                elseif (
mysql_num_rows (mysql_query ("SELECT * FROM `pvp_memb` WHERE (`id_event`='$e[id]')"))>=24) {
                                                                                                
// свободного места нет..
                                                                                
}
                                                                                else {
                                                                                
                                                                                                
// в максимальном размере лучше выбирать четное число, которое бы делилось на 2, сам понимаешь))
                                                                                                
$team = -1// выбираем тиму
                                                                                                // teambalance
                                                                                                
if ($team0<=$team1 and $team0 <ceil ($_event_max_size/2)) // fix
                                                                                                                
$team 0;
                                                                                                
                                                                                                
                                                                                                
                                                                                                if (
$team==-1) { // если команда еще не выбрана, т.е выбрано -1, если команда выбрана, то не выбираем ни чего, оставляем всё как есть..
                                                                                                                
if ($team1<=$team0 and $team1<ceil ($_event_max_size/2)) // fix
                                                                                                                                
$team 1;
                                                                                                }
                                                                                              
//// логирование /////////
                                                                                              
mysql_query("INSERT INTO `log_g` SET `user`='".$user['id']."',`g_do`='".$user['g']."',`g_posle`='".($user['g']-$_event_price)."', `text`='заявка на pvp', `time`='".time()."'");
                                                                                              
//////////////////////////
                                                                                                
mysql_query ("UPDATE `users` SET `$_table_users_column_gold`=`$_table_users_column_gold`-$_event_price WHERE (`id`='$user[id]')");
                                                                                                
mysql_query ("INSERT INTO `pvp_memb` (`id_event`,`id_user`,`team`, `hp`) VALUES ('$e[id]', '$user[id]', '$team', '" ceil($user['vit']*2) . "')");
    
 
$_SESSION['soz'] = '<center> <font color="lime"><img src="/images/icon/ok.png"> Вы подали заявку на бой, с балланса снято 10 <img src="/images/icon/gold.png"></font></center>';                                                                                                                                                                                         header ("location: /pvp.php");
                                                                                }
                                                                }
                                                                

?>
                                <span style='color:#9090c0;font-size:16px;font-weight:bold;'><?=$team0?></span> vs <span style='color:#c09090;font-size:16px;font-weight:bold;'><?=$team1?></span>
                                <br/>
                                Битва начнется через <?=_time (ceil (($e['time']-time ())))?>
                                <br/>
                                <br/>
                                <a class="btn22" href='/pvp.php?register=1' class='btn22'>Подать заявку <img src='/images/icon/gold.png' alt=''/> <?=$_event_price?> золота</a>
                                            
                                
<?php
                                            
}
                            }


                                }

?>
                
<?php

                
}
                


}
else {
                
$_GET['create'] = isset ($_GET['create']) ? intval ($_GET['create']) : 0;
                if (
$_GET['create']==1) {
                                if (
$user[$_table_users_column_gold]<$_event_price) {
                                                
// this handle error with gold
                                
}
                                else {
                                                
mysql_query ("INSERT INTO `pvp_event` (`start`,`end`, `time`) VALUES ('0', '0', '" . (time ()+$_event_wait). "')");
                                                
header ("location: /pvp.php");
                                }
                }

?>
                
                                <a href='/pvp.php?create=1' class='btn22'>Создать битву</a>
            
                                В битве учавствуют максимум 24 человека поделенные на 2 команды.
                                Победившая команда и все выжившые герои получают по <img src='/images/icon/gold.png' alt=''/> <?=$_event_win_team_reward?> золота, убитые герои получают <img src='/images/icon/gold.png' alt=''/> <?=$_event_win_team_reward_dead?> золота, проигравшая команда не получает ничего.<br/>
                

<?php
}

?>



<?php


require_once $basepath "/system/f.php";
Онлайн: 1
Реклама