Problem is, is where I started a loop with a max 100, it went through the entire 100 loops, bringing both player/NPC health to like -40K health lol.....
Where do I stop it? Since I've mixed it all, I have no idea where to place it...
Now everything works... I click attack... it displays the attack on both sides... when it reaches - 0 or below on HP for either player/NPC, it displays if u've lost or won... (I'll have to fix the hp going negative eventually, but it still works for now)... I just have to keep refreshing page to do each round until I win/lose..... As said, I have no idea where to put the command, or exactly what command to put, in order to loops this and then stop when you either win or lose... I won't expect an immediate answer, as it's a lot of code to wade through, but if anyone has the time, it would be appreciated. Thank you much!
CODE:
Code: Select all
<script>
function FocusOut()
{
document.status.msgbx.focus();
}
function FocusOut1()
{
document.weapons.life.focus();
}
function npc_check()
{
var enemyHp = "<?php echo $enemyHp; ?>";
if(enemyHp <= 0){
document.status2.msgbx2.value = "Congratulations, you win!";
}else{
}
}
function player_check()
{
var playerHp = "<?php echo $playerHp; ?>";
if(playerHp <= 0){
document.status2.msgbx2.value = "You've lost the battle!";
}else{
}
}
</script>
<script>
setTimeout('document.weapons.life.value = "<?php echo $playerHp; ?>";', 0);
</script>
<?php
$player_accuracy = mt_rand($user_accuracy, 100);
$player_atkdam = mt_rand(0,$user_strength);
$player_critical = mt_rand(0,$user_strength)*2;
if($player_accuracy > 80 && $player_critical>=$user_strength){
$outputList .= 'Your critical attack hits and ' . $arena_char_name . ' suffers ' . $player_critical . ' health';
$npc_hp_lost = $player_critical;
$npc_new_hpoints -= $npc_hp_lost;
$updateatkhp = "UPDATE npc_characters SET hpoints=hpoints +'$npc_new_hpoints' WHERE charid ='$character' AND userid = '$user_id'";
$user_query = mysqli_query($db_conx, $updateatkhp);
?>
<script>
setTimeout('document.status.msgbx.value = "<?php echo $outputList; ?>";', 2000);
setTimeout('npc_check()', 6000);
</script>
<?php
}elseif($player_accuracy < 80 || $player_accuracy > 80) {
$outputList .= 'Your attack hits and ' . $arena_char_name . ' suffers ' . $player_atkdam . ' health';
$npc_hp_lost = $player_atkdam;
$npc_new_hpoints -= $npc_hp_lost;
$updateatkhp = "UPDATE npc_characters SET hpoints=hpoints +'$npc_new_hpoints' WHERE charid ='$character' AND userid = '$user_id'";
$user_query = mysqli_query($db_conx, $updateatkhp);
?>
<script>
setTimeout('document.status.msgbx.value = "<?php echo $outputList; ?>";', 2000);
setTimeout('npc_check()', 6000);
</script>
<?php
}else{
$outputList .= 'Your attacked missed! You really suck !'; ?>
<script>
setTimeout('document.status.msgbx.value = "<?php echo $outputList; ?>";', 2000);
setTimeout('npc_check()', 6000);
</script>
<?php
}
$outputList1 = '';
$sql = "SELECT * FROM characters where id ='$character' LIMIT $character";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
$row = mysqli_fetch_array($user_query, MYSQLI_ASSOC);
$enemy_accuracy = mt_rand($characters_accuracy, 100);
$enemy_atkdam = mt_rand(0,$row['attack']);
$enemy_critical = mt_rand(0,$row['attack'])*2;
if($enemy_accuracy > 80 && $enemy_critical>=$row['attack']){
$outputList1 .= '' . $enemyname . ' critical attack hit you. You suffer ' . $enemy_critical . ' health';
$player_hp_lost = $enemy_critical;
$player_new_hpoints -= $player_hp_lost;
$updateplayerhp = "UPDATE users SET hpoints=hpoints +'$player_new_hpoints' WHERE id = '$user_id'";
$user_query = mysqli_query($db_conx, $updateplayerhp);
?>
<script>
setTimeout('document.status1.msgbx1.value = "<?php echo $outputList1; ?>";', 4000);
setTimeout('player_check()', 8000);
</script>
<?php
}elseif($enemy_accuracy < 80 || $enemy_accuracy > 80) {
$outputList1 .= '' . $enemyname . ' hits and you suffer ' . $enemy_atkdam . ' health';
$player_hp_lost = $enemy_atkdam;
$player_new_hpoints -= $player_hp_lost;
$updateplayerhp = "UPDATE users SET hpoints=hpoints +'$player_new_hpoints' WHERE id = '$user_id'";
$user_query = mysqli_query($db_conx, $updateplayerhp);
?>
<script>
setTimeout('document.status1.msgbx1.value = "<?php echo $outputList1; ?>";', 4000);
setTimeout('player_check()', 8000);
</script>
<?php
}else{
$outputList1 .= '' . $enemyname . ' missed. They really suck !'; ?>
<script>
setTimeout('document.status1.msgbx1.value = "<?php echo $outputList1; ?>";', 4000);
setTimeout('player_check()', 8000);
</script>
<?php
}
}
}
}
?>
<br />
<form name="weapons">
<font face="Times New Roman" size="3"><i>Your life: </i></font>
<input type="text" readonly="true" size="10" maxlength="10" name="life" onFocus="FocusOut1()" style="background-color:#575957; border:none"><br>
</form>
<br />
<form name="status">
<input type="text" readonly="true" name="msgbx" size="80" maxlength="80" onFocus="FocusOut()" onKeyDown="javascript: alert('Don\'t do that!');" style="background-color:#575957; border:none">
</form>
<br />
<form name="status1">
<input type="text" readonly="true" name="msgbx1" size="80" maxlength="80" onFocus="FocusOut()" onKeyDown="javascript: alert('Don\'t do that!');" style="background-color:#575957; border:none">
</form>
<br />
<form name="status2">
<input type="text" readonly="true" name="msgbx2" size="80" maxlength="80" onFocus="FocusOut()" onKeyDown="javascript: alert('Don\'t do that!');" style="background-color:#575957; border:none">
</form>