Xyphon Posted January 19, 2009 Share Posted January 19, 2009 This is part of my script where it seems to go wrong: <?PHP if($Submit=='Taijutsu') { $EnemyRand= rand(1, 4); $GenjutsuE= $Battle_Rows['Enemy_Genjutsu']; $GenjutsuE= mysql_real_escape_string($GenjutsuE); $NinjutsuE= $Battle_Rows['Enemy_Ninjutsu']; $NinjutsuE= mysql_real_escape_string($NinjutsuE); $TaijutsuE= $Battle_Rows['Enemy_Taijutsu']; $TaijutsuE= mysql_real_escape_string($TaijutsuE); $WeaponE= $Battle_Rows['Enemy_Weapon']; $WeaponE= mysql_real_escape_string($WeaponE); $Taijutsu_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$TaijutsuE'"); $Taijutsu_Enemy_Rows= mysql_fetch_array($Taijutsu_Enemy_Result); $Ninjutsu_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$NinjutsuE'"); $Ninjutsu_Enemy_Rows= mysql_fetch_array($Ninjutsu_Enemy_Result); $Genjutsu_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$GenjutsuE'"); $Genjutsu_Enemy_Rows= mysql_fetch_array($Genjutsu_Enemy_Result); $Weapon_Enemy_Result= mysql_query("SELECT * FROM jutsus WHERE Jutsu_Name='$WeaponE'"); $Weapon_Enemy_Rows= mysql_fetch_array($Weapon_Enemy_Result); if($EnemyRand=="4") { $Enemy_Move= $NinjutsuE; $EnemyDamage1= $Ninjutsu_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Ninjutsupower= $Battle_Rows['Ninjutsu_Power']; $Ninjutsupower= mysql_real_escape_string($Ninjutsupower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Ninjutsupower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $Defense= $Ninjutsu_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); $EnemyChakra= $Battle_Rows['Enemy_Chakra']; $EnemyChakra= mysql_real_escape_string($EnemyChakra); $ChakraUsedE= $Ninjutsu_Enemy_Rows['Chakra_Used']; $ChakraUsedE= mysql_real_escape_string($ChakraUsedE); $PastEnemyChakra= $EnemyChakra; if($EnemyDamage1=="0") { $EnemyDamage3= 0; } } elseif($EnemyRand=="3") { $Enemy_Move= $TaijutsuE; $EnemyDamage1= $Taijutsu_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Taijutsupower= $Battle_Rows['Taijutsu_Power']; $Taijutsupower= mysql_real_escape_string($Taijutsupower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Taijutsupower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $Defense= $Taijutsu_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); $EnemyChakra= $Battle_Rows['Enemy_Chakra']; $EnemyChakra= mysql_real_escape_string($EnemyChakra); $ChakraUsedE= $Taijutsu_Enemy_Rows['Chakra_Used']; $ChakraUsedE= mysql_real_escape_string($ChakraUsedE); $PastEnemyChakra= $EnemyChakra; } elseif($EnemyRand=="2") { $Enemy_Move= $GenjutsuE; $EnemyDamage1= $Genjutsu_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Genjutsupower= $Battle_Rows['Genjutsu_Power']; $Genjutsupower= mysql_real_escape_string($Genjutsupower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Genjutsupower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $Defense= $Genjutsu_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); $EnemyChakra= $Battle_Rows['Enemy_Chakra']; $EnemyChakra= mysql_real_escape_string($EnemyChakra); $ChakraUsedE= $Genjutsu_Enemy_Rows['Chakra_Used']; $ChakraUsedE= mysql_real_escape_string($ChakraUsedE); $PastEnemyChakra="$EnemyChakra"; if($EnemyDamage1=="0") { $EnemyDamage3= 0; } } else { $Enemy_Move= $WeaponE; $EnemyDamage1= $Weapon_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Weaponpower= $Battle_Rows['Weapon_Power']; $Weaponpower= mysql_real_escape_string($Weaponpower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Weaponpower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $Defense= $Weapon_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); $EnemyChakra= $Battle_Rows['Enemy_Chakra']; $EnemyChakra= mysql_real_escape_string($EnemyChakra); $ChakraUsedE= $Weapon_Enemy_Rows['Chakra_Used']; $ChakraUsedE= mysql_real_escape_string($ChakraUsedE); $PastEnemyChakra= $EnemyChakra; } $Damage1= $Taijutsu_Rows['Jutsu_Power']; $Damage1= mysql_real_escape_string($Damage1); $Taijutsupower= $Battle_Rows2['Taijutsu_Power']; $Taijutsupower= mysql_real_escape_string($Taijutsupower); $Damage2= round(($Damage1 + $Taijutsupower) + $Power); $Damage3= round($Damage2 / 5); $YourChakra= $Battle_Rows2['Chakra']; $YourChakra= mysql_real_escape_string($YourChakra); $ChakraUsed= $Taijutsu_Rows['Chakra_Used']; $ChakraUsed= mysql_real_escape_string($ChakraUsed); if($Defense=="Yes") { $Damage3="0"; $DefenseMessage="It stopped you from doing damage!"; } if($EnemyChakra < $ChakraUsedE) { $Enemy_Move= $WeaponE; $EnemyDamage1= $Weapon_Enemy_Rows['Jutsu_Power']; $EnemyDamage1= mysql_real_escape_string($EnemyDamage1); $Weaponpower= $Battle_Rows['Weapon_Power']; $Weaponpower= mysql_real_escape_string($Weaponpower); $EnemyPower= $Battle_Rows['Enemy_Power']; $EnemyPower= mysql_real_escape_string($EnemyPower); $EnemyDamage2= round(($EnemyDamage1 + Weaponpower) + $EnemyPower); $EnemyDamage3= round($EnemyDamage2 / 5); $HP= $Battle_Rows2['HP']; $HP= mysql_real_escape_string($HP); $Defense= $Weapon_Enemy_Rows['Defense']; $Defense= mysql_real_escape_string($Defense); $EnemyChakra= $Battle_Rows['Enemy_Chakra']; $EnemyChakra= mysql_real_escape_string($EnemyChakra); $ChakraUsedE= $Weapon_Enemy_Rows['Chakra_Used']; $ChakraUsedE= mysql_real_escape_string($ChakraUsedE); } else { $EnemyChakra= round($EnemyChakra - $ChakraUsedE); } if($YourChakra < $ChakraUsed) { $Enemy_Move="Nothing"; $EnemyChakra="$PastEnemyChakra"; $Damage3= 0; $EnemyDamage3= 0; $DefenseMessage2="You do not have enough Chakra"; } else { $YourChakra= round($YourChakra - $ChakraUsed); } $EnemyDamage3= round($EnemyDamage3 / 1.25); $Enemy_HP= round($Enemy_HP - $Damage3); $Enemy_MHP= $Battle_Rows['Enemy_Max_HP']; $HP= round($HP - $EnemyDamage3); if($HP < 0) { $HP= 0; } if($Enemy_HP < 0) { $Enemy_HP= 0; } mysql_query("UPDATE Battle_Information SET Enemy_HP='$Enemy_HP' WHERE ID='$ID'"); mysql_query("UPDATE users SET HP='$HP' WHERE ID='$ID'"); mysql_query("UPDATE Battle_Information SET Enemy_Chakra='$EnemyChakra' WHERE ID='$ID'"); mysql_query("UPDATE users SET Chakra='$YourChakra' WHERE ID='$ID'"); echo "<html> <center> <table border='3' bordercolor='red' width='350' height='300'><td><center> <table border='0' width='350'><td><center>" . $Battle_Rows['Enemy_Name'] . "<br> HP: " . $Enemy_HP . "/" . $Battle_Rows['Enemy_Max_HP'] . " Chakra: " . $EnemyChakra . "/" . $Battle_Rows['Enemy_Max_Chakra'] . "</td></table><br><br><br><br> <table border='1' width='350'><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><font size='3'><td>Genjutsu:<br><a href='battle.php?Type=Genjutsu'>" . $Battle_Rows2['Genjutsu']. "</a></td><td>Weapon:<br><a href='battle.php?Type=Weapon'>" . $Battle_Rows2['Weapon'] . "</a></td></table><br><table border='0' width='350'> <td><center>" . $Battle_Rows2['Username'] . "<br> HP: " . $HP . "/" . $Battle_Rows2['Max_HP'] . " Chakra: " . $YourChakra . "/" . $Battle_Rows2['Max_Chakra'] . "</td></table>The Enemy used $Enemy_Move. $DefenseMessage<br>It did $EnemyDamage3 damage!<br>$DefenseMessage2<br>You did $Damage3 damage!"; What happened here.. It was working before.. Now after an attack the enemy's HP automatically = 0.. The enemy's HP variable= $Enemy_HP btw. The damage displays correctly.. Quote Link to comment https://forums.phpfreaks.com/topic/141524-solved-what-happened-hp-automatically-0/ Share on other sites More sharing options...
Rushyo Posted January 19, 2009 Share Posted January 19, 2009 Initial observation: $EnemyDamage3= round($EnemyDamage3 / 1.25); Since you set EnemyDamage3 to 0 when there's insufficient Chakra, you're going to cause a division by zero. Honestly, I'd be surprised if anyone has time to dig through all that code. Have you tried a 'dry run'? You will probably find any bug quicker than we will. Quote Link to comment https://forums.phpfreaks.com/topic/141524-solved-what-happened-hp-automatically-0/#findComment-740790 Share on other sites More sharing options...
Xyphon Posted January 19, 2009 Author Share Posted January 19, 2009 that is a problem.. But it wasnt 'the' problem. Because even with sufficent chakra, it does the same thing. For some reason all of its HP depletes. And well, it was working before and randomly stopped... I dont know why.. Thats why I want you guys to help. Quote Link to comment https://forums.phpfreaks.com/topic/141524-solved-what-happened-hp-automatically-0/#findComment-740802 Share on other sites More sharing options...
Xyphon Posted January 19, 2009 Author Share Posted January 19, 2009 NvM found error thanks for helping with the / by 0 though. Quote Link to comment https://forums.phpfreaks.com/topic/141524-solved-what-happened-hp-automatically-0/#findComment-740809 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.