Jump to content

Help with if statement


twilitegxa

Recommended Posts

I have the following script and I would like to write a script that prints "Hit!" if the roll3 is less than or equal to $acv1 or "Miss!" if it is higher than the $acv1. How can I do this? Here is my page so far:

 

<?php
include "connect_db.php";

$get_identity = "select id, identity from scouts where id = '$_GET[id]'";
$get_identity_res = mysql_query($get_identity, $conn) or die(mysql_error());

while ($get_scouts = mysql_fetch_array($get_identity_res)) {
    $id = $get_scouts['id'];
    $identity = $get_scouts['identity'];
}

//stats
$get_stats = "select * from stats where identity = '$identity'";

$get_stats_res = mysql_query($get_stats, $conn) or die(mysql_error());

while ($stats_info = mysql_fetch_array($get_stats_res)) {
        $body = $stats_info['body'];
        $mind = $stats_info['mind'];
        $soul = $stats_info['soul'];
        
    }
    
//gather derived values
$get_derived = "select * from derived_values where identity = '$identity'";

$get_derived_res = mysql_query($get_derived, $conn) or die(mysql_error());

while ($derived_info = mysql_fetch_array($get_derived_res)) {
    $health = $derived_info['health'];
    $energy = $derived_info['energy'];
    $acv1 = $derived_info['acv1'];
    $acv2 = $derived_info['acv2'] . ' (for Sailor Scout Attack)';
    $dcv1 = $derived_info['dcv1'];
    $dcv2 = $derived_info['dcv2'] . ' (for Sailor Scout Attack)';
}
?>
<html>
<head>
<title>Untitled Document</title>
<SCRIPT LANGUAGE="JavaScript">
var die = 6; // 6 sided dice
var dice = 2; // number of dice to roll
function dice_roll(die, dice) {
var roll = 0;
for (loop=0; loop < dice; loop++) {
roll = roll + Math.round(Math.random() * die) % die + 1;
}
document.form.text.value = roll;
}

</script>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<center>
<form name=form>
<table border="1" cellpadding="3" cellspacing="3">
<tr>
<td align=middle>Roll the dice to take your turn</td>
<td><?php print $identity; ?></td>
</tr>
<tr>
<td>
<b>Total:</b>
<input type=text size=1 name=text  class="dice_total">
<input type=button value="Roll" name=button onclick="dice_roll(die, dice)"></td>
<td>Body: <?php print $body;?><br>
Mind: <?php print $mind; ?><br>
Soul: <?php print $soul; ?><br>
Health: <?php print $health; ?><br>
Energy: <?php print $energy; ?><br>
ACV: <?php print $acv1; ?> [<?php print $acv2; ?>]<br>
DCV: <?php print $dcv1; ?> [<?php print $dcv2; ?>]<br></td>
<td valign="top">
<script type="text/javascript">
min=2;
max=7;
var roll1=Math.floor(Math.random()*(max-min))+min;
var roll2=Math.floor(Math.random()*(max-min))+min;
var roll3 = roll1+roll2;

var roll1 = roll1+<?php print $acv1 ?>;
var roll2 = roll1+<?php print $acv1 ?>; //this will be enemy's acv
</script>
Initiative:<br>
<?php print $identity ?> - <script>document.write(roll1)</script><br>
Enemy - <script>document.write(roll2)</script><br><br>
Attack: <script>document.write(roll3)</script>  <script>document.write(hit)</script>


</td>
</tr>
</table>
</form>
</center>
</div>
<?php include("bottomnav.php"); ?>
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters are<br>
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br>
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav"><!-- <ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul> --></div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/173974-help-with-if-statement/
Share on other sites

<script type="text/javascript">

min=2;

max=7;

var roll1=Math.floor(Math.random()*(max-min))+min;

var roll2=Math.floor(Math.random()*(max-min))+min;

var roll3 = roll1+roll2;

 

var roll1 = roll1+<?php print $acv1 ?>;

var roll2 = roll1+<?php print $acv1 ?>; //this will be enemy's acv

 

if(document.getElementById('roll3').value <= document.getElementById('acv1').value)

alert("Miss");

else

alert("hit");

</script>

 

remember

 

ACV: <?php print $acv1; ?>

 

put a hidden textbox

 

<input type="hidden" value="<?php print $acv1; ?>" id="acv1"/>

 

 

hope this help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.