seany123 Posted May 6, 2009 Share Posted May 6, 2009 for some reason the outputs are running but the queries arnt. <?php include("lib.php"); define("PAGENAME", "Battle"); $player = check_user($secret_key, $db); include("templates/private_header3.php"); include("maxexpgain.php"); ?> <html> <head> <title>MafiaKiller</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="all" /> </head> <body alink="#cc9900" vlink="#cc9900" link="#cc9900"> </div> </div> <tr> <div id="left_c"><div class="g_content" style="width: 613; height: 90"><h3> Fight House</h3><div class="g_text"> <?php switch($_GET['act']) { case "attack": if (!$_GET['username']) //No username entered { header("Location: battle.php"); break; } //Otherwise, get player data: $query = $db->execute("select * from `players` where `username`=?", array($_GET['username'])); if ($query->recordcount() == 0) //Player doesn't exist { echo "This player doesn't exist!"; break; } $enemy1 = $query->fetchrow(); //Get player info foreach($enemy1 as $key=>$value) { $enemy->$key = $value; } //HOSPITAL //player in hospital. if ($player->hospital >= 1) { echo "You can't fight anyone while being wounded in hospital."; echo "<br><a href=\"home.php\">Back</a>"; break; } //enemy in hospital. if ($enemy->hospital >= 1) { echo "You can't fight someone when they are in hospital."; echo "<br><a href=\"home.php\">Back</a>"; break; } //PRISON //player in prison. if ($player->prison >= 1) { echo "You can't fight anyone while in prison."; echo "<br><a href=\"home.php\">Back</a>"; break; } //enemy in prison. if ($enemy->prison >= 1) { echo "You can't fight someone when they are in prison."; echo "<br><a href=\"home.php\">Back</a>"; break; } //OTHER VARIABLES //player energy if ($player->energy < $player->energy * 0.25) { echo "You need atleast 25% energy to attack someone."; echo "<br><a href=\"home.php\">Back</a>"; break; } //Player hp if ($player->hp < $player->maxhp * 0.20) { echo "You need atleast 20% hp to attack someone"; echo "<br><a href=\"home.php\">Back</a>"; break; } //enemy hp if ($enemy->hp < $enemy->maxhp * 0.20) { echo "You can't attack someone with less than 20% hp."; echo "<br><a href=\"home.php\">Back</a>"; break; } //Attacking players in another City if($player->city_id != $enemy->city_id) { echo "You cant attack someone in another city."; echo "<br><a href=\"home.php\">Back</a>"; break; } if ($enemy->username == $player->username) { echo "You cannot attack yourself..."; echo "<br><a href=\"home.php\">Back</a>"; break; } //================================================ Variables ======================================================================= //Calculate some variables that will be used $enemy->strdiff = (($enemy->strength - $player->strength) > 0)?($enemy->strength - $player->strength):0; $enemy->vitdiff = (($enemy->defense - $player->defense) > 0)?($enemy->defense - $player->defense):0; $enemy->agidiff = (($enemy->speed - $player->speed) > 0)?($enemy->speed - $player->speed):0; $player->strdiff = (($player->strength - $enemy->strength) > 0)?($player->strength - $enemy->strength):0; $player->vitdiff = (($player->defense - $enemy->defense) > 0)?($player->defense - $enemy->defense):0; $player->agidiff = (($player->speed - $enemy->speed) > 0)?($player->speed - $enemy->speed):0; $totalstr = $enemy->strength + $player->strength; $totalvit = $enemy->defense + $player->defense; $totalagi = $enemy->speed + $player->speed; //Calculate the damage to be dealt by each player (dependent on strength and defense) $enemy->maxdmg = (($enemy->strength * 2) + $enemy->atkbonus['effectiveness']) - ($player->defbonus['effectiveness']); $enemy->maxdmg = $enemy->maxdmg - intval($enemy->maxdmg * ($player->vitdiff / $totalvit)); $enemy->maxdmg = ($enemy->maxdmg <= 2)?2:$enemy->maxdmg; //Set 2 as the minimum damage $enemy->mindmg = (($enemy->maxdmg - 4) < 1)?1:($enemy->maxdmg - 4); //Set a minimum damage range of maxdmg-4 $player->maxdmg = (($player->strength * 2) + $player->atkbonus['effectiveness']) - ($enemy->defbonus['effectiveness']); $player->maxdmg = $player->maxdmg - intval($player->maxdmg * ($enemy->vitdiff / $totalvit)); $player->maxdmg = ($player->maxdmg <= 2)?2:$player->maxdmg; //Set 2 as the minimum damage $player->mindmg = (($player->maxdmg - 4) < 1)?1:($player->maxdmg - 4); //Set a minimum damage range of maxdmg-4 //Calculate battle 'combos' - how many times in a row a player can attack (dependent on speed) $enemy->combo = ceil($enemy->speed / $player->speed); $enemy->combo = ($enemy->combo > 3)?3:$enemy->combo; $player->combo = ceil($player->speed / $enemy->speed); $player->combo = ($player->combo > 3)?3:$player->combo; //Calculate the chance to miss opposing player $enemy->miss = intval(($player->agidiff / $totalagi) * 100); $enemy->miss = ($enemy->miss > 20)?20:$enemy->miss; //Maximum miss chance of 20% (possible to change in admin panel?) $enemy->miss = ($enemy->miss <= 5)?5:$enemy->miss; //Minimum miss chance of 5% $player->miss = intval(($enemy->agidiff / $totalagi) * 100); $player->miss = ($player->miss > 20)?20:$player->miss; //Maximum miss chance of 20% $player->miss = ($player->miss <= 5)?5:$player->miss; //Minimum miss chance of 5% $battlerounds = 30; //Maximum number of rounds/turns in the battle. Changed in admin panel? $output = ""; //Output message //While somebody is still alive, battle! while ($enemy->hp > 0 && $player->hp > 0 && $battlerounds > 0) { $attacking = ($player->speed >= $enemy->speed)?$player:$enemy; $defending = ($player->speed >= $enemy->speed)?$enemy:$player; for($i = 0;$i < $attacking->combo;$i++) { //Chance to miss? $misschance = intval(rand(0, 100)); if ($misschance <= $attacking->miss) { $output .= $attacking->username . " tried to attack " . $defending->username . " but missed!<br />"; } else { $damage = rand($attacking->mindmg, $attacking->maxdmg); //Calculate random damage $defending->hp -= $damage; $output .= ($player->username == $defending->username)?"<font color=\"red\">":"<font color=\"green\">"; $output .= $attacking->username . " attacks " . $defending->username . " for <b>" . $damage . "</b> damage! ("; $output .= ($defending->hp > 0)?$defending->hp . " HP left":"Dead"; $output .= ")<br />"; $output .= "</font>"; //Check if anybody is dead if ($defending->hp <= 0) { $player = ($player->speed >= $enemy->speed)?$attacking:$defending; $enemy = ($player->speed >= $enemy->speed)?$defending:$attacking; break 2; //Break out of the for and while loop, but not the switch structure } } $battlerounds--; if ($battlerounds <= 0) { break 2; //Break out of for and while loop, battle is over! } } for($i = 0;$i < $defending->combo;$i++) { //Chance to miss? $misschance = intval(rand(0, 100)); if ($misschance <= $defending->miss) { $output .= $defending->username . " tried to attack " . $attacking->username . " but missed!<br />"; } else { $damage = rand($defending->mindmg, $defending->maxdmg); //Calculate random damage $attacking->hp -= $damage; $output .= ($player->username == $defending->username)?"<font color=\"green\">":"<font color=\"red\">"; $output .= $defending->username . " attacks " . $attacking->username . " for <b>" . $damage . "</b> damage! ("; $output .= ($attacking->hp > 0)?$attacking->hp . " HP left":"Dead"; $output .= ")<br />"; $output .= "</font>"; //Check if anybody is dead if ($attacking->hp <= 0) { $player = ($player->speed >= $enemy->speed)?$attacking:$defending; $enemy = ($player->speed >= $enemy->speed)?$defending:$attacking; break 2; //Break out of the for and while loop, but not the switch structure } } $battlerounds--; if ($battlerounds <= 0) { break 2; //Break out of for and while loop, battle is over! } } $player = ($player->speed >= $enemy->speed)?$attacking:$defending; $enemy = ($player->speed >= $enemy->speed)?$defending:$attacking; } if ($player->hp <= 0) //ENEMY WINS { //Calculate losses $exploss = (($player->level - $enemy->level) * 100 + 100); if($exploss <= 1) { $exploss = rand(1, 10); } if($exploss >= 10000) { $exploss = 10000; } $moneyloss = intval($player->money * 0.05); $output .= "<br /><u>You were defeated by " . $enemy->username . "!</u><br />"; $output .= "<br />You lost <b>$" . $moneyloss . "</b> ."; $newexp = $exploss + $enemy->exp - $enemy->maxexp; //Update player (the loser) $query = $db->execute("update `players` set `energy`=?, `money`=?, `battle_loss`=?, `battle_total`=? `battle_money`=?, `hp`=? where `id`=?", array($player->energy * 0.25, $player->money - $moneyloss, $player->battle_loss + 1, $player->battle_total + 1, $player->battle_money - $moneyloss, 0, $player->id)); //Update enemy (the winner) if ($exploss + $enemy->exp < $enemy->maxexp) { $query = $db->execute("update `players` set `exp`=?, `money`=?, `battle_won`=?, `battle_total`=?, `battle_total`, `hp`=? where `id`=?", array($enemy->exp + $exploss, $enemy->money + $moneyloss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->hp, $enemy->id)); //Add log message for winner $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); } else if ($enemy->exp + $expgain >= $enemy->maxexp && $enermy->level >= $enemy->maxlevel) { $query = $db->execute("update `players` set `money`=?, `exp`=?, `battle_won`=?, `battle_total`=? `battle_money`=? where `id`=?", array($enemy->money + $moneyloss, $enemy->exp + $exploss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->id )); $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); } else if ($enemy->exp + $expgain >= $enemy->maxexp && $enemy->level < $enemy->maxlevel) { $query = $db->execute("Update `players` set `level`= `level`+?, `maxexp` =?, `exp` =?, `money` = `money` + ?, `hp`=?, `maxhp`=?,`maxenergy`=`maxenergy`+?, `energy`=?, `battle_won`=?, `battle_money`=?, `battle_total`=?, `maxnerve`=? where `id`=?",array(1, $maxexpgain, $newexp, $enemy->money + $moneygain, $enemy->maxhp + 10, $enemy->maxhp + 10, $enemy->maxenergy + 1, $enemy->energy = $enemy->maxenergy, $enemy->battle_won + 1, $enemy->battle_money + $moneyloss, $enemy->battle_total + 1, $enemy->maxnerve + 1, $enemy->id)); //Add log message for winner $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; $logmsg2 = "You gained a level."; addlog($enemy->id, $logmsg, $logmsg2, $db); } } else if ($enemy->hp <= 0) //PLAYER WINS { //Calculate losses $expwin = (($enemy->level - $player->level) * 100 + 100); if($expwin <= 1) { $expwin = rand(1, 10); } if($expwin >= 10000) { $expwin = 10000; } $moneywin = intval($enemy->money * 0.05); $newexp = $expwin + $enemy->exp - $enemy->maxexp; $output .= "<br />You attacked " . $enemy->username . " and won.<br />"; $output .= "<br />You gained <b>" . $expwin . "</b> EXP and <b>$" . $moneywin . "</b>."; //Update Enemy (THE LOSER) $query = $db->execute("update `players` set `money`=?, `battle_loss`=?, `battle_total`=?, `battle_money`=?, `hospital`=?, `hp`=? where `id`=?", array($enemy->money - $moneywin, $enemy->battle_loss + 1, $enemy->battle_total + 1, $enemy->battle_money - $moneywin, 20, 0, $enemy->id)); $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> and lost<br />\nYou lost $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); //Update player (the winner). if ($expwin + $player->exp < $player->maxexp) { $query = $db->execute("update `players` set `exp`=?, `money`=?, `battle_won`=?, `battle_total`=?, `battle_total`, `hp`=? where `id`=?", array($player->exp + $expwin, $player->money + $moneywin, $player->battle_won + 1, $player->battle_total + 1, $player->battle_money + $moneywin, $player->hp, $player->id)); } // MAX LEVEL (NO EXP). if ($player->exp + $expgain >= $player->maxexp && $player->level >= $player->maxlevel) { $query = $db->execute("update `players` set `money`=?, `exp`=?, `battle_won`=?, `battle_total`=? `battle_money`=? where `id`=?", array($player->money + $moneywin, $player->exp + $expwin, $player->battle_won + 1, $player->battle_total + 1, $player->battle_money + $moneywin, $player->id )); } // GAINED A LEVEL. if ($player->exp + $expwin >= $player->maxexp && $player->level < $player->maxlevel) { $newexp = $exploss + $enemy->exp - $enemy->maxexp; $query = $db->execute("Update `players` set `level`= `level`+?, `maxexp` =?, `exp` =?, `money` = `money` + ?, `hp`=?, `maxhp`=?,`maxenergy`=`maxenergy`+?, `energy`=?, `battle_won`=?, `battle_money`=?, `battle_total`=?, `maxnerve`=? where `id`=?",array(1, $maxexpgain, $newexp, $player->money + $moneywin, $player->maxhp + 10, $player->maxhp + 10, $player->maxenergy + 1, $player->energy = $player->maxenergy, $player->battle_won + 1, $player->battle_money + $moneywin, $player->battle_total + 1, $player->maxnerve + 1, $player->id)); } } //NOT EDITED!!!!!!!!!! $player = check_user($secret_key, $db); //Get new stats echo $output; break; case "search": //Check in case somebody entered 0 $_GET['fromlevel'] = ($_GET['fromlevel'] == 0)?"":$_GET['fromlevel']; $_GET['tolevel'] = ($_GET['tolevel'] == 0)?"":$_GET['tolevel']; //Construct query $query = "select `id`, `username`, `hp`, `maxhp`, `level` from `players` where `id`!= ? and "; $query .= ($_GET['username'] != "")?"`username` LIKE ? and ":""; $query .= ($_GET['fromlevel'] != "")?"`level` >= ? and ":""; $query .= ($_GET['tolevel'] != "")?"`level` <= ? and ":""; $query .= ($_GET['alive'] == "1")?"`hp` > 0 ":"`hp` = 0 "; $query .= "limit 20"; //Construct values array for adoDB $values = array(); array_push($values, $player->id); //Make sure battle search doesn't show self if ($_GET['username'] != "") { array_push($values, "%".trim($_GET['username'])."%"); //Add username value for search } //Add level range for search if ($_GET['fromlevel']) { array_push($values, intval($_GET['fromlevel'])); } if ($_GET['tolevel']) { array_push($values, intval($_GET['tolevel'])); } //Display search form again echo "<fieldset>\n"; echo "<legend><b>Search for a player</b></legend>\n"; echo "<form method=\"get\" action=\"battle.php\">\n<input type=\"hidden\" name=\"act\" value=\"search\" />\n"; echo "<table width=\"100%\">\n"; echo "<tr>\n<td width=\"40%\">Username:</td>\n<td width=\"60%\"><input type=\"text\" name=\"username\" value=\"" . stripslashes($_GET['username']) . "\" /></td>\n</tr>\n"; echo "<tr>\n<td width=\"40%\">Level</td>\n<td width=\"60%\"><input type=\"text\" name=\"fromlevel\" size=\"4\" value=\"" . stripslashes($_GET['fromlevel']) . "\" /> to <input type=\"text\" name=\"tolevel\" size=\"4\" value=\"" . stripslashes($_GET['tolevel']) . "\" /></td>\n</tr>\n"; echo "<tr>\n<td width=\"40%\">Status:</td>\n<td width=\"60%\"><select name=\"alive\" size=\"2\">\n<option value=\"1\""; echo ($_GET['alive'] == 1)?" selected=\"selected\"":""; echo ">Alive</option>\n<option value=\"0\""; echo ($_GET['alive'] == 0)?" selected=\"selected\"":""; echo ">Dead</option>\n</select></td>\n</tr>\n"; echo "<tr><td></td><td><br /><input type=\"submit\" value=\"Search!\" /></td></tr>\n"; echo "</table>\n"; echo "</form>\n</fieldset>\n"; echo "<br /><br />"; echo "<table width=\"100%\">\n"; echo "<tr><th width=\"50%\">Username</th><th width=\"20%\">Level</th><th width=\"30%\">Battle</a></th></tr>\n"; $query = $db->execute($query, $values); //Search! if ($query->recordcount() > 0) //Check if any players were found { $bool = 1; while ($result = $query->fetchrow()) { echo "<tr class=\"row" . $bool . "\">\n"; echo "<td width=\"50%\"><a href=\"profile.php?username=" . $result['username'] . "\">" . $result['username'] . "</a></td>\n"; echo "<td width=\"20%\">" . $result['level'] . "</td>\n"; echo "<td width=\"30%\"><a href=\"battle.php?act=attack&username=" . $result['username'] . "\">Attack</a></td>\n"; echo "</tr>\n"; $bool = ($bool==1)?2:1; } } else //Display error message { echo "<tr>\n"; echo "<td colspan=\"3\">No players found. Try changing your search criteria.</td>\n"; echo "</tr>\n"; } echo "</table>\n"; break; default: //The default battle page, giving choice of whether to search for players or to target one echo "<fieldset>\n"; echo "<legend><b>Search for a player</b></legend>\n"; echo "<form method=\"get\" action=\"battle.php\">\n<input type=\"hidden\" name=\"act\" value=\"search\" />\n"; echo "<table width=\"100%\">\n"; echo "<tr>\n<td width=\"40%\">Username:</td>\n<td width=\"60%\"><input type=\"text\" name=\"username\" /></td>\n</tr>\n"; echo "<tr>\n<td width=\"40%\">Level</td>\n<td width=\"60%\"><input type=\"text\" name=\"fromlevel\" size=\"4\" /> to <input type=\"text\" name=\"tolevel\" size=\"4\" /></td>\n</tr>\n"; echo "<tr>\n<td width=\"40%\">Status:</td>\n<td width=\"60%\"><select name=\"alive\" size=\"2\">\n<option value=\"1\" selected=\"selected\">Alive</option>\n<option value=\"0\">Dead</option>\n</select></td>\n</tr>\n"; echo "<tr><td></td><td><br /><input type=\"submit\" value=\"Search!\" /></td></tr>\n"; echo "</table>\n"; echo "</form>\n</fieldset>\n"; echo "<br /><br />\n"; echo "<fieldset>\n"; echo "<legend><b>Attack a player</b></legend>\n"; echo "<form method=\"get\" action=\"battle.php?act=attack\">\n<input type=\"hidden\" name=\"act\" value=\"attack\" />\n"; echo "Username: <input type=\"text\" name=\"username\" /><br />\n"; echo "<input type=\"submit\" value=\"Battle!\" />\n"; echo "</form>\n"; break; } ?> i know the above code could be hard to understand... but the queries are near the bottom of the script. (i just thought it important to post the whole thing. Quote Link to comment Share on other sites More sharing options...
kickstart Posted May 6, 2009 Share Posted May 6, 2009 for some reason the outputs are running but the queries arnt. What is output? Is it going into the branch of the switch statement to do the queries? All the best Keith Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 I don't think SQL has a != syntax. Use <> Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 6, 2009 Author Share Posted May 6, 2009 for some reason the outputs are running but the queries arnt. What is output? Is it going into the branch of the switch statement to do the queries? All the best Keith for example... if ($exploss + $enemy->exp < $enemy->maxexp) { $query = $db->execute("update `players` set `exp`=?, `money`=?, `battle_won`=?, `battle_total`=?, `battle_total`, `hp`=? where `id`=?", array($enemy->exp + $exploss, $enemy->money + $moneyloss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->hp, $enemy->id)); //Add log message for winner $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); } else if ($enemy->exp + $expgain >= $enemy->maxexp && $enermy->level >= $enemy->maxlevel) { $query = $db->execute("update `players` set `money`=?, `exp`=?, `battle_won`=?, `battle_total`=? `battle_money`=? where `id`=?", array($enemy->money + $moneyloss, $enemy->exp + $exploss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->id )); $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); } else if ($enemy->exp + $expgain >= $enemy->maxexp && $enemy->level < $enemy->maxlevel) { $query = $db->execute("Update `players` set `level`= `level`+?, `maxexp` =?, `exp` =?, `money` = `money` + ?, `hp`=?, `maxhp`=?,`maxenergy`=`maxenergy`+?, `energy`=?, `battle_won`=?, `battle_money`=?, `battle_total`=?, `maxnerve`=? where `id`=?",array(1, $maxexpgain, $newexp, $enemy->money + $moneygain, $enemy->maxhp + 10, $enemy->maxhp + 10, $enemy->maxenergy + 1, $enemy->energy = $enemy->maxenergy, $enemy->battle_won + 1, $enemy->battle_money + $moneyloss, $enemy->battle_total + 1, $enemy->maxnerve + 1, $enemy->id)); //Add log message for winner $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; $logmsg2 = "You gained a level."; addlog($enemy->id, $logmsg, $logmsg2, $db); } } else if ($enemy->hp <= 0) //PLAYER WINS { //Calculate losses $expwin = (($enemy->level - $player->level) * 100 + 100); if($expwin <= 1) { $expwin = rand(1, 10); } if($expwin >= 10000) { $expwin = 10000; } $moneywin = intval($enemy->money * 0.05); $newexp = $expwin + $enemy->exp - $enemy->maxexp; $output .= "<br />You attacked " . $enemy->username . " and won.<br />"; $output .= "<br />You gained <b>" . $expwin . "</b> EXP and <b>$" . $moneywin . "</b>."; in the code above it will display the $output .= "<br />You attacked " . $enemy->username . " and won.<br />"; $output .= "<br />You gained <b>" . $expwin . "</b> EXP and <b>$" . $moneywin . "</b>."; however it will run the queries. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Okay...? So which part of the query do you want us to look at? Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 6, 2009 Author Share Posted May 6, 2009 i really don't think there is anything wrong with the queries... i have also ran this script through a debugger and it came through without errors. i just have no idea why the queries arn't running. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 That's such a long script. Can you trim it down or post up to the part where the SQLs aren't running? Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 6, 2009 Author Share Posted May 6, 2009 <?php switch($_GET['act']) { //While somebody is still alive, battle! while ($enemy->hp > 0 && $player->hp > 0 && $battlerounds > 0) { $attacking = ($player->speed >= $enemy->speed)?$player:$enemy; $defending = ($player->speed >= $enemy->speed)?$enemy:$player; for($i = 0;$i < $attacking->combo;$i++) { //Chance to miss? $misschance = intval(rand(0, 100)); if ($misschance <= $attacking->miss) { $output .= $attacking->username . " tried to attack " . $defending->username . " but missed!<br />"; } else { $damage = rand($attacking->mindmg, $attacking->maxdmg); //Calculate random damage $defending->hp -= $damage; $output .= ($player->username == $defending->username)?"<font color=\"red\">":"<font color=\"green\">"; $output .= $attacking->username . " attacks " . $defending->username . " for <b>" . $damage . "</b> damage! ("; $output .= ($defending->hp > 0)?$defending->hp . " HP left":"Dead"; $output .= ")<br />"; $output .= "</font>"; //Check if anybody is dead if ($defending->hp <= 0) { $player = ($player->speed >= $enemy->speed)?$attacking:$defending; $enemy = ($player->speed >= $enemy->speed)?$defending:$attacking; break 2; //Break out of the for and while loop, but not the switch structure } } $battlerounds--; if ($battlerounds <= 0) { break 2; //Break out of for and while loop, battle is over! } } for($i = 0;$i < $defending->combo;$i++) { //Chance to miss? $misschance = intval(rand(0, 100)); if ($misschance <= $defending->miss) { $output .= $defending->username . " tried to attack " . $attacking->username . " but missed!<br />"; } else { $damage = rand($defending->mindmg, $defending->maxdmg); //Calculate random damage $attacking->hp -= $damage; $output .= ($player->username == $defending->username)?"<font color=\"green\">":"<font color=\"red\">"; $output .= $defending->username . " attacks " . $attacking->username . " for <b>" . $damage . "</b> damage! ("; $output .= ($attacking->hp > 0)?$attacking->hp . " HP left":"Dead"; $output .= ")<br />"; $output .= "</font>"; //Check if anybody is dead if ($attacking->hp <= 0) { $player = ($player->speed >= $enemy->speed)?$attacking:$defending; $enemy = ($player->speed >= $enemy->speed)?$defending:$attacking; break 2; //Break out of the for and while loop, but not the switch structure } } $battlerounds--; if ($battlerounds <= 0) { break 2; //Break out of for and while loop, battle is over! } } $player = ($player->speed >= $enemy->speed)?$attacking:$defending; $enemy = ($player->speed >= $enemy->speed)?$defending:$attacking; } if ($player->hp <= 0) //ENEMY WINS { //Calculate losses $exploss = (($player->level - $enemy->level) * 100 + 100); if($exploss <= 1) { $exploss = rand(1, 10); } if($exploss >= 10000) { $exploss = 10000; } $moneyloss = intval($player->money * 0.05); $output .= "<br /><u>You were defeated by " . $enemy->username . "!</u><br />"; $output .= "<br />You lost <b>$" . $moneyloss . "</b> ."; $newexp = $exploss + $enemy->exp - $enemy->maxexp; //Update player (the loser) $query = $db->execute("update `players` set `energy`=?, `money`=?, `battle_loss`=?, `battle_total`=? `battle_money`=?, `hp`=? where `id`=?", array($player->energy * 0.25, $player->money - $moneyloss, $player->battle_loss + 1, $player->battle_total + 1, $player->battle_money - $moneyloss, 0, $player->id)); //Update enemy (the winner) if ($exploss + $enemy->exp < $enemy->maxexp) { // NOT WORKING QUERY $query = $db->execute("update `players` set `exp`=?, `money`=?, `battle_won`=?, `battle_total`=?, `battle_total`, `hp`=? where `id`=?", array($enemy->exp + $exploss, $enemy->money + $moneyloss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->hp, $enemy->id)); //Add log message for winner $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); } else if ($enemy->exp + $expgain >= $enemy->maxexp && $enermy->level >= $enemy->maxlevel) { // NOT WORKING QUERY $query = $db->execute("update `players` set `money`=?, `exp`=?, `battle_won`=?, `battle_total`=? `battle_money`=? where `id`=?", array($enemy->money + $moneyloss, $enemy->exp + $exploss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->id )); $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); } else if ($enemy->exp + $expgain >= $enemy->maxexp && $enemy->level < $enemy->maxlevel) { // NOT WORKING QUERY $query = $db->execute("Update `players` set `level`= `level`+?, `maxexp` =?, `exp` =?, `money` = `money` + ?, `hp`=?, `maxhp`=?,`maxenergy`=`maxenergy`+?, `energy`=?, `battle_won`=?, `battle_money`=?, `battle_total`=?, `maxnerve`=? where `id`=?",array(1, $maxexpgain, $newexp, $enemy->money + $moneygain, $enemy->maxhp + 10, $enemy->maxhp + 10, $enemy->maxenergy + 1, $enemy->energy = $enemy->maxenergy, $enemy->battle_won + 1, $enemy->battle_money + $moneyloss, $enemy->battle_total + 1, $enemy->maxnerve + 1, $enemy->id)); //Add log message for winner $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> but you won!<br />\nYou gained " . $exploss . " EXP and $" . $moneyloss .""; $logmsg2 = "You gained a level."; addlog($enemy->id, $logmsg, $logmsg2, $db); } } else if ($enemy->hp <= 0) //PLAYER WINS { //Calculate losses $expwin = (($enemy->level - $player->level) * 100 + 100); if($expwin <= 1) { $expwin = rand(1, 10); } if($expwin >= 10000) { $expwin = 10000; } $moneywin = intval($enemy->money * 0.05); $newexp = $expwin + $enemy->exp - $enemy->maxexp; $output .= "<br />You attacked " . $enemy->username . " and won.<br />"; $output .= "<br />You gained <b>" . $expwin . "</b> EXP and <b>$" . $moneywin . "</b>."; //Update Enemy (THE LOSER) // NOT WORKING QUERY $query = $db->execute("update `players` set `money`=?, `battle_loss`=?, `battle_total`=?, `battle_money`=?, `hospital`=?, `hp`=? where `id`=?", array($enemy->money - $moneywin, $enemy->battle_loss + 1, $enemy->battle_total + 1, $enemy->battle_money - $moneywin, 20, 0, $enemy->id)); $logmsg = "You were attacked by <a href=\"profile.php?id=" . $player->username . "\">" . $player->username . "</a> and lost<br />\nYou lost $" . $moneyloss .""; addlog($enemy->id, $logmsg, $db); //Update player (the winner). if ($expwin + $player->exp < $player->maxexp) { // NOT WORKING QUERY $query = $db->execute("update `players` set `exp`=?, `money`=?, `battle_won`=?, `battle_total`=?, `battle_total`, `hp`=? where `id`=?", array($player->exp + $expwin, $player->money + $moneywin, $player->battle_won + 1, $player->battle_total + 1, $player->battle_money + $moneywin, $player->hp, $player->id)); } // MAX LEVEL (NO EXP). if ($player->exp + $expgain >= $player->maxexp && $player->level >= $player->maxlevel) { // NOT WORKING QUERY $query = $db->execute("update `players` set `money`=?, `exp`=?, `battle_won`=?, `battle_total`=? `battle_money`=? where `id`=?", array($player->money + $moneywin, $player->exp + $expwin, $player->battle_won + 1, $player->battle_total + 1, $player->battle_money + $moneywin, $player->id )); } // GAINED A LEVEL. if ($player->exp + $expwin >= $player->maxexp && $player->level < $player->maxlevel) { $newexp = $exploss + $enemy->exp - $enemy->maxexp; // NOT WORKING QUERY $query = $db->execute("Update `players` set `level`= `level`+?, `maxexp` =?, `exp` =?, `money` = `money` + ?, `hp`=?, `maxhp`=?,`maxenergy`=`maxenergy`+?, `energy`=?, `battle_won`=?, `battle_money`=?, `battle_total`=?, `maxnerve`=? where `id`=?",array(1, $maxexpgain, $newexp, $player->money + $moneywin, $player->maxhp + 10, $player->maxhp + 10, $player->maxenergy + 1, $player->energy = $player->maxenergy, $player->battle_won + 1, $player->battle_money + $moneywin, $player->battle_total + 1, $player->maxnerve + 1, $player->id)); } } $player = check_user($secret_key, $db); //Get new stats echo $output; break; } ?> im trimmed as much as i thought i could... i also made all the queries so they have no indents and have commented above them all "// NOT WORKING QUERY". Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Can you tell if the IF statements run? If so, which ones? I rather not go testing for them all. Also, does your DB class have a debug method anywhere that prints out any MySQL errors? Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 6, 2009 Author Share Posted May 6, 2009 i have just realised for one of the IF statements im getting this error: Warning: Division by zero on line 145 line 145,146,147,148: $enemy->combo = ceil($enemy->speed / $player->speed); $enemy->combo = ($enemy->combo > 3)?3:$enemy->combo; $player->combo = ceil($player->speed / $enemy->speed); $player->combo = ($player->combo > 3)?3:$player->combo; and then Fatal error: Maximum execution time of 30 seconds exceeded... Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 So $enemy->speed is 0? Well there you go! Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 6, 2009 Author Share Posted May 6, 2009 So $enemy->speed is 0? Well there you go! i saw the error there but it was a error i caused due to trying to fix the issue of the queries not running. i have no set speed back to a value higher than 0... but still the queries arnt running... not any of the IF statements Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Inside each if statement, before any queries, can you put an echo to see if it gets executed? Thanks! Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 6, 2009 Author Share Posted May 6, 2009 thats what u i thought the outputs would do. i did what you asked... ALL the echos did display however the database was never updated with the query. Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 11, 2009 Author Share Posted May 11, 2009 im back from my weekend away... im still having the same issues as before.. with the queries not running Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 After this, set up your DB class to output MySQL errors. You have one in almost every line. That's a little ridiculous. First SQL - $query = $db->execute("update `players` set `energy`=?, `money`=?, `battle_loss`=?, `battle_total`=? `battle_money`=?, `hp`=? where `id`=?", array($player->energy * 0.25, $player->money - $moneyloss, $player->battle_loss + 1, $player->battle_total + 1, $player->battle_money - $moneyloss, 0, $player->id)); Missing comma after battle_total. Second SQL - $query = $db->execute("update `players` set `exp`=?, `money`=?, `battle_won`=?, `battle_total`=?, `battle_total`, `hp`=? where `id`=?", array($enemy->exp + $exploss, $enemy->money + $moneyloss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->hp, $enemy->id)); Missing =? after battle_total. Third SQL - $query = $db->execute("update `players` set `money`=?, `exp`=?, `battle_won`=?, `battle_total`=? `battle_money`=? where `id`=?", array($enemy->money + $moneyloss, $enemy->exp + $exploss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->id )); Same as #1. Fourth SQL - $query = $db->execute("Update `players` set `level`= `level`+?, `maxexp` =?, `exp` =?, `money` = `money` + ?, `hp`=?, `maxhp`=?,`maxenergy`=`maxenergy`+?, `energy`=?, `battle_won`=?, `battle_money`=?, `battle_total`=?, `maxnerve`=? where `id`=?",array(1, $maxexpgain, $newexp, $enemy->money + $moneygain, $enemy->maxhp + 10, $enemy->maxhp + 10, $enemy->maxenergy + 1, $enemy->energy = $enemy->maxenergy, $enemy->battle_won + 1, $enemy->battle_money + $moneyloss, $enemy->battle_total + 1, $enemy->maxnerve + 1, $enemy->id)); In the array, what are you trying to do with $enemy->energy = $enemy->maxenergy? As for your other SQLs, check for similar errors. I'm not going through them all. Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 11, 2009 Author Share Posted May 11, 2009 After this, set up your DB class to output MySQL errors. You have one in almost every line. That's a little ridiculous. First SQL - $query = $db->execute("update `players` set `energy`=?, `money`=?, `battle_loss`=?, `battle_total`=? `battle_money`=?, `hp`=? where `id`=?", array($player->energy * 0.25, $player->money - $moneyloss, $player->battle_loss + 1, $player->battle_total + 1, $player->battle_money - $moneyloss, 0, $player->id)); Missing comma after battle_total. Second SQL - $query = $db->execute("update `players` set `exp`=?, `money`=?, `battle_won`=?, `battle_total`=?, `battle_total`, `hp`=? where `id`=?", array($enemy->exp + $exploss, $enemy->money + $moneyloss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->hp, $enemy->id)); Missing =? after battle_total. Third SQL - $query = $db->execute("update `players` set `money`=?, `exp`=?, `battle_won`=?, `battle_total`=? `battle_money`=? where `id`=?", array($enemy->money + $moneyloss, $enemy->exp + $exploss, $enemy->battle_won + 1, $enemy->battle_total + 1, $enemy->battle_money + $moneyloss, $enemy->id )); Same as #1. Fourth SQL - $query = $db->execute("Update `players` set `level`= `level`+?, `maxexp` =?, `exp` =?, `money` = `money` + ?, `hp`=?, `maxhp`=?,`maxenergy`=`maxenergy`+?, `energy`=?, `battle_won`=?, `battle_money`=?, `battle_total`=?, `maxnerve`=? where `id`=?",array(1, $maxexpgain, $newexp, $enemy->money + $moneygain, $enemy->maxhp + 10, $enemy->maxhp + 10, $enemy->maxenergy + 1, $enemy->energy = $enemy->maxenergy, $enemy->battle_won + 1, $enemy->battle_money + $moneyloss, $enemy->battle_total + 1, $enemy->maxnerve + 1, $enemy->id)); In the array, what are you trying to do with $enemy->energy = $enemy->maxenergy? As for your other SQLs, check for similar errors. I'm not going through them all. ah i see the errors... i gave all the queries a good looking through and fixed any errors i found. $enemy->energy = $enemy->maxenergy this is supposed to set $enemy->energy to be the same value as $enemy->maxenergy. another quick thing i wanna check, i have this in my query.... `level`= `level`+?, is this wrong? and the array part for that i have just put 1 Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 I don't know if that's wrong. What's considered wrong? Also, I'm not sure how SQL will take it if you just insert $enemy->energy = $enemy->maxenergy into it. Can't you do that outside of the query? Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 11, 2009 Author Share Posted May 11, 2009 I don't know if that's wrong. What's considered wrong? Also, I'm not sure how SQL will take it if you just insert $enemy->energy = $enemy->maxenergy into it. Can't you do that outside of the query? wrong meaning coded incorrectly and not able to work. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 wrong meaning coded incorrectly and not able to work. Don't know about those either. All I know is it can be syntactically correct pending the execute method does the right thing. 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.