Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Using a macro to roll a d20 and using the result to pull from the proper roll table

Hey everyone!  I have no clue how to code/use javascript.  My ask is this: I have already imported 3 different wild magic tables into their own and which one gets rolled on is based off of a d20 roll.  1-3 rolls on one table, 4-9 on the second table, 10+ on the last.  I'm looking for an API script that could use a macro's resulting d20 roll to roll on the proper table and give the result. 

As of right now, I gave the players 3 different macros to use (cleaner than table results):
&{template:npcaction} {{rname= Wild Magic}} {{name= 1-3}} {{description= [[1t[Wild-Magic-1-3]]] }}

&{template:npcaction} {{rname= Wild Magic}} {{name= 4-9}} {{description= [[1t[Wild-Magic-4-9]]] }}

&{template:npcaction} {{rname= Wild Magic}} {{name= 10+}} {{description= [[1t[Wild-Magic-10+]]] }}

The first action the player has to take though is roll a d20 to determine which macro to use.  

So to summarize, I'd like the API to roll a d20, then roll on the proper table based on the result.  I'm pretty sure this is possible, I just don't know how.


Thanks in advance!

If you assign the weights correctly these could be combined into a single rollable table. Multiply the weights for each tables entries, by the number of times in 20 that that subtable would be used.

For example:

Table 1 (1-3 on d20) has 5 equal chance entries

Table 2 (4-9 on d20) has 7 equal chance entries

Table 3 (10+ on d20) has only 3 entiries with weights 1, 2, and 3 respectively

weights would look like this: 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 11, 22, 33

May 25 (4 years ago)
GiGs
Pro
Sheet Author
API Scripter

There's an old script, Real Rollable Tables, that works for this: https://app.roll20.net/forum/permalink/1408851/

You can call it with

!rt table-name 3d6

There's a version of it lower down in the thread that works with Power Cards so you can use more complex formatting: https://gist.github.com/shdwjk/eda6313c93d51dbbfb8c. Though Power Cards has been updated many times since then, so you'd have to test it still works.


I recommend looking at The Aaron's script, Recursive Tables.  It is available from the one-click library.  You can set one macro to roll the d20, rolling on a rollable table which has for each value another, nested, rollable table.

The issue with this would be that there's 100 entries on each of the 3 tables.  So wouldn't the weight be 3 for everything on the 1-3 table, 6 for everything on the 4-9 table and 11 for everything on the 10+ table?

Seb_Romu said:

If you assign the weights correctly these could be combined into a single rollable table. Multiply the weights for each tables entries, by the number of times in 20 that that subtable would be used.

For example:

Table 1 (1-3 on d20) has 5 equal chance entries

Table 2 (4-9 on d20) has 7 equal chance entries

Table 3 (10+ on d20) has only 3 entiries with weights 1, 2, and 3 respectively

weights would look like this: 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 11, 22, 33




If you do it in two steps, using Recursive Tables, the first table has three entries, each with a weight (3, 6, and 11 as you have noted) and the child tables just has the list of entries with the default weight of 1.  There is another a script, TableExport, also available in the one-click, for importing table items from a text file in a format friendly to the API, so those very large tables would be manageable.