Jump to content

help please


seany123

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

<?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".

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.