Senior Member
Join Date: Oct 2011
Posts: 865
|
feel fre to upload it to my github page. the idea is so that people could put their stuff there and share it. part of the reason i made it public.
|
#61 |
Senior Member
Join Date: Aug 2013
Posts: 108
|
Okay,
I hope I did it right as I've never used a repository before. |
#62 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
if you want, I can do it (or you can create a github account and upload to my repository)
|
#63 |
Senior Member
Join Date: Oct 2011
Posts: 118
|
OK - next question my java experts.
I am now working on the random encounters for Kingmaker part 2 and some of the encounters call for 2d4 of a creature. Obviously the 'Rand ()' function I have been using wont work for 2 dice, so what function do I need to use? Thankyou in Advance |
#64 |
Senior Member
Join Date: Apr 2014
Location: California
Posts: 295
|
you can do one of two things.
First, 2d4 is 7 possible values (2 to 8) so you could just use the same random function with 7 as the highest value possible then add one (+1) to get a range of 2 to 8. Second, you could call the random 4 value twice storing the results in two separate variables (call the variables DieRoll1 and DieRoll2) and then add the two variables together to get the final result. I'm sure someone will come along to give you the actual code. Personally, I'd go with the first option but that's just me. |
#65 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
the problem with that is that it skews the probabilities.
you have a one in 7 chance of getting a 2 with your probabilities, and a 1 in 7 chance of getting a 5. but in 2d4, there are multiple ways of getting a 5 1,4 2,3 3,2 4,1 4 chances out of a total 16. (1 in 4) whereas the chance of getting 2 or 8 is actually 1 in 16 for either. (there are actually 16 different combinations when rolling 2d4) 2 dice skew to the middle, but make it much harder to get either the min or the max. |
#66 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
we can add a new method that uses the existing rand method
Code:
function randDice(numDice, diceType, modifier) { var total = 0; if (!numDice) { numDice) = 1; } for (i = 0; i < numDice; i++) { total += rand(diceType); } if (modifier) { total += modifier; } return total; } randDice(2,4) 2d4+3 would be called by randDice(2,4,3) its not the prettiest version. i can write a prettier one later Last edited by mirtos; September 2nd, 2014 at 06:13 AM. |
#67 |
Senior Member
Join Date: Aug 2013
Posts: 108
|
If you look at my RotRL Encounter tables, I just did rand(4) + rand(4) in the honoured KISS method. :-)
Last edited by Farnaby; September 3rd, 2014 at 11:30 PM. |
#68 |
Senior Member
Join Date: Oct 2011
Posts: 118
|
Quote:
(no programming skills, remember?) OK - I have now completed the random chart for Kingmaker book 2 (posted below). Cleaned up the code a bit and put everything in order too. Will try to up load to github, but not sure how to do so....might be a trial and error thing....! *Edit* I tried to upload the file, but it got 'forked' (no really, that is actually the word the site used, not the other thing ). Then I created a 'pull' request. Not sure if successful or not. Let me know if there is anything else I need to do. Code:
<HTML> <HEAD> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <TITLE>Kingmaker - Rivers Run Red</TITLE> </HEAD> <BODY> <script language="JavaScript"> // Some Arrays function rand(x) { return Math.floor(Math.random() * x) + 1; } function tableResults(argument) { var hexencounterArray = []; var DayornightArray = []; var forestArray = []; var lakeArray = []; var plainsArray = []; var hillsArray = []; hexencounterArray.push({"max": 5, "content": "Random Encounter"}); hexencounterArray.push({"max": 100, "content": "No Encounter"}); DayornightArray.push({"max": 15, "content": "Random Encounter"}); DayornightArray.push({"max": 100, "content": "No Encounter"}); forestArray.push({"max": 5, "content": "1 barghest; CR 4"}); forestArray.push({"max": 13, "content": rand(8) + " Boars; CR 6"}); forestArray.push({"max": 17, "content": rand(4) + rand (4) + " boggards; CR 3"}); forestArray.push({"max": 23, "content": rand(6) + " brush thylacines; CR 5"}); forestArray.push({"max": 29, "content": rand(6) + rand(6) + " elk; CR 6"}); forestArray.push({"max": 35, "content": "1 faerie dragon; CR 2"}); forestArray.push({"max": 42, "content": rand(4) + rand(4) + " giant Spiders; CR 5"}); forestArray.push({"max": 49, "content": rand(4) + " grizzly bears; CR 6"}); forestArray.push({"max": 53, "content": "1 hydra; CR 4"}); forestArray.push({"max": 57, "content": "1 manticore; CR 5"}); forestArray.push({"max": 63, "content": "1 owlbear; CR 4"}); forestArray.push({"max": 68, "content": "1 shambling mound; CR 6"}); forestArray.push({"max": 71, "content": rand(6) + " shocking lizards; CR 5"}); forestArray.push({"max": 75, "content": rand(6) + " tatzlwyrms; CR 5"}); forestArray.push({"max": 79, "content": rand(4) + rand(4) + " trolls; CR 9"}); forestArray.push({"max": 82, "content": "1 werewolf; CR 2"}); forestArray.push({"max": 85, "content": "1 will o wisp; CR 6"}); forestArray.push({"max": 93, "content": rand(6) + rand(6) + " wolves; CR 6"}); forestArray.push({"max": 97, "content": rand(6) + rand(6) + " worgs; CR 7"}); forestArray.push({"max": 100, "content": "1 wyvern; CR 6"}); lakeArray.push({"max": 3, "content": "1 barghest; CR 4"}); lakeArray.push({"max": 10, "content": rand(8) + " Boars; CR 6"}); lakeArray.push({"max": 17, "content": rand(4) + rand (4) + " boggards; CR 3"}); lakeArray.push({"max": 21, "content": rand(6) + " brush thylacines; CR 5"}); lakeArray.push({"max": 28, "content": rand(6) + rand(6) + " elk; CR 6"}); lakeArray.push({"max": 32, "content": "1 faerie dragon; CR 2"}); lakeArray.push({"max": 35, "content": rand(4) + rand(4) + " giant Spiders; CR 5"}); lakeArray.push({"max": 41, "content": rand(4) + " grizzly bears; CR 6"}); lakeArray.push({"max": 47, "content": "1 hydra; CR 4"}); lakeArray.push({"max": 54, "content": "1 nixie; CR 1"}); lakeArray.push({"max": 59, "content": "1 owlbear; CR 4"}); lakeArray.push({"max": 68, "content": "1 shambling mound; CR 6"}); lakeArray.push({"max": 75, "content": rand(6) + " shocking lizards; CR 5"}); lakeArray.push({"max": 79, "content": rand(6) + " tatzlwyrms; CR 5"}); lakeArray.push({"max": 83, "content": rand(4) + rand(4) + " trolls; CR 9"}); lakeArray.push({"max": 88, "content": "1 will o wisp; CR 6"}); lakeArray.push({"max": 94, "content": rand(6) + rand(6) + " wolves; CR 6"}); lakeArray.push({"max": 98, "content": rand(6) + rand(6) + " worgs; CR 7"}); lakeArray.push({"max": 100, "content": "1 wyvern; CR 6"}); plainsArray.push({"max": 4, "content": "1 barghest; CR 4"}); plainsArray.push({"max": 15, "content": rand(8) + " Boars; CR 6"}); plainsArray.push({"max": 20, "content": rand(6) + " brush thylacines; CR 5"}); plainsArray.push({"max": 28, "content": rand(6) + rand(6) + " elk; CR 6"}); plainsArray.push({"max": 32, "content": "1 faerie dragon; CR 2"}); plainsArray.push({"max": 38, "content": rand(4) + rand(4) + " giant Spiders; CR 5"}); plainsArray.push({"max": 40, "content": rand(4) + " grizzly bears; CR 6"}); plainsArray.push({"max": 51, "content": rand(6) + rand(6) + " Kobolds; CR 2"}); plainsArray.push({"max": 54, "content": "1 manticore; CR 5"}); plainsArray.push({"max": 59, "content": "1 owlbear; CR 4"}); plainsArray.push({"max": 63, "content": "1 shambling mound; CR 6"}); plainsArray.push({"max": 66, "content": rand(6) + " tatzlwyrms; CR 5"}); plainsArray.push({"max": 71, "content": rand(4) + rand(4) + " trolls; CR 9"}); plainsArray.push({"max": 75, "content": "1 werewolf; CR 2"}); plainsArray.push({"max": 77, "content": "1 will o wisp; CR 6"}); plainsArray.push({"max": 86, "content": rand(6) + rand(6) + " wolves; CR 6"}); plainsArray.push({"max": 95, "content": rand(6) + rand(6) + " worgs; CR 7"}); plainsArray.push({"max": 100, "content": "1 wyvern; CR 6"}); hillsArray.push({"max": 7, "content": "1 barghest; CR 4"}); hillsArray.push({"max": 14, "content": rand(8) + " Boars; CR 6"}); hillsArray.push({"max": 19, "content": rand(6) + " brush thylacines; CR 5"}); hillsArray.push({"max": 27, "content": rand(6) + rand(6) + " elk; CR 6"}); hillsArray.push({"max": 30, "content": "1 faerie dragon; CR 2"}); hillsArray.push({"max": 35, "content": rand(4) + rand(4) + " giant Spiders; CR 5"}); hillsArray.push({"max": 43, "content": rand(6) + rand(6) + " Kobolds; CR 2"}); hillsArray.push({"max": 45, "content": "1 manticore; CR 5"}); hillsArray.push({"max": 53, "content": "1 owlbear; CR 4"}); hillsArray.push({"max": 58, "content": "1 shambling mound; CR 6"}); hillsArray.push({"max": 65, "content": rand(6) + " tatzlwyrms; CR 5"}); hillsArray.push({"max": 70, "content": rand(4) + rand(4) + " trolls; CR 9"}); hillsArray.push({"max": 74, "content": "1 werewolf; CR 2"}); hillsArray.push({"max": 81, "content": "1 will o wisp; CR 6"}); hillsArray.push({"max": 88, "content": rand(6) + rand(6) + " wolves; CR 6"}); hillsArray.push({"max": 95, "content": rand(6) + rand(6) + " worgs; CR 7"}); hillsArray.push({"max": 100, "content": "1 wyvern; CR 6"}); var allArrays = { "Hex": hexencounterArray, "DayNight": DayornightArray, "lake": lakeArray, "forest": forestArray, "hills": hillsArray, "plains": plainsArray }; 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> As the PCs enter a hex, hit the button to see if there is an encounter (5% chance) <form> <input type="button" name="Button1" value="Hex Encounter" onClick="this.form.textField1.value = tableResults('Hex')" size="" /> <textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea> </form> For each day or night cycle spent exploring, hit the button to see if there is an encounter (15% chance) <form> <input type="button" name="Button2" value="Day or Night encounter" onClick="this.form.textField1.value = tableResults('DayNight')" size="" /> <textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea> </form> If there is a random encounter, hit the button of the corresponding terrain to generate an encounter. <form> <input type="button" name="Button3" 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="Button4" value="Lake/River" onClick="this.form.textField1.value = tableResults('lake')" size="" /> <textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea> </form> <form> <input type="button" name="Button5" value="Plains" onClick="this.form.textField1.value = tableResults('plains')" size="" /> <textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea> </form> <form> <input type="button" name="Button6" value="Hills" onClick="this.form.textField1.value = tableResults('hills')" size="" /> <textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea> </form> </BODY> </HTML> Last edited by Jaynay27; September 3rd, 2014 at 12:38 AM. |
|
#69 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
I have merged both of your code back in, so all three files are up there.
|
#70 |
|
|