while loop stuck after 1 loop

Hey guys, I’m building an online game and I’ve currently tried implementing a quick battle feature, which auto resolves a fight instead of playing through rounds one at a time.

However, all that’s currently happening is it’s running through once. Most of the variables are self explanatory - $mobcurrhealth is the enemy’s health, $currhealth is your health, $pdamage is your damage, $mdamage is enemy damage, $phit and $mhit are hits modified by armour (all predefined) and the crit’s also predefined.

while (($mobcurrhealth > 0) && ($currhealth > 0)) {
$pdamage = floor(rand($pdamage0.8,$pdamage1.2));
$mdamage = floor(rand($mdamage0.8,$mdamage1.2));

	$phit = (($pdamage)-($marmor));
	if ($phit < 0) {
		$phit = 0;
	}
	
	$mhit = (($mdamage)-($parmor));
	if ($mhit < 0) {
		$mhit = 0;
	}
	if ($mhit < (($mlevel/2)+1)) {
		$mhit = (($mlevel/2)+1);
	}
		
	$playercrit = rand(1,100);
	if ($playercrit <= $pcrit) {
		$pmoddamage = 1.5;
	} elseif ($playercrit > $pcrit) {
		$pmoddamage = 1;
	}
	$mobcrit = rand(1,100);
	if ($mobcrit <= $mcrit) {
		$mmoddamage = 1.5;
	} elseif ($mobcrit > $mcrit) {
		$mmoddamage = 1;
	}
	$poveralldamage = floor($phit*$pmoddamage);
	$moveralldamage = floor($mhit*$mmoddamage);
	
	$currhealth = $currhealth-$moveralldamage;
	$mobcurrhealth = $mobcurrheath-$poveralldamage;
	
	if ($currhealth < 0) {
		$currhealth = 0;
	}
	if ($mobcurrhealth < 0) {
		$mobcurrhealth = 0;
	}
	mysql_query("UPDATE mobs SET mobcurrhealth = ".$mobcurrhealth." WHERE mobid= ".$rmob['mobid']);
	mysql_query("UPDATE users SET currhealth = ".$currhealth." WHERE id= ".$r['id']);
	
	if ($pmoddamage == 1.5) {
		echo "You CRIT the ".$rmob['mobname']." for <b>".$poveralldamage."!</b> <br />";
	} elseif ($pmoddamage == 1) {
		echo "You hit the ".$rmob['mobname']." for ".$poveralldamage."! <br />";
	}
	if ($mmoddamage == 1.5) {
		echo "The ".$rmob['mobname']." CRITS you for <b>".$moveralldamage."!</b><br />";	
	} elseif ($mmoddamage == 1) {
		echo "The ".$rmob['mobname']." hits you for ".$moveralldamage."!<br />";	
	}
	
}

Also, it’d be useful to share that one round is executing perfectly and both mysql queries are successful

Sponsor our Newsletter | Privacy Policy | Terms of Service