PDA

View Full Version : Calling all rpg players, need calculator help


Antoniohawk
12-15-2002, 04:42 AM
For all of you that play rpgs, it will be alot easier for u to help me. To see the visual part, go to http://www.avidgamers.com/RuneRaiders/prayercalc.html

I will try to give short yet detailed summary of what this script does. As you open the page u can see that there are 2 input fields, one where you enter in the experience that you currently have, and the other where you enter in the lvl you want (if the first radio is checked) or the experience you want (if the second radio is checked. It then outputs the result of an equation, but that has nothing to do with my problem. What i want to happen, is that the table cell that says "Burst of Strength" to have a red background if the number entered into the first field is "< lvl[4]". If the number in the first field is ">= lvl[4]" then the bg color should be red. For some reason i get no errors but it works, i think it has something to do with the function that has the code that says what color the bg should be, maybe it isnt getting called. Well that was tough, and Im sure i didnt explain enough of something, please reply and try to help me, i will try to answer any questions that you may have.

<html>
<head>
<style>
INPUT {
FONT-FAMILY: Verdana, Helvetica;
FONT-SIZE: 10px;
border: 1px green solid;
background-color: #000000;
color: #ffffff;
}
</style>
<script language=javascript>
function calcPray(prayer1,prayer2,prayeroutput,prayeroutput2)
{

var lvl = new Array(99)
lvl[0]=0;
lvl[1]=0;
lvl[2]=83;
lvl[3]=174;
lvl[4]=276;
lvl[5]=388;
lvl[6]=512;
lvl[7]=650;
lvl[8]=801;
lvl[9]=969;
lvl[10]=1154;
lvl[11]=1358;
lvl[12]=1584;
lvl[13]=1833;
lvl[14]=2107;
lvl[15]=2411;
lvl[16]=2746;
lvl[17]=3115;
lvl[18]=3523;
lvl[19]=3973;
lvl[20]=4470;
lvl[21]=5018;
lvl[22]=5624;
lvl[23]=6291;
lvl[24]=7028;
lvl[25]=7842;
lvl[26]=8740;
lvl[27]=9730;
lvl[28]=10824;
lvl[29]=12031;
lvl[30]=13364;
lvl[31]=14833;
lvl[32]=16456;
lvl[33]=18249;
lvl[34]=20224;
lvl[35]=22406;
lvl[36]=24815;
lvl[37]=27473;
lvl[38]=30408;
lvl[39]=33648;
lvl[40]=37224;
lvl[41]=41171;
lvl[42]=45529;
lvl[43]=50339;
lvl[44]=55649;
lvl[45]=61512;
lvl[46]=67983;
lvl[47]=75127;
lvl[48]=83014;
lvl[49]=91720;
lvl[50]=101333;
lvl[51]=111945;
lvl[52]=123660;
lvl[53]=136594;
lvl[54]=150872;
lvl[55]=166636;
lvl[56]=184040;
lvl[57]=203254;
lvl[58]=224466;
lvl[59]=247886;
lvl[60]=273742;
lvl[61]=302288;
lvl[62]=333804;
lvl[63]=368599;
lvl[64]=407015;
lvl[65]=449428;
lvl[66]=496254;
lvl[67]=547953;
lvl[68]=605032;
lvl[69]=668051;
lvl[70]=737627;
lvl[71]=814445;
lvl[72]=899257;
lvl[73]=992895;
lvl[74]=1093728;
lvl[75]=1210421;
lvl[76]=1336443;
lvl[77]=1475581;
lvl[78]=1629200;
lvl[79]=1798808;
lvl[80]=1986068;
lvl[81]=2192818;
lvl[82]=2421087;
lvl[83]=2673114;
lvl[84]=2951373;
lvl[85]=3258594;
lvl[86]=3597793;
lvl[87]=3972294;
lvl[88]=3485774;
lvl[89]=5346332;
lvl[90]=5902831;
lvl[91]=6517253;
lvl[92]=7195629;
lvl[93]=7195629;
lvl[94]=7944614;
lvl[95]=8771558;
lvl[96]=9684577;
lvl[97]=10692629;
lvl[98]=11805606;
lvl[99]=13034431;

if (prayerform.enter[0].checked)
{
var num1 = lvl[prayer1.value];
}

if (prayerform.enter[1].checked)
{
var num1 = parseInt(prayer1.value,10)
}

var num2 = parseInt(prayer2.value,10);

if (isNaN(num1) || num1<0){
alert("Please enter a positive number for field 1.");
prayer1.focus();
return;
}
if (isNaN(num2) || num2<0){
alert("Please enter a positive number for field 2.");
prayer2.focus();
return;
}

prayeroutput.value = Math.ceil((num1-num2)/3.75);
prayeroutput2.value = Math.ceil((num1-num2)/12.5);

function lvlColor()
{
if (prayer2 < lvl[4])
{
document.getElementById("lvl4").bgColor = "red";
}

if (prayer2 < lvl[7])
{
document.getElementById("lvl7").bgColor = "red";
}

if (prayer2 < lvl[10])
{
document.getElementById("lvl10").bgColor = "red";
}

if (prayer2 < lvl[13])
{
document.getElementById("lvl13").bgColor = "red";
}

if (prayer2 < lvl[16])
{
document.getElementById("lvl16").bgColor = "red";
}

if (prayer2 < lvl[19])
{
document.getElementById("lvl19").bgColor = "red";
}

if (prayer2 < lvl[22])
{
document.getElementById("lvl22").bgColor = "red";
}

if (prayer2 < lvl[25])
{
document.getElementById("lvl25").bgColor = "red";
}

if (prayer2 < lvl[28])
{
document.getElementById("lvl28").bgColor = "red";
}

if (prayer2 < lvl[31])
{
document.getElementById("lvl31").bgColor = "red";
}

if (prayer2 < lvl[34])
{
document.getElementById("lvl34").bgColor = "red";
}

if (prayer2 < lvl[37])
{
document.getElementById("lvl37").bgColor = "red";
}

if (prayer2 < lvl[40])
{
document.getElementById("lvl40").bgColor = "red";
}

if (prayer2 >= lvl[4])
{
document.getElementById("lvl4").bgColor = "green";
}

if (prayer2 >= lvl[7])
{
document.getElementById("lvl7").bgColor = "green";
}
}

}
</script>
</head>
<body>
<table cellspacing="2" cellpadding="0">
<th colspan="2"><center><b>Prayer</b></center></th>
<tr>
<td bgcolor="gray" style="font-size:15px; color: white; padding-left: 10px; padding-right: 10px; padding-top: 10px; border:1px #000000 solid" colspan="2">
<form name="prayerform">
Enter in your Prayer experience: <input name="prayer2">
<br>
Enter in wanted lvl<input type="radio" name="enter" value="lvl"> or exact exp.<input type="radio" name="enter" value="exactexp">: <input name="prayer1">
<br>
<center><input type="button" value="Submit" onclick="calcPray(this.form.prayer1,this.form.prayer2,this.form.prayeroutput,this.form.prayeroutput2)" onSubmit="lvlColor()"></center>
<br>
</td>
</tr>
<tr>
<td bgcolor="gray" style="font-size:15px; color: white; padding-left: 10px; padding-right: 10px; padding-top: 10px; border:1px #000000 solid" colspan="2">
You have to bury <input name="prayeroutput"> small bones!
<br>
You have to bury <input name="prayeroutput2"> big bones!
</form>
</td>
</tr>
</table>
<table style="border:1px green solid; padding-left: 10px; padding-right: 10px;" width="500">
<tr>
<td><b>Level<b></td>
<td><b>Prayer<b></td>
</tr>
<tr>
<td>1</td>
<td bgcolor="green">Thick Skin</td>
</tr>
<tr>
<td>4</td>
<td id="lvl4">Burst of Strength</td>
</tr>
<tr>
<td>7</td>
<td id="lvl7">Clarity of Thought</td>
</tr>
<tr>
<td>10</td>
<td id="lvl10">Rock Skin</td>
</tr>
<tr>
<td>13</td>
<td id="lvl13">Superhuman Strength</td>
</tr>
<tr>
<td>16</td>
<td id="lvl16">Improved Reflexes</td>
</tr>
<tr>
<td>19</td>
<td id="lvl19">Rapid Restore</td>
</tr>
<tr>
<td>22</td>
<td id="lvl22">Rapid Heal</td>
</tr>
<tr>
<td>25</td>
<td id="lvl25">Protect Items</td>
</tr>
<tr>
<td>28</td>
<td id="lvl28">Steel Skin</td>
</tr>
<tr>
<td>31</td>
<td id="lvl31">Ultimate Strength</td>
</tr>
<tr>
<td>34</td>
<td id="lvl34">Incredible Reflexes</td>
</tr>
<tr>
<td>37</td>
<td id="lvl37">Paralyze Monster</td>
</tr>
<tr>
<td>40</td>
<td id="lvl40">Protect From Missiles</td>
</tr>
</table>
<br>
<br>
<center>Created by Antoniohawk</center>
<br><center>Feel free to use the calculators. If you wish to put it on your website, please give credit to the creator.</center>
<br>
</body>
</html>

joh6nn
12-15-2002, 08:36 AM
What i want to happen, is that the table cell that says "Burst of Strength" to have a red background if the number entered into the first field is "< lvl[4]". If the number in the first field is ">= lvl[4]" then the bg color should be red. For some reason i get no errors but it works,


i think you definitely need to do a little bit more explainging

Antoniohawk
12-15-2002, 06:03 PM
lol i thought so. Well here goes:

As you can see if you go to the page, the table cell that says "Thick Skin" is already green, because you start at lvl 1 so, you can do that skill. This is a calculator based on a role-playing game called Runescape (http://www.runescape.com). Let me explain a litle about the game so you can figure out how to help me. You start out as a person, and the object of the game is to grow in certain skill areas, such as woodcutting, firemaking, and in this case prayer. You grow by gaining experience points when you do things. You start at lvl 1 which is at 0 experience points. AS you can see if you look at the array,
'lvl[1] = 0' says that at lvl 1 you have 0 experience. 'lvl[2] = 83' says that to get to lvl 2 from lvl 1 you need 83 experience. Now to explain more about prayer. To gain experience in prayer, you must bury bones that are located throughout the game. There are 2 types, regular and big bones. Each regular bone that you bury is worth 3.75 experience. Each big bone that you bury is worth 12.5 experience. AS you look at the calculator, the first field is where you enter in the experience that you currently have. Now lets say you want to figure out how many small bones you need to bury to get to lvl 5 from 0 experience. You would type in 0 in the first field, and then you would type in 5 in the second field and check the first radio button, meaning that you want to get to a certain lvl, instead of a certain amount experience. At the bottom of the page you can see a table with cells pertaining to different prayers. At lvl four prayer, you use burst of strength. What I want to happen is, if the experience entered into the first field is greater than or equal to the amount of experience you have at lvl 4, then the table cell that says 'burst of strength' will have a green background, meaning you can use that prayer. If your experience is less than what you would have at lvl 4, then the background color should be red, meaning that you cant use that prayer yet. The following is the part of the code that I used to change the colors of the backgrounds depending on the experience that you enter:

function lvlColor()
{
if (prayer2 < lvl[4])
{
document.getElementById("lvl4").bgColor = "red";
}

if (prayer2 < lvl[7])
{
document.getElementById("lvl7").bgColor = "red";
}

if (prayer2 < lvl[10])
{
document.getElementById("lvl10").bgColor = "red";
}

if (prayer2 < lvl[13])
{
document.getElementById("lvl13").bgColor = "red";
}

if (prayer2 < lvl[16])
{
document.getElementById("lvl16").bgColor = "red";
}

if (prayer2 < lvl[19])
{
document.getElementById("lvl19").bgColor = "red";
}

if (prayer2 < lvl[22])
{
document.getElementById("lvl22").bgColor = "red";
}

if (prayer2 < lvl[25])
{
document.getElementById("lvl25").bgColor = "red";
}

if (prayer2 < lvl[28])
{
document.getElementById("lvl28").bgColor = "red";
}

if (prayer2 < lvl[31])
{
document.getElementById("lvl31").bgColor = "red";
}

if (prayer2 < lvl[34])
{
document.getElementById("lvl34").bgColor = "red";
}

if (prayer2 < lvl[37])
{
document.getElementById("lvl37").bgColor = "red";
}

if (prayer2 < lvl[40])
{
document.getElementById("lvl40").bgColor = "red";
}

if (prayer2 >= lvl[4])
{
document.getElementById("lvl4").bgColor = "green";
}

if (prayer2 >= lvl[7])
{
document.getElementById("lvl7").bgColor = "green";
}

To explain what i tried to do, as you can see in:
____________________________________________________
if (prayer2 < lvl[4])
{
document.getElementById("lvl4").bgColor = "red";
}
____________________________________________________

'prayer2' is the number you entered for the experience that you currently have.

'lvl[4]' is the item in the array that says that lvl 4 is at 276 experience.

so all i did was add 'id="lvl4"' inside of the <td> cell containing Burst of Srength and tried to say that if the prayer2 is less than lvl[4], then the bgcolor of the cell should be red. That was a very long explaination, please ask any questions that you may have. As for you joh6nn, the part of my post that you had quoted was wrong, and that may be the source of ur confusion. It was supposed to read:

"What i want to happen, is that the table cell that says "Burst of Strength" to have a red background if the number entered into the first field is "< lvl[4]". If the number in the first field is ">= lvl[4]" then the bg color should be green . For some reason i get no errors but it works,"

joh6nn
12-15-2002, 07:36 PM
ok, let me know if this isn't what you want. it's a bit too large to post, so i'm attaching it instead.

Antoniohawk
12-15-2002, 08:43 PM
Hey its great that you got the colors to change, but i still got a prob. If lvl 7 is green, then 4 and 1 should be green too, because you can do those prayers. Anything after 7, or higher in number should be red.

Antoniohawk
12-15-2002, 09:22 PM
thanks alot for your time spent on helping me, but i figured it out. I got rid of the function lvlColor and i figured out the main cause of my misery. When i used the value of prayer 2 in my calcualtions, it was changed to num2, so i just replaced all of the prayer2's in the if statements to num1's. Thanks alot for ur help though, it wouldnt have worked without ".style.backgroundColor". Ty again! :thumbsup: