Kensai Posted November 14, 2011 Share Posted November 14, 2011 I'm making a game from scratch. It's pretty sloppy, but the only thing that's giving me trouble is the PvP System. Problems: Battle Variables wont change in the DB after everything had checked out. Attack options wont execute. *I'm sure the Battle Log wont Log the most recent attack, but I'm not particularly worried about that. This is what I want it to do: Require all files Make time variables If Get ID is set (run all checks) if - Player Home Status elseif - enemy level elseif - player level elseif - enemy home status elseif - player in battle elseif - enemy in battle elseif - player location elseif - enemy location else - set battle in DB (Cheack for Player Death, Enemy Death, and Attack Turn) if player health <= 0 echo victory text distribute battle gains in DB unset battle in DB send loser to their village put looser to sleep in their home elseif enemy health <= 0 echo victory text distribute battle gains in DB unset battle in DB send loser to their village put looser to sleep in their home elseif enemy time to attack echo can't attack now echo time limit echo last attack echo Refresh Button elseif player time to attack display pvp interface display time limit echo last attack <?php require 'login_check.php'; require 'global.php'; require 'get_enemy_data.php'; require 'get_user_data.php'; include 'layout_html.php'; include 'menu_check.php'; $time1 = time(); $time = time(); if (isset($_GET['ID'])) { if ($player['home_status'] == 1) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><td class = ''><font color = 'darkred'> You are at home, who are you attacking?</font></td></tr></table>"; } elseif ($enemy['level'] == $player['level']-5) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><td class = ''><font color = 'darkred'> You cant attack a someone 5 levels below you.</font></td></tr></table>"; } elseif ($player['level'] == $enemy['level']-5){ echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><font color = 'darkred'> Don't be a fool, your enemy is 5 levels above you. </font></td></tr></table>"; } elseif ($enemy['home_status'] == 1) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><td class = ''><font color = 'darkred'>This person is in their home, you can not attack them.</font></td></tr></table>"; } elseif ($plalyer['battle'] != $enemy['id']) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><font color = 'darkred'> You are currently in battle with <a href = ./battle.php?&ID=".$enemy['id'].">".$enemy['username']."</a></font></td></tr></table>"; } elseif ($enemy['battle'] != $player['id']) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><font color = 'darkred'> This person is already locked in battle.</font></td></tr></table>"; } elseif ($player['village'] == $enemy['village']) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><font color = 'darkred'>Do not attack your allies!</font></td></tr></table>"; } elseif ($player['user_x'] != $enemy['user_x']) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><font color = 'darkred'>The enemy is not near.</font></td></tr></table>"; } elseif ($player['user_y'] != $enemy['user_y']) { echo "<table class = '' width = '' border = '0' cellpadding = '0' cellspacing = '0'> <tr><font color = 'darkred'>The enemy is not near.</font></td></tr></table>"; } else { mysql_query("UPDATE users SET battle='".$enemy['id']."' WHERE username='".$player['username']."'"); mysql_query("UPDATE users SET battle='".$player['id']."' WHERE username='".$enemy['username']."'"); } } if($enemy['health'] <= 0) { echo "<table width = '540'> <tr algin=center><td align = 'center' class = ''>You are victorious!</td></tr> <tr align=center><td class = ''><font color = 'darkgreen'>".$enemy['username']." has been defeated by your hands.</font></td></tr></table>"; mysql_query("UPDATE users SET pvp_kills='".$player['pvp_kills']."' + 1 WHERE username='".$player['username']."'"); mysql_query("UPDATE users SET battle='0' WHERE username='".$player['username']."'"); mysql_query("UPDATE users SET battle='0' WHERE username='".$enemy['username']."'"); mysql_query("UPDATE users SET user_x='".$enemy2['village_x']."' WHERE username='".$enemy['username']."'"); mysql_query("UPDATE users SET user_y='".$enemy2['village_y']."' WHERE username='".$enemy['username']."'"); mysql_query("UPDATE `villages` SET `village_points`= `village_points` + 1 WHERE `village_name` = '".$player['village']."'") or die(mysql_error()); } elseif($player['health'] == 0) { echo "<table width = '540'> <tr algin=center><td align = 'center' class = ''>You have lost.</td></tr> <tr align=center><td class = ''><font color = 'darkgreen'>".$enemy['username']." has defeated you.</font></td></tr></table>"; mysql_query("UPDATE users SET pvp_kills='".$enemy['pvp_kills']."' + 1 WHERE username='".$enemy['username']."'"); mysql_query("UPDATE users SET battle='0' WHERE username='".$player['username']."'"); mysql_query("UPDATE users SET battle='0' WHERE username='".$enemy['username']."'"); mysql_query("UPDATE users SET user_x='".$player2['village_x']."' WHERE username='".$player['username']."'"); mysql_query("UPDATE users SET user_y='".$player2['village_y']."' WHERE username='".$player['username']."'"); mysql_query("UPDATE `villages` SET `village_points`= `village_points` + 1 WHERE `village_name` = '".$enemy['village']."'") or die(mysql_error()); } elseif($enemy['user_attack_turn'] > 0) { echo "<table> <tr><td><font color = 'darkred'>Your opponent must attack now.</font></td></tr></table>"; $time = time()-60; } elseif($player['user_attacked_last'] <= $time && $player['user_attacked_by'] > 0) { mysql_query("UPDATE `users` SET `user_attack_turn` = 1 WHERE `username` = '".$player['username']."'") or die(mysql_error()); mysql_query("UPDATE `users` SET `user_attack_turn` = 0 WHERE `username` = '".$enemy['username']."'")or die(mysql_error()); if($_GET['atk'] == "hit") { if($_POST['action'] == "Hand to Hand") { if(rand($enemy['luc'],$player['luc']) > rand($enemy['luc'],$player['luc'])) { $attack = (($player['str'] * 1.3) + ($player['dex'] * 0.2)) + ($player['luc'] * rand(0,1.5)); } else { $attack = ($player['str'] * 1.3) + ($player['dex'] * 0.2); } $damage = $attack - $enemy['dur']; if($damage < 0) { $damage = 0; } else { $damage = $attack - $enemy['dur']; } mysql_query("UPDATE `users` SET `health` = `health` - $damage, `user_attack_turn` = 1 WHERE `username = '".$enemy['username']."'") or die(mysql_error()); mysql_query("UPDATE `users` SET `user_attack_turn` = 0, `user_attacked_last` = $time1 WHERE `username`='".$player['username']."'") or die(mysql_error()); echo"<p align=center>".$player['username']." attacked ".$enemy['username']." using Hand to Hand Combat dealing $damage damage. </p>"; $_SESSION['attacklog'].="<p align=center>".$player['username']." attacked ".$enemy['username']." using their fists dealing $damage damage. </p>"; echo "<p align=center><a href='./battle.php?&ID=".$enemy['id']."'>Continue</a></p>"; } elseif($_POST['action'] == "Bad Medicine") { if(rand($enemy['luc'],$player['luc']) > rand($enemy['luc'],$player['luc'])) { $attack = (($player['int'] * 1.3) + ($player['wis'] * 0.2)) + ($player['luc'] * rand(0,1.5)); } else { $attack = ($player['int'] * 1.3) + ($player['wis'] * 0.2); } $damage = $attack - $enemy['wis']; if($damage < 0) { $damage = 0; } else { $damage = $attack - $enemy['wis']; } mysql_query("UPDATE `users` SET `health` = `health` - $damage, `user_attack_turn` = 1 WHERE `username = '".$enemy['username']."'") or die(mysql_error()); mysql_query("UPDATE `users` SET `user_attack_turn` = 0, `user_attacked_last` = $time1 WHERE `username = '".$player['username']."'") or die(mysql_error()); echo"<p align=center>".$player['username']." attacked ".$enemy['username']." using their Bad Medicine dealing $damage damage.</p>"; $_SESSION['attacklog'].="<p align=center>".$player['username']." attacked ".$enemy['username']." using their Bad Medicine dealing $damage damage. </p>"; echo "<p align=center><a href='./battle.php?&ID=".$enemy['id']."'>Continue</a></p>"; } } } else { $width=($player['health']/$player['max_health']*100); $width2=($enemy['health']/$enemy['max_health']*100); echo "<table align = 'center'> <tr><td align = 'center' class = ''>".$player['username']." VS. ".$enemy['username']."</td></tr>"; echo"<tr class=td><td>"; echo"<table align='left' width='268' class='table' cellpadding='0' cellspacing='1'><tr><th class=th>".$player['username']."</th><tr><tr><td align='center'><img src='".$player['avatar']."' width='150' height='150' /></td></tr><tr align=center><td>Level ".$player['level']." - ".$player['rank']."</td></tr><tr><td align=center>Health: ".$player['health']."/".$player['max_health']."<br /><img height=5 src=./images/life_bar.jpg width={$width}></td></tr></table>"; echo"<table align='right' width='268' class='table' cellpadding='0' cellspacing='1'><tr><th class=th>".$enemy['username']."</th><tr><tr><td align='center'><img src='".$enemy['avatar']."' width='150' height='150' /></td></tr><tr align=center><td>Level ".$enemy['level']." - ".$enemy['rank']."</td></tr><tr><td align=center>Health: ".$enemy['health']."/".$enemy['max_health']."<br /><img height=5 src=./images/life_bar.jpg width={$width2}></td></tr></table></td></tr></table><br />"; echo"<form method=post action=./battle.php?&ID=".$enemy['id']."&atk=hit> <table align='center' width='540' class='table' cellpadding='0' cellspacing='1'><tr><th class='th'>Battle Options:</th></tr><tr class=td><td align=center> <input name='action' type='radio' value='Hand to Hand'>Hand to Hand<br /> <input name='action' type='radio' value='Bad Medicine'>Bad Medicine <br />"; echo"<br /><input type='submit' name='".$enemy['id']."' value='Attack' /></td></tr></form></table>"; echo"<br /><p align=center><u><b>Battle Logs:</b></u><br /><Br />".$_SESSION['attacklog']."</p><br /></td></tr></table>"; } if(isset($_SESSION['username'])){ echo '<br /><br /><p style="text-align:center;color:FFFFFF;"><a href="logout.php">Log out</a>'; } echo $footer; ?> I'm still new at PhP, so forgive my sloppiness and poor coding. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.