Jump to content

[SOLVED] Help with reducing health


Xyphon

Recommended Posts

    <?PHP
include('top.php');
include('Connect.php');
$ID = $_COOKIE['UserID'];
$ID = mysql_real_escape_string($ID);
$Battle_Result= mysql_query("SELECT * FROM Battle_Information WHERE ID='$ID'");
$Battle_Rows= mysql_fetch_array($Battle_Result);
$Battle_Result2= mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Battle_Rows2= mysql_fetch_array($Battle_Result2);

$Taijutsu= $Battle_Rows2['Taijutsu'];
$Taijutsu = mysql_real_escape_string($Taijutsu);
$Ninjutsu= $Battle_Rows2['Ninjutsu'];
$Ninjutsu = mysql_real_escape_string($Ninjutsu);
$Genjutsu= $Battle_Rows2['Genjutsu'];
$Genjutsu = mysql_real_escape_string($Genjutsu);
$Bloodline1= $Battle_Rows2['Bloodline'];
$Bloodline1 = mysql_real_escape_string($Bloodline1);
$Bloodline2= $Battle_Rows2['Bloodline2'];
$Bloodline2 = mysql_real_escape_string($Bloodline2);
$Bloodline3= $Battle_Rows2['Bloodline3'];
$Bloodline3 = mysql_real_escape_string($Bloodline3);
$Bloodline4= $Battle_Rows2['Bloodline4'];
$Bloodline4 = mysql_real_escape_string($Bloodline4);
$Bloodline5= $Battle_Rows2['Bloodline5'];
$Bloodline5 = mysql_real_escape_string($Bloodline5);
$Weapon= $Battle_Rows2['Weapon'];
$Weapon = mysql_real_escape_string($Weapon);
$Taijutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Taijutsu'");
$Taijutsu_Rows= mysql_fetch_array($Taijutsu_Result);
$Ninjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Ninjutsu'");
$Ninjutsu_Rows= mysql_fetch_array($Ninjutsu_Result);
$Genjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Genjutsu'");
$Genjutsu_Rows= mysql_fetch_array($Genjutsu_Result);
$Bloodline1_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline1'");
$Bloodline1_Rows= mysql_fetch_array($Bloodline1_Result);
$Bloodline2_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline2'");
$Bloodline2_Rows= mysql_fetch_array($Bloodline2_Result);
$Bloodline3_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline3'");
$Bloodline3_Rows= mysql_fetch_array($Bloodline3_Result);
$Bloodline4_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline4'");
$Bloodline4_Rows= mysql_fetch_array($Bloodline4_Result);
$Bloodline5_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline5'");
$Bloodline5_Rows= mysql_fetch_array($Bloodline5_Result);
$Weapon_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Weapon'");
$Weapon_Rows= mysql_fetch_array($Weapon_Result);
$Power= $Battle_Rows2['Power'];
$Power = mysql_real_escape_string($Power);
if(!isset($ID))
{
    echo "Sorry, you must be logged in to view this page";
    include('bottom.php');
    exit;
}
$Submit = $_GET['Type'];
if(!$Submit)
{
    if($Battle_Rows['Enemy_Name']=="")
    {
        echo "Sorry, you aren't in a battle..";
    }
    else
    {
        echo "
        <html>
        <center>
        <table border='3' bordercolor='red' width='550' height='300'><td><center>
        <table border='0' width='550'><td><center>" . $Battle_Rows['Enemy_Name'] . "<br>
        HP: " . $Battle_Rows['Enemy_HP'] . "/" . $Battle_Rows['Enemy_Max_HP'] . "            Chakra: " . $Battle_Rows['Enemy_Chakra'] . "/" . $Battle_Rows['Enemy_Max_Chakra'] . "</table><br><br><br><br>
        <table border='0' width='550'><tr><td><center>Taijutsu:<br><a href='battle.php?Type=Taijutsu'>" . $Battle_Rows2['Taijutsu'] . "</a></td>            <td>Ninjutsu:<br><a href='battle.php?Type=Ninjutsu'>" . $Battle_Rows2['Ninjutsu'] . "</a></td>            <td>Genjutsu:<br><a href='battle.php?Type=Genjutsu'>" . $Battle_Rows2['Genjutsu']. "</a></td>            <td>Bloodline:<br><a href='battle.php?Type=Bloodline1'>" . $Battle_Rows2['Bloodline'] . "</a></td>            <td>Weapon:<br><a href='battle.php?Type=Weapon'>" . $Battle_Rows2['Weapon'] . "</a></table><br><table border='0' width='550'>
        <td><center>" . $Battle_Rows2['Username'] . "<br>
        HP: " . $Battle_Rows2['HP'] . "/" . $Battle_Rows2['Max_HP'] . "            Chakra: " . $Battle_Rows2['Chakra'] . "/" . $Battle_Rows2['Max_Chakra'] . "</table></table>";
    }
}
else
{

    if($Submit=='Taijutsu')
    {
$Enemy_HP= $BattleRows['Enemy_HP'];
        $Damage1= $Taijutsu_Rows['Jutsu_Power'];
        $Taijutsupower= $Battle_Rows2['$Taijutsu_Power'];
        $Taijutsupower= mysql_real_escape_string($Taijutsupower);
        $Damage2= round(($Damage1 + $Taijutsupower) + $Power);
        $Damage3= round($Damage2 / 5);
        $Enemy_HP= round($Enemy_HP - $Damage3);
        echo "<html>
        <center>
        <table border='3' bordercolor='red' width='550' height='300'><td><center>
        <table border='0' width='550'><td><center>" . $Battle_Rows['Enemy_Name'] . "<br>
        HP: " . $E_HP . "/" . $Battle_Rows['Enemy_Max_HP'] . "            Chakra: " . $Battle_Rows['Enemy_Chakra'] . "/" . $Battle_Rows['Enemy_Max_Chakra'] . "</table><br><br><br><br>
        <table border='0' width='550'><tr><td><center>Taijutsu:<br><a href='battle.php?Type=Taijutsu'>" . $Battle_Rows2['Taijutsu'] . "</a></td>            <td>Ninjutsu:<br><a href='battle.php?Type=Ninjutsu'>" . $Battle_Rows2['Ninjutsu'] . "</a></td>            <td>Genjutsu:<br><a href='battle.php?Type=Genjutsu'>" . $Battle_Rows2['Genjutsu']. "</a></td>            <td>Bloodline:<br><a href='battle.php?Type=Bloodline1'>" . $Battle_Rows2['Bloodline'] . "</a></td>            <td>Weapon:<br><a href='battle.php?Type=Weapon'>" . $Battle_Rows2['Weapon'] . "</a></table><br><table border='0' width='550'>
        <td><center>" . $Battle_Rows2['Username'] . "<br>
        HP: " . $Battle_Rows2['HP'] . "/" . $Battle_Rows2['Max_HP'] . "            Chakra: " . $Battle_Rows2['Chakra'] . "/" . $Battle_Rows2['Max_Chakra'] . "</table><br>You did $Damage3 damage!</table>";
    }
    elseif($Submit=='Ninjutsu')
    {
        echo "Ninjutsu!";
    }
    elseif($Submit=='Genjutsu')
    {
        echo "Genjutsu!";
    elseif($Submit=='Bloodline1')
    {
        echo "Bloodline1!";
    }
    else
    {
        echo "Weapon!";
    }
}
?>

 

that is so far of my battle code. The problem is that well after the health bar goes down to 72 or whatever, I'll click the attack button again and it'll stay at 72. I think this is because it refreshes after I click it and then depletes again. Please help me on this..

Link to comment
Share on other sites

Oops, that was an attempt to fix it heres the real one

 

<?PHP
include('top.php');
include('Connect.php');
$ID = $_COOKIE['UserID'];
$ID = mysql_real_escape_string($ID);
$Battle_Result= mysql_query("SELECT * FROM Battle_Information WHERE ID='$ID'");
$Battle_Rows= mysql_fetch_array($Battle_Result);
$Battle_Result2= mysql_query("SELECT * FROM users WHERE ID='$ID'");
$Battle_Rows2= mysql_fetch_array($Battle_Result2);
$Enemy_HP= $Battle_Rows['Enemy_HP'];
$Taijutsu= $Battle_Rows2['Taijutsu'];
$Taijutsu = mysql_real_escape_string($Taijutsu);
$Ninjutsu= $Battle_Rows2['Ninjutsu'];
$Ninjutsu = mysql_real_escape_string($Ninjutsu);
$Genjutsu= $Battle_Rows2['Genjutsu'];
$Genjutsu = mysql_real_escape_string($Genjutsu);
$Bloodline1= $Battle_Rows2['Bloodline'];
$Bloodline1 = mysql_real_escape_string($Bloodline1);
$Bloodline2= $Battle_Rows2['Bloodline2'];
$Bloodline2 = mysql_real_escape_string($Bloodline2);
$Bloodline3= $Battle_Rows2['Bloodline3'];
$Bloodline3 = mysql_real_escape_string($Bloodline3);
$Bloodline4= $Battle_Rows2['Bloodline4'];
$Bloodline4 = mysql_real_escape_string($Bloodline4);
$Bloodline5= $Battle_Rows2['Bloodline5'];
$Bloodline5 = mysql_real_escape_string($Bloodline5);
$Weapon= $Battle_Rows2['Weapon'];
$Weapon = mysql_real_escape_string($Weapon);
$Taijutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Taijutsu'");
$Taijutsu_Rows= mysql_fetch_array($Taijutsu_Result);
$Ninjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Ninjutsu'");
$Ninjutsu_Rows= mysql_fetch_array($Ninjutsu_Result);
$Genjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Genjutsu'");
$Genjutsu_Rows= mysql_fetch_array($Genjutsu_Result);
$Bloodline1_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline1'");
$Bloodline1_Rows= mysql_fetch_array($Bloodline1_Result);
$Bloodline2_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline2'");
$Bloodline2_Rows= mysql_fetch_array($Bloodline2_Result);
$Bloodline3_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline3'");
$Bloodline3_Rows= mysql_fetch_array($Bloodline3_Result);
$Bloodline4_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline4'");
$Bloodline4_Rows= mysql_fetch_array($Bloodline4_Result);
$Bloodline5_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline5'");
$Bloodline5_Rows= mysql_fetch_array($Bloodline5_Result);
$Weapon_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Weapon'");
$Weapon_Rows= mysql_fetch_array($Weapon_Result);
$Power= $Battle_Rows2['Power'];
$Power = mysql_real_escape_string($Power);
if(!isset($ID))
{
    echo "Sorry, you must be logged in to view this page";
    include('bottom.php');
    exit;
}
$Submit = $_GET['Type'];
if(!$Submit)
{
    if($Battle_Rows['Enemy_Name']=="")
    {
        echo "Sorry, you aren't in a battle..";
    }
    else
    {
        echo "
        <html>
        <center>
        <table border='3' bordercolor='red' width='550' height='300'><td><center>
        <table border='0' width='550'><td><center>" . $Battle_Rows['Enemy_Name'] . "<br>
        HP: " . $Battle_Rows['Enemy_HP'] . "/" . $Battle_Rows['Enemy_Max_HP'] . "            Chakra: " . $Battle_Rows['Enemy_Chakra'] . "/" . $Battle_Rows['Enemy_Max_Chakra'] . "</table><br><br><br><br>
        <table border='0' width='550'><tr><td><center>Taijutsu:<br><a href='battle.php?Type=Taijutsu'>" . $Battle_Rows2['Taijutsu'] . "</a></td>            <td>Ninjutsu:<br><a href='battle.php?Type=Ninjutsu'>" . $Battle_Rows2['Ninjutsu'] . "</a></td>            <td>Genjutsu:<br><a href='battle.php?Type=Genjutsu'>" . $Battle_Rows2['Genjutsu']. "</a></td>            <td>Bloodline:<br><a href='battle.php?Type=Bloodline1'>" . $Battle_Rows2['Bloodline'] . "</a></td>            <td>Weapon:<br><a href='battle.php?Type=Weapon'>" . $Battle_Rows2['Weapon'] . "</a></table><br><table border='0' width='550'>
        <td><center>" . $Battle_Rows2['Username'] . "<br>
        HP: " . $Battle_Rows2['HP'] . "/" . $Battle_Rows2['Max_HP'] . "            Chakra: " . $Battle_Rows2['Chakra'] . "/" . $Battle_Rows2['Max_Chakra'] . "</table></table>";
    }
}
else
{

    if($Submit=='Taijutsu')
    {

        $Damage1= $Taijutsu_Rows['Jutsu_Power'];
        $Taijutsupower= $Battle_Rows2['$Taijutsu_Power'];
        $Taijutsupower= mysql_real_escape_string($Taijutsupower);
        $Damage2= round(($Damage1 + $Taijutsupower) + $Power);
        $Damage3= round($Damage2 / 5);
        $Enemy_HP= round($Enemy_HP - $Damage3);
        echo "<html>
        <center>
        <table border='3' bordercolor='red' width='550' height='300'><td><center>
        <table border='0' width='550'><td><center>" . $Battle_Rows['Enemy_Name'] . "<br>
        HP: " . $Enemy_HP . "/" . $Battle_Rows['Enemy_Max_HP'] . "            Chakra: " . $Battle_Rows['Enemy_Chakra'] . "/" . $Battle_Rows['Enemy_Max_Chakra'] . "</table><br><br><br><br>
        <table border='0' width='550'><tr><td><center>Taijutsu:<br><a href='battle.php?Type=Taijutsu'>" . $Battle_Rows2['Taijutsu'] . "</a></td>            <td>Ninjutsu:<br><a href='battle.php?Type=Ninjutsu'>" . $Battle_Rows2['Ninjutsu'] . "</a></td>            <td>Genjutsu:<br><a href='battle.php?Type=Genjutsu'>" . $Battle_Rows2['Genjutsu']. "</a></td>            <td>Bloodline:<br><a href='battle.php?Type=Bloodline1'>" . $Battle_Rows2['Bloodline'] . "</a></td>            <td>Weapon:<br><a href='battle.php?Type=Weapon'>" . $Battle_Rows2['Weapon'] . "</a></table><br><table border='0' width='550'>
        <td><center>" . $Battle_Rows2['Username'] . "<br>
        HP: " . $Battle_Rows2['HP'] . "/" . $Battle_Rows2['Max_HP'] . "            Chakra: " . $Battle_Rows2['Chakra'] . "/" . $Battle_Rows2['Max_Chakra'] . "</table><br>You did $Damage3 damage!</table>";
    }
    elseif($Submit=='Ninjutsu')
    {
        echo "Ninjutsu!";
    }
    elseif($Submit=='Genjutsu')
    {
        echo "Genjutsu!";
    }
    elseif($Submit=='Bloodline1')
    {
        echo "Bloodline1!";
    }
    else
    {
        echo "Weapon!";
    }
}
?>

Link to comment
Share on other sites

reducing health would be a simple UPDATE

 

however before I get into that.. I want to point something else out that you might not be aware of..

$Taijutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Taijutsu'");
$Taijutsu_Rows= mysql_fetch_array($Taijutsu_Result);
$Ninjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Ninjutsu'");
$Ninjutsu_Rows= mysql_fetch_array($Ninjutsu_Result);
$Genjutsu_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Genjutsu'");
$Genjutsu_Rows= mysql_fetch_array($Genjutsu_Result);
$Bloodline1_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline1'");
$Bloodline1_Rows= mysql_fetch_array($Bloodline1_Result);
$Bloodline2_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline2'");
$Bloodline2_Rows= mysql_fetch_array($Bloodline2_Result);
$Bloodline3_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline3'");
$Bloodline3_Rows= mysql_fetch_array($Bloodline3_Result);
$Bloodline4_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline4'");
$Bloodline4_Rows= mysql_fetch_array($Bloodline4_Result);
$Bloodline5_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$Bloodline5'");
$Bloodline5_Rows= mysql_fetch_array($Bloodline5_Result);

 

could be shortened dramatically.. and save you a ton of performance most likely

 

$result = mysql_query("SELECT * FROM `jutsus` WHERE `Jutsu_Name` IN ('$Taijutsu,$Ninjutsu,$Genjutsu,$Bloodline1,$Bloodline2,$Bloodline3,$Bloodline4,$Bloodline5')");
while ($a = mysql_fetch_array($result)) {
$rows[] = $a;
}

 

NOW for that update

 

get rid of this line:

        $Taijutsupower= mysql_real_escape_string($Taijutsupower);

 

 

$Battle_Rows2['$Taijutsu_Power'];

 

that will look for the literal string '$Taijutsu_Power'

 

not whatever is contained within $Taijutsu_Power

 

if this is really a variable remove the single quotes, if you meant NOT to put the $ in there, remove it

 

 

and as for the update.. I can't figure out the uhm.. field in the MAIn database for the hp of the user.. so you'd hafta figure out that lil factor.. but your script NEEDS to update the database to tell the database the enemy's new HP value

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.