• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Random Tables lookups?

I was wondering if I just haven't see the feature or it isn't there, but is there a way as a GM to create a random table.

Seems like it would be a custom snippet that would allow you to give the number of rows in the table, and the table would have a roll number and then description. Then you would have an option to "roll" the dice to look up in the table.

something like fumbles:

1 - Your incompetent blow makes you the laughing stock
2 - You damage yourself
 
I couldn't find a way to do this, but I was able to create one using html attachments. It would be by nice if this was a feature in line, but I figured I would share what I did, in case others have the same use.

I come across a lot of tables that you roll results for (such as critical hit lists or miss lists), so I wanted some way to have a button that randomly selects from that list.

What I did was a simple javascript and I do an add HTML (complete) to have the javascript code, then you can select the html and it will pull it up. here is an example:

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Moods and Attitudes</TITLE>
</HEAD>
<BODY>

<script language="JavaScript">
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 makeArray(n) {
this.length = n;
for(var i = 1; i <= n; i++)
this = "";
return this;
} ;// End of function makeArray

function BitchRule() {
var WIndex = rand(6) ;
RClass = new makeArray(7);
RClass[0] = "happy, cheerful, optimistic, helpful, friendly";
RClass[1] = "happy, cheerful, optimistic, helpful, friendly";
RClass[2] = "self-pity, unhelpful, brooding, pessimistic";
RClass[3] = "pissed off, vengeful, cruel";
RClass[4] = "playful, energetic, daring, foolhardy, practical joker";
RClass[5] = "vain, proud, lazy, bored, omnipotent feeling";
RClass[6] = "restless, impatient, takes control, urge to get on with things, roll 1d6 for obsession check";
return RClass[WIndex];
};
</script>

<form>
<input type="button" name="Button1" value="Moods and Attitudes" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>
 
Oh, this is awesome! If someone could do this for a variety of tables I use, I would be so happy!

Either that, or it's time I start learning how to code. :)
 
Nice, I use Inspiration Pad Pro and just put the table files directly in RW as attachements, but that looks like it'd work as well.
 
This is great.

Could someone who can code please modify the above code to roll a percentile instead of a D6, and make the results a range vs a single digit. I would like to use it as a random encounter generator.
 
easy enough. but how many options do you want, and do you want it evenly distributed, if not, please provide the numbers.

Thanks. Range vs a single digit is still a percent, but happy to do so.
 
ok, here you go. I changed a couple things.

1. array can be any size (you dont need a makeArray method)
2. using "ranges" (technically percentile from 1-100) it actually only looks at the max. (you dont need to specify a min)

Now i havent tried this inline yet, but this is vanilla javascript.


<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Moods and Attitudes</TITLE>
</HEAD>
<BODY>

<script language="JavaScript">
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 BitchRule() {
var randomNum = rand(100) + 1;
console.log(randomNum);
var arrayOfChoices = [];
arrayOfChoices.push( {"max": 15, "content": "happy, cheerful, optimistic, helpful, friendly" });
arrayOfChoices.push({"max": 30, "content": "happy, cheerful, optimistic, helpful, friendly"});
arrayOfChoices.push({"max": 45, "content": "self-pity, unhelpful, brooding, pessimistic"});
arrayOfChoices.push({"max": 60, "content": "pissed off, vengeful, cruel"});
arrayOfChoices.push({"max": 75, "content": "playful, energetic, daring, foolhardy, practical joker"});
arrayOfChoices.push({"max": 99, "content": "vain, proud, lazy, bored, omnipotent feeling"});
arrayOfChoices.push({"max": 100,"content": "restless, impatient, takes control, urge to get on with things, roll 1d6 for obsession check"});

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="Moods and Attitudes" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>
 
btw, if you dont like the "max" and "content", i could easily make it more array/index based, i just prefer that because its easier to look at the code, and if you want to add other pieces of data, you could. (say you had two fields, one for a short description, one for a long description)
 
Thank You Mirtos. There seems to be something wrong with the code. Nothing displays when to click the button. I have started to modify the code to become the Crown of the World Random Encounter table. This is what I have so far. Not sure what values to change to make a different array for each button. Again thank you mirtos for your help.

<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">
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 BitchRule() {
var randomNum = rand(100) + 1;
console.log(randomNum);
var arrayOfChoices = [];
arrayOfChoices.push( {"max": 18, "content": "1 draugr; CR 2; Bestiary 2 110" });
arrayOfChoices.push({"max": 31, "content": "1 bunyip; CR 3; Bestiary 2 50"});
arrayOfChoices.push({"max": 59, "content": "1 orca; CR 5; Bestiary 88"});
arrayOfChoices.push({"max": 72, "content": "1 selkie; CR 5; Pathfinder #50 pg 88"});
arrayOfChoices.push({"max": 84, "content": "1 glacier toad; CR 6; Bestiary 2 268"});
arrayOfChoices.push({"max": 100,"content": "1 qallupilluk; CR 7; Pathfinder #51 pg 88"});

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 = BitchRule()" 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 = BitchRule()" 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 = BitchRule()" 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 = BitchRule()" 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 = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>
 
Last edited:
This particular encounter table has twenty different outcomes based on five different terrains. Some have five or six outcomes others have all but three.
 
im confused... is it working, or not working for you? It works for me in a browser, but havent tried it directly in RealmWorks

This is starting to get complicated, but i'd suggest modifying the function to determine which set of tables to use...
 
ok, here is the latest. Ive done forest and aquatic for you. You will need to do the rest. Tested in a browser, but not Realm Works:

Code:
<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


var forestArray = [];
var aquaticArray = [];

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


aquaticArray.push({"max": 70, "content": "another shark"});
aquaticArray.push({"max": 100, "content": "a nice dolphin"});


var allArrays = {
	"forest": forestArray,
	"aquatic": aquaticArray
};

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 randomNum = rand(100) + 1;
	console.log(randomNum);
	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()" 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()" 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()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>
 
i put it in a code block to keep the formatting (easy to follow when you have multiple blocks).

I changed a method name, and now the method requires an argument, for your code.
 
by the way, we're starting to get complicated. something like jquery would start to be better. but i dont know if realms works can handle external javascript libraries or not.
 
Last edited:
Here is a slightly nicer, cleaner version. not much, but a little.

I dont think you need the input box. You could style the result tag a little nicer.

Slightly better formatted to (even though i hate using table formatting, i just dont know what html engine Realm Works is using)

<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


var forestArray = [];
var aquaticArray = [];

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


aquaticArray.push({"max": 70, "content": "another shark"});
aquaticArray.push({"max": 100, "content": "a nice dolphin"});


var allArrays = {
"forest": forestArray,
"aquatic": aquaticArray
};

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(el, argument) {
var randomNum = rand(100) + 1;

var arrayOfChoices = allArrays[argument];
var chosenString = "";
if (!arrayOfChoices) {
chosenString = "no such set: " + argument;
} else {
for (var itemIndex in arrayOfChoices) {
var item = arrayOfChoices[itemIndex];
if (randomNum <= item.max) {
chosenString = item.content;
break;
}
}
}

var resultSection = el.parentNode.parentNode.getElementsByClassName('results')[0];
resultSection.innerHTML = chosenString;
}

</script>

<table>
<tr>
<td><input type="button" value="Aquatic" onClick="tableResults(this, 'aquatic')" size=""/></td>
<td><span class="results"></span>
</tr>
<tr>
<td><input type="button" value="Forest" onClick="tableResults(this, 'forest')" size=""/></td>
<td><span class="results"></span>
</tr>
<tr>
<td><input type="button" value="Hills" onClick="tableResults(this, 'hills')" size=""/></td>
<td><span class="results"></span>
</tr>
</table>
</form>

</BODY>
</HTML>
 
Last edited:
i guess i should test in realms work before i put up. looks like it might be using a different javascript engine.
 
I just tried the first one. got it to work while rmeoving the console.log statement... (debugging statement).

Couldnt get the second one to work... looks like whatever JS engine is being used it doesnt know the parentdom stuff.

When i was doing it all earlier i wasnt by realms works... tested, now it works (well one of them does) It would be interesting to know what JS engine is being used.


You could do a table with ids or something, but you can use the first one:


<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 forestArray = [];
var aquaticArray = [];

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


aquaticArray.push({"max": 70, "content": "another shark"});
aquaticArray.push({"max": 100, "content": "a nice dolphin"});


var allArrays = {
"forest": forestArray,
"aquatic": aquaticArray
};

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()" 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()" 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()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>
 
Last edited:
Realm Works (likely via the .NET WebBrowser control) uses the engine from the main version of IE installed on your machine. I have IE11 and the User Agent for Realm Works is:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)

It'll navigate to other websites and run plugins if you want. I wouldn't recommend using external resources but you likely can. At that point, though, why not just link to a page on the Internet? The "local" page won't work without Internet access anyway.
 
Last edited:
Back
Top