Lone Wolf Development Forums  

Go Back   Lone Wolf Development Forums > Realm Works Forums > Realm Works Discussion
Register FAQ Community Today's Posts Search

Notices

Reply
 
Thread Tools Display Modes
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 06:57 PM
hmmm... parentNode should have worked if it uses the same engine, but in reality, it doesnt matter that much.
mirtos is offline   #21 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 10th, 2014, 12:03 AM
Sorry for the late reply. I had a game tonight. Final battle of Jade regent Night of Frozen Shadows. I have the final code. It is tested to work in RW.

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Crown of the World Random Encounters</TITLE>
</HEAD>
<BODY>

<script language="JavaScript">

// Some Arrays




rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
}

function rand(number) {
return Math.ceil(rnd()*number);
}

function tableResults(argument) {

var aquaticArray = [];
var forestArray = [];
var hillsArray = [];
var mountainsArray = [];
var tundraArray = [];

aquaticArray.push({"max": 18, "content": "1 draugr; CR 2; Bestiary 2 pg 110" });
aquaticArray.push({"max": 31, "content": "1 bunyip; CR 3; Bestiary 2 pg 50"});
aquaticArray.push({"max": 59, "content": "1 orca; CR 5; Bestiary pg 88"});
aquaticArray.push({"max": 72, "content": "1 selkie; CR 5; Pathfinder #50 pg 88"});
aquaticArray.push({"max": 84, "content": "1 glacier toad; CR 6; Bestiary 2 pg 268"});
aquaticArray.push({"max": 100,"content": "1 qallupilluk; CR 7; Pathfinder #51 pg 88"});


forestArray.push({"max": 16, "content": "1 hoarfrost spirit; CR 3; Pathfinder #51 pg 14"});
forestArray.push({"max": 29, "content": "1 ice troll; CR 4; Bestiary 2 pg 271"});
forestArray.push({"max": 58, "content": "1 winter wolf; CR 5; Bestiary pg 280"});
forestArray.push({"max": 68, "content": "1 glacier toad; CR 6; Bestiary 2 pg 268"});
forestArray.push({"max": 79, "content": "1 witchfire; CR 9; Bestiary 2 pg 284"});
forestArray.push({"max": 94, "content": "1 saumen kar; CR 10; Pathfinder #51 pg 90"});
forestArray.push({"max": 100, "content": "1 taiga giant; CR 12; Bestiary 2 pg 131"});


hillsArray.push({"max": 11, "content": "1 hoarfrost spirit; CR 3; Pathfinder #51 pg 14"});
hillsArray.push({"max": 24, "content": "1 ice troll; CR 4; Bestiary 2 pg 271"});
hillsArray.push({"max": 32, "content": "1 yeti; CR 4; Bestiary pg 287"});
hillsArray.push({"max": 42, "content": "1 winter wolf; CR 5; Bestiary pg 280"});
hillsArray.push({"max": 51, "content": "1 woolly rhinoceros; CR 6; Bestiary pg 235"});
hillsArray.push({"max": 59, "content": "1 frost drake; CR 7 Bestiary 2 pg 108"});
hillsArray.push({"max": 69, "content": "1 mastodon; CR 9; Bestiary pg 128"});
hillsArray.push({"max": 75, "content": "1 frost giant; CR 9 Bestiary pg 149"});
hillsArray.push({"max": 79, "content": "1 frostfallen mammoth; CR 10; Pathfinder #51 pg 84"});
hillsArray.push({"max": 88, "content": "1 saumen kar; CR 10; Pathfinder #51 pg 90"});
hillsArray.push({"max": 92, "content": "1 white pudding; CR 10; ToH pg 276"});
hillsArray.push({"max": 97, "content": "1 frost worm; CR 12; Bestiary 2 pg 126"});
hillsArray.push({"max": 100, "content": "1 taiga giant; CR 12; Bestiary 2 pg 131"});


mountainsArray.push({"max": 7, "content": "1 hoarfrost spirit; CR 3; Pathfinder #51 pg 14"});
mountainsArray.push({"max": 14, "content": "1 ice troll; CR 4; Bestiary 2 pg 271"});
mountainsArray.push({"max": 43, "content": "1 yeti; CR 4; Bestiary pg 287"});
mountainsArray.push({"max": 56, "content": "1 frost drake; CR 7 Bestiary 2 pg 108"});
mountainsArray.push({"max": 69, "content": "1 frost giant; CR 9 Bestiary pg 149"});
mountainsArray.push({"max": 75, "content": "1 witchfire; CR 9; Bestiary 2 pg 284"});
mountainsArray.push({"max": 84, "content": "1 frostfallen mammoth; CR 10; Pathfinder #51 pg 84"});
mountainsArray.push({"max": 92, "content": "1 saumen kar; CR 10; Pathfinder #51 pg 90"});
mountainsArray.push({"max": 100, "content": "1 frost worm; CR 12; Bestiary 2 pg 126"});


tundraArray.push({"max": 8, "content": "1 draugr; CR 2; Bestiary 2 pg 110"});
tundraArray.push({"max": 15, "content": "1 hoarfrost spirit; CR 3; Pathfinder #51 pg 14"});
tundraArray.push({"max": 22, "content": "1 ice troll; CR 4; Bestiary 2 pg 271"});
tundraArray.push({"max": 29, "content": "1 yeti; CR 4; Bestiary pg 287"});
tundraArray.push({"max": 40, "content": "1 winter wolf; CR 5; Bestiary pg 280"});
tundraArray.push({"max": 43, "content": "1 glacier toad; CR 6; Bestiary 2 pg 268"});
tundraArray.push({"max": 49, "content": "1 woolly rhinoceros; CR 6; Bestiary pg 235"});
tundraArray.push({"max": 54, "content": "1 frost drake; CR 7 Bestiary 2 pg 108"});
tundraArray.push({"max": 62, "content": "1 qallupilluk; CR 7; Pathfinder #51 pg 88"});
tundraArray.push({"max": 72, "content": "1 mastodon; CR 9; Bestiary pg 128"});
tundraArray.push({"max": 79, "content": "1 frost giant; CR 9 Bestiary pg 149"});
tundraArray.push({"max": 84, "content": "1 frostfallen mammoth; CR 10; Pathfinder #51 pg 84"});
tundraArray.push({"max": 89, "content": "1 saumen kar; CR 10; Pathfinder #51 pg 90"});
tundraArray.push({"max": 94, "content": "1 white pudding; CR 10; ToH pg 276"});
tundraArray.push({"max": 97, "content": "1 frost worm; CR 12; Bestiary 2 pg 126"});
tundraArray.push({"max": 100, "content": "1 taiga giant; CR 12; Bestiary 2 pg 131"});



var allArrays = {
"aquatic": aquaticArray,
"forest": forestArray,
"hills": hillsArray,
"mountains": mountainsArray,
"tundra": tundraArray
};

var randomNum = rand(100) + 1;
var arrayOfChoices = allArrays[argument];
if (!arrayOfChoices) {
return "no such set: " + argument;
}

var chosenString = "";
for (var itemIndex in arrayOfChoices) {
var item = arrayOfChoices[itemIndex];
if (randomNum <= item.max) {
chosenString = item.content;
break;
}
}
return chosenString;
}

</script>

<form>
<input type="button" name="Button1" value="Aquatic" onClick="this.form.textField1.value =

tableResults('aquatic')" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button2" value="Forest" onClick="this.form.textField1.value =

tableResults('forest')" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button3" value="Hills" onClick="this.form.textField1.value =

tableResults('hills')" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button4" value="Mountains" onClick="this.form.textField1.value =

tableResults('mountains')" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button5" value="Tundra" onClick="this.form.textField1.value =

tableResults('tundra')" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>

Last edited by jkthomsen9; August 10th, 2014 at 10:04 AM. Reason: Fixed break in code
jkthomsen9 is offline   #22 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 10th, 2014, 12:05 AM
Thank you to everyone that helped on this. I could never have done it on my own.
jkthomsen9 is offline   #23 Reply With Quote
AEIOU
Senior Member
 
Join Date: Jan 2012
Posts: 1,147

Old August 10th, 2014, 09:09 AM
As an armchair observer, this has been a wonderful thread to watch unfold. The code is clear and concise. The help back-and-forth made me smile. And the utility this adds to RW is amazing. Thank you to everyone!

EDIT: I'm not a programmer.... I directly cut/pasted the above code from the forum into a html snippet and it didn't work. Comparing to Mirtos' version it appeared that line breaks were not exact. After deleting the breaks after the mammoths and for each of the forms so they matched Mirtos' example, the code now works flawlessly. This could cause issues for others trying to walk in these footsteps so I wanted to point it out.

Last edited by AEIOU; August 10th, 2014 at 09:41 AM. Reason: Heads up to get code working from forum
AEIOU is offline   #24 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 10th, 2014, 10:07 AM
Good catch. I edited and fixed the problem. Not sure why that broke there. I just copied and pasted from notepad. I too am not a programer. Infact I learned a lot between the board and a friend that is. Is there a better program to test this in? I had a syntax error that caused the program to fail. I had no idea why it wasn't working as I got no error codes, it just didn't work. It took me about two hours to find it.
jkthomsen9 is offline   #25 Reply With Quote
Parody
Senior Member
 
Join Date: Jan 2013
Location: Rochester, MN
Posts: 1,516

Old August 10th, 2014, 11:50 AM
Feel free to test with whichever browser you normally use while making changes. Just make sure you also test in RW, and if you have problems then go to IE and see if things are different there than in your normal browser. (F12 opens the developer tools in IE11.)

