|
Answer» This is my calculator for a certain game .
combat.js is located in the folder combat.php_files. Code: [Select]function hits(){ var finallvl = 0; var hitexp = 0;
var attack = Math.floor(document.forms["combat"].attack.value); var defence = Math.floor(document.forms["combat"].defence.value); var strength = Math.floor(document.forms["combat"].strength.value); var ranged = Math.floor(document.forms["combat"].ranged.value); var magic = Math.floor(document.forms["combat"].magic.value); var rsclvl = Math.floor(document.forms["combat"].rscranged.value); var mexp = Math.floor(document.forms["combat"].nomagic.value); rexp = calclvl(rsclvl);
hitexp = hitexp + calclvl(attack); hitexp = hitexp + calclvl(defence); hitexp = hitexp + calclvl(strength); hitexp = hitexp + calclvl(ranged); hitexp = hitexp + calclvl(magic); if (rsclvl > 1){ hitexp = hitexp - rexp; } if (mexp > 1){ hitexp = hitexp - mexp; } hitexp = ((hitexp / 4) * 1.33); hitexp = hitexp + 1155; finallvl = expToLevel(hitexp); if (finallvl >= 99){ finallvl = 99; } if (finallvl <= 10){ finallvl = 10 } var level = Math.round(finallvl) document.forms["combat"].hitpoints.value = level; }
function calclvl(level){ var points = 0; var output = 0; for (var lvl = 1; lvl <= 150; lvl++){ points = points + Math.floor(lvl + 300 * Math.pow(2, lvl / 7.)); if (lvl >= 1){ if (lvl == level){ return output; } output = Math.floor(points / 4); } } return 0; }
function expToLevel(exp){ var points = 0; var output = 0; for (var lvl = 1; lvl <= 150; lvl++){ points = points + Math.floor(lvl + 300 * Math.pow(2, lvl / 7.)); if (lvl >= 1){ if (output >= exp){ return lvl - 1; } output = Math.floor(points / 4); } } return 0; } This is my html code for the webpage. Code: [Select]<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><head>
<title>WestScript RS2 Calculators</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="description" content="RuneScape 2 Calculators featuring a combat calculator, high-alchemy calculator and a super heat calculator."> <meta name="keywords" content="westscript, michael west, web development, runescape, runescape 2, rs, rs2, calculators, rshsc, runehead, hiscores, memberlist, clan, nonclan, non-clan, combat, high alchemy, super heat"> <link rel="stylesheet" type="text/CSS" href="combat.php_files/styles.css" media="screen, tv, projection"> <link rel="icon" href="http://www.westscript.com/westscript.ico" type="image/x-icon"> <link rel="shortcut icon" href="http://www.westscript.com/westscript.ico" type="image/x-icon"> </head><body> <div id="header"> <div style="vertical-align: bottom; margin-top: 12px;"><img src="combat.php_files/westscript.png" ALT=""></div> </div> <div id="content"> <div id="links"> <a href="http://www.westscript.com/calcs/index.php">Home</a><br> <a href="http://www.westscript.com/calcs/combat.php">Combat</a><br> <a href="http://www.westscript.com/calcs/alchemy.php">High-Alchemy</a><br> <a href="http://www.westscript.com/calcs/heat.php">Superheat</a><br><br> <a href="http://www.westscript.com/calcs/contact.php">Contact Me</a><br> <a href="http://www.westscript.com/index.php">Back to WestScript</a><br> </div> <div id="text"> <script src="combat.php_files/combat.js" type="text/javascript"></script> <form action="combat.php" id="combat" method="post"> <h1 style="text-align: center;">Combat Calculator</h1> <table style="width: 280px; margin-left: auto; margin-right: auto; margin-top: 15px;" border="1"> <tbody><tr> <td style="width: 85%; text-align: right;">Attack Level: </td> <td style="width: 15%;"><input size="3" name="attack" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">Defence Level: </td> <td style="width: 15%;"><input size="3" name="defence" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">Strength Level: </td> <td style="width: 15%;"><input size="3" name="strength" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">Hitpoints Level: </td> <td style="width: 15%;"><input size="3" name="hitpoints" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">Prayer Level: </td> <td style="width: 15%;"><input size="3" name="prayer" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">Ranged Level: </td> <td style="width: 15%;"><input size="3" name="ranged" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">Magic Level: </td> <td style="width: 15%;"><input size="3" name="magic" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">RSC Ranged (optional): </td> <td style="width: 15%;"><input size="3" name="rscranged" maxlength="2" value=""></td> </tr> <tr> <td style="width: 85%; text-align: right;">Non-HP Magic XP (optional): </td> <td style="width: 15%;"><input size="3" name="nomagic" value=""></td> </tr> </tbody></table> <table style="width: 280px; margin-left: auto; margin-right: auto;" border="0"> <tbody><tr> <td style="width: 50%;"><input class="submit" onclick="hits();" value="Calculate Hitpoints" type="button"></td> <td style="width: 50%;"><input class="submit" value="Calculate Combat" type="submit"></td> </tr> <tr> <td colspan="2"> <div style="border: 0px none ; text-align: center; margin-top: 5px; width: 264px; color: rgb(0, 0, 0); font-family: verdana,sans-serif; font-style: normal; font-variant: normal; font-weight: bold; font-size: 16px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; display: block;">Combat Level: 0</div> </td> </tr> </tbody></table> </form>
<p> <br> This Combat Calculator will calculate your RuneScape 2 Combat Level.<br><br> Insert Attack, Defence etc. levels and click the 'Calculate Combat' button to find out the Combat Level for those stats. Pressing 'Calculate Hits' will calculate the Hitpoints Level for those stats.<br><br> In 'RSC Ranged' field you can enter your RuneScape Classic Ranged Level or leave it blank. In the 'Non-HP Magic XP' field add how much XP you have gained using styles of magic such as alchemy that give no HP or leave it empty.<br><br> <b>Please note that formulas are not 100% accurate.</b> </p> </div> </div> <div id="footer"> <a href="http://www.westscript.com/">© 2004-2008 Michael West</a> | <a href="http://validator.w3.org/check?uri=referer"><img src="combat.php_files/w3c.png" alt=""> Validate XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="combat.php_files/w3c.png" alt=""> Validate CSS</a> </div> </body></html>
When I click calculate combat it does nothing, help is appreciated please. I would also like it to be a JavaScript alert to pop-up with your combat level. All help is appreciated. Thanks.Woah, that's a complicated script you got there...
What is combat.php?combat.php is the webpage (the second code).Shucks! yep a good size chunk of code there. Most interesting.
Sadly my JScript skills are well below this level but I'll see if I can follow the flow. At the moment I am looking for a call to combat.js in the html head - and only see a CSS call plus favicon, tho I see a call for it in the body. Would a call from be better?
I assume no eror messages but - have you done a debug on it? Always so aware that the smallest syntax error can screw things up totally.
The js content itself is right now a bit deep for me.I appreciate your help anyway. And I need a call from the button to display an alert with the combat level.I this script supposed to redirect to combat.php? Is that where a user calculates his/her combat level? Just for clarification, does the hit points button work? Most of the time it SEEMS when a button does nothing, it is usually because of a misspelling. Do you get any errors when you click the combat button?Yes hitpoints work And there is no error on combat. Instead of refreshing how would i make it display the combat level in an alert?
|