I can't get the battle to stop once there hp is 0 I get this...
Test attacks Wuggy for 11 damage,14 remaining.
Wuggy attacks Test for 9 damage,16 remaining.
Test attacks Wuggy for 7 damage,7 remaining.
Wuggy attacks Test for 1 damage,13 remaining.
Test attacks Wuggy for 6 damage,1 remaining.
Wuggy attacks Test for 9 damage,-2 remaining.Wuggy beats Test
Test attacks Wuggy but misses!
Wuggy attacks Test for 10 damage,-10 remaining.Wuggy beats Test
Wuggy attacks and kills him, but yet test attacks him, forcing him to attack back. I have my add +1 kill and death in the killing attack, so if he attacks twice, it adds 2 of each kills and deaths.
Here is my script, Its a little messy so don't complain :-p
I have the two attack functions that are supposed to stop it if they're dead, but it doesn't, the damage done is entered into the database and then taken out once it attacks again and so forth. Any ideas?
<?php
function attack2() {
if(!($link_id = mysql_connect($db_host, $db_user, $db_password))) die(mysql_erorr());
mysql_select_db($db_name);
$wdbattle = mysql_query("SELECT FROM wdbattle WHERE uid = 1");
$wdbattle = mysql_fetch_array($wdbattle);
$strength = $wdbattle[strength];
$speed = $wdbattle[speed];
$defense = $wdbattle[defense];
$hpleft = $wdbattle[hpleft];
$name = $wdbattle[name];
$strength = $strength;
if(!($link_id = mysql_connect($db_host, $db_user, $db_password))) die(mysql_erorr());
mysql_select_db($db_name);
$wdbattle2 = mysql_query("SELECT FROM wdbattle WHERE uid = 2");
$wdbattle2 = mysql_fetch_array($wdbattle2);
$strength2 = $wdbattle2[strength];
$speed2 = $wdbattle2[speed];
$defense2 = $wdbattle2[defense];
$hpleft2 = $wdbattle2[hpleft];
$name2 = $wdbattle2[name];
$strength2 = $strength2 + 1;
echo "<BR>";
$result2 = $strength2 - $defense;
$result4 = $result2 + 5;
$result3 = $result2 - 5;
$result2 = rand($result3, $result4);
$rand2 = rand(1, 100);
if($rand2 < 21) {
echo "$name2 attacks $name but misses!";
} else {
echo "$name2 attacks $name for $result2 damage,";
$hpleft = $hpleft - $result2;
mysql_query("UPDATE wdbattle SET hpleft=$hpleft WHERE uid='1'");
$wdbattle = mysql_query("SELECT * FROM wdbattle WHERE uid = 1");
$wdbattle = mysql_fetch_array($wdbattle);
$hpleft = $wdbattle[hpleft];
echo "$hpleft remaining.";
}
if ($hpleft < 1) {
echo "$name2 beats $name";
mysql_query("UPDATE wdbattle SET hpleft=0 WHERE uid='1'");
mysql_query("UPDATE wdbattle SET deaths=deaths+1 WHERE uid='1'");
mysql_query("UPDATE wdbattle SET kills=kills+1 WHERE uid='2'");
}
else {
attack();
}
}
function attack() {
if(!($link_id = mysql_connect($db_host, $db_user, $db_password))) die(mysql_erorr());
mysql_select_db($db_name);
$wdbattle = mysql_query("SELECT FROM wdbattle WHERE uid = 1");
$wdbattle = mysql_fetch_array($wdbattle);
$strength = $wdbattle[strength];
$speed = $wdbattle[speed];
$defense = $wdbattle[defense];
$hpleft = $wdbattle[hpleft];
$name = $wdbattle[name];
$strength = $strength;
if(!($link_id = mysql_connect($db_host, $db_user, $db_password))) die(mysql_erorr());
mysql_select_db($db_name);
$wdbattle2 = mysql_query("SELECT FROM wdbattle WHERE uid = 2");
$wdbattle2 = mysql_fetch_array($wdbattle2);
$strength2 = $wdbattle2[strength];
$speed2 = $wdbattle2[speed];
$defense2 = $wdbattle2[defense];
$hpleft2 = $wdbattle2[hpleft];
$name2 = $wdbattle2[name];
$strength2 = $strength2 + 1;
echo "<BR>";
$result = $strength - $defense2;
$result0 = $result + 5;
$result1 = $result - 5;
$result = rand($result1, $result0);
$rand = rand(1, 100);
if($rand < 21) {
echo "$name attacks $name2 but misses!";
} else {
echo "$name attacks $name2 for $result damage,";
$hpleft2 = $hpleft2 - $result;
mysql_query("UPDATE wdbattle SET hpleft=$hpleft WHERE uid='2'");
$wdbattle = mysql_query("SELECT * FROM wdbattle WHERE uid = 2");
$wdbattle = mysql_fetch_array($wdbattle);
$hpleft = $wdbattle[hpleft];
echo "$hpleft2 remaining.";
}
if ($hpleft2 < 1) {
echo "$name beats $name2";
mysql_query("UPDATE wdbattle SET hpleft=0 WHERE uid='2'");
mysql_query("UPDATE wdbattle SET deaths=deaths+1 WHERE uid='2'");
mysql_query("UPDATE wdbattle SET kills=kills+1 WHERE uid='1'");
}
else {
attack2();
}
}
attack();
attack2();
?>