If an error causes you to get a scripting/ActiveX warning (the yellow bar) in IE then it will silently fail in RW. The time it happened to me I had a comma in the wrong spot in my JavaScript. The error message was, sadly, completely unhelpful.

For editing I've been using Notepad++ and I let JSLint (via plugin) do some checking. Lints are always super picky and need their settings tweaked, but they can tell you things you aren't getting from elsewhere.

Parody is offline   #26 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 10th, 2014, 03:56 PM
Thanks Parody. LOL I did not know there was a better notepad. That is exactly what I had, a stray coma. Keep /* */ out portions till I narrowed it down to the right section.
jkthomsen9 is offline   #27 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 10th, 2014, 04:20 PM
i also normally like to put them in code blocks, so indenting is easier to read. ill do that from now on.

Notepad++ is my favorite editor... though im also a big fan of jedit as well (which requires java)
mirtos is offline   #28 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 10th, 2014, 04:42 PM
javascript errors (as opposed to things that arent supported) will generally appear in most of the major browsers. i personally like chromes debugging better than IEs, but thats just me.


Also, please feel free to post or PM any others if you need additional eyes to look at anything. I dont have RW at work, but i can often look at JS stuff at work.
mirtos is offline   #29 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 10th, 2014, 05:02 PM
Again Thank you to all. This was so much FUN that I decided to try it on a different random encounter chart. I got it to work more or less but there are a couple tweaks I would like to do to this one.

1. I would like the button at the top of the text verses the bottom.
2. I would like to bold the name of the encounter.
3. I noticed that it doesn't like +,-, or ' in the text....is there a way past that?




<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Varisia Caravan Encounters</TITLE>
</HEAD>
<BODY>

<script language="JavaScript">

// Some Arrays


rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
}

function rand(number) {
return Math.ceil(rnd()*number);
}

function tableResults(argument) {

var varisiaArray = [];

varisiaArray.push({"max": 15, "content": "Bad Weather: Fog, rain, high winds, or some other form of bad weather slows the caravan, reducing its overall speed by half for the day unless the caravan makes a DC 12 Security check." });
varisiaArray.push({"max": 30, "content": "Bandit Ambush (CR 2): The caravan must make a DC 15 Security check to notice this ambush in time to react; if this check fails, the caravan takes a –2 penalty to its Armor Class and on attack rolls for the first round of combat. The ambushers could be a group of bandits, a gang of highwaymen, or even a small tribe of Nolander barbarians. Regardless of their makeup, the ambushers’ stats and aggression are identical (AC 14; hp 20; Attack +4; Damage 2d6+3). They fight to the death. If defeated, 1 cargo unit of treasure worth 250 gp can be recovered."});
varisiaArray.push({"max": 50, "content": "Goblin Raiders (CR 1/2): A shrieking band of goblins wielding dogslicers and broken branches attacks the caravan (AC 11; hp 10; Attack +1; Damage 1d8). If the PCs have a horse train, the goblins are more timid than normal and take a –2 penalty on attack rolls. If defeated, a search of the goblins reveals a single cargo unit of treasure worth 125 gp."});
varisiaArray.push({"max": 55, "content": "Ogre Assault (CR 3): A small band of ogres lumbers out of the surrounding foliage to attack the caravan (AC 15; hp 30; Attack +6; Damage 3d4+6). The ogres flee if reduced below 10 hit points. If they are slain, looting produces 2 cargo units of treasure worth 400 gp each."});
varisiaArray.push({"max": 65, "content": "Treacherous Road: The road conditions become hazardous. They might be muddy, partially flooded, or even blocked by a fallen tree. The caravan must make a DC 14 Security check or lose 2d6 miles of progress for the day as the situation is dealt with."});
varisiaArray.push({"max": 100,"content": "Varisian Caravan: The PCs encounter another Varisian caravan heading in the opposite direction. With a DC 12 Resolve check, the PCs can befriend the other caravan. If this encounter occurs during the day, the caravan can give the PCs advice as to what lies ahead, reducing the chance of an encounter to 5% per day for the next 1d6 days. If the encounter occurs during the evening, the caravan agrees to share their camp, allowing the PCs to trade with them. The caravan can purchase up to 2,000 gp in objects, and can offer anything worth 600 gp or less for sale."});



var allArrays = {
"varisia": varisiaArray,
};

var randomNum = rand(100) + 1;
var arrayOfChoices = allArrays[argument];
if (!arrayOfChoices) {
return "no such set: " + argument;
}

var chosenString = "";
for (var itemIndex in arrayOfChoices) {
var item = arrayOfChoices[itemIndex];
if (randomNum <= item.max) {
chosenString = item.content;
break;
}
}
return chosenString;
}

</script>

<form>
<input type="button" name="Button1" value="Varisia Caravan Encounters" onClick="this.form.textField1.value = tableResults

('varisia')" size="" />
<textarea name="textField1" cols="40" rows="10" wrap="soft"></textarea>
</form>
jkthomsen9 is offline   #30 Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:57 AM.


Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.