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

Macro For Running Script Dependent on A Roll Result

I am trying to set up a 5e game with a Wild Magic sorcerer. I have a script to be able to roll on the wild surge table, but I would like to set up a macro that first rolls a 1d20 and THEN rolls on the wild surge table ONLY if it gets a 1 on the d20. I currently have set up a macro that rolls both the d20 and also on the table at the same time: /r 1d20 !wildmagic But I would appreciate any help in making one dependent on the result of the other.
1665867064
Gauss
Forum Champion
Are any modifiers applied to the d20 roll? Please supply the full non-macro breakdown of what you want (modifiers etc).
1665867305

Edited 1665867478
Mark
Pro
No modifiers. It would basically be a token action for the wild magic sorcerer character that, when pressed: 1. Roll 1d20 (no modifiers) when token action button used. 2. If result of roll equals "1", run !wildmagic script/macro ( !wildmagic then runs an API script that I have working properly. Just not sure if it is possible to make a macro that makes running the macro depended on rolling a 1 when you hit the token action button)
1665868093

Edited 1665868177
Gauss
Forum Champion
I don't know of any macro which could spit out an API command as a result of the macro (although maybe someone else might know of an option).  You may need an API or a chat button to do this.  Now, on the other hand...what does the wildmagic script do? You may be able to get that into a macro instead of a script. 
Here's the text of it. Basically using the command "!wildmagic" causes it to roll 1d100 and display an entry based on the table. I found the script a year or two ago. Unfortunately I don't remember who made it. <a href="https://docs.google.com/document/d/1MlQhNNVnekx6hsWwDhPPnRdAMoipfgCGl6mk5sn9dcM/edit?usp=sharing" rel="nofollow">https://docs.google.com/document/d/1MlQhNNVnekx6hsWwDhPPnRdAMoipfgCGl6mk5sn9dcM/edit?usp=sharing</a>
1665877360
Gauss
Forum Champion
Could you summarize what the script does? My look at it (I don't know API code) seems to indicate that all it is is a table with multiple text outputs.&nbsp; If that is the case it can be reproduced in a table. Which then means you can make a macro for it.
1665879607

Edited 1665879976
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I would strongly recommend against that script. It does not seem to do anything that a rollable table wouldn't do, doesn't provide an automatic trigger or reminder (which IMO would be the only reason to use a mod script for this), and does not wrap its variables in an event handler or function. They are all exposed at the root level (not scoped) and could interfere with other scripts. Above and beyond all of that is that the Wild Magic table is not SRD content and is lifted directly from the Players Handbook. It's copyrighted material and should not be provided in a script. Is there a reason you want to use this other than a rollable table? If you have the PHB in any digital format, it's pretty easy to transform into commands usable by TableExport.&nbsp; I have a spreadsheet that does this here . Make a local copy, duplicate pages as you need more tables and go to town. Just copy the code parsed into the last column and use that with the&nbsp; Aaron's table import script . In this way, you could also spice up your table with some unexpected results.
Thanks Gauss and Keith. I had added the stuff for the PHB for my own game, but have taken it down. I'll try making the table. Thanks!
1665882416
GiGs
Pro
Sheet Author
API Scripter
I don't understand Keith's comment. There's nothing wrong with putting copyright content in a script. The problem is if you share that script with others 9which you shouldn't do). But using copyrwritten content in your own game - including that PHB stuff you had taken down - is perfectly fine.
1665887241

Edited 1665887275
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
GiGs said: I don't understand Keith's comment. There's nothing wrong with putting copyright content in a script. The problem is if you share that script with others 9which you shouldn't do). But using copyrwritten content in your own game - including that PHB stuff you had taken down - is perfectly fine. No, there's absolutely no problem with using copyrighted content in a script for your own personal use.&nbsp; The script as posted was shared in-forum. That's what I meant by " provided in a script". "Provided" as in made publicly available for others. The share link target has since been taken down. Innocent error, though. No blood, no foul.
1665907889
GiGs
Pro
Sheet Author
API Scripter
keithcurtis said: GiGs said: I don't understand Keith's comment. There's nothing wrong with putting copyright content in a script. The problem is if you share that script with others 9which you shouldn't do). But using copyrwritten content in your own game - including that PHB stuff you had taken down - is perfectly fine. No, there's absolutely no problem with using copyrighted content in a script for your own personal use.&nbsp; The script as posted was shared in-forum. That's what I meant by " provided in a script". "Provided" as in made publicly available for others. The share link target has since been taken down. Innocent error, though. No blood, no foul. Ah, I didn't realise it had been shared in the forum. Taking that down is sensible.
1665973810

Edited 1666137703
timmaugh
Pro
API Scripter
The metascript toolbox can accomplish this in a number of different ways, depending on how complex the set up is. The idea behind the toolbox is that you're altering the message (either the text of the command line or the other properties of the message -- selected tokens, rolls, etc.) before it reaches other scripts. 1 For a simple setup, you can use APILogic + ZeroFrame to establish an if-then based on your roll: !{&amp;if [[1d10]].value = 1}token-mod --set bar2|+1 {&amp;elseif $[[0]].value &lt;= 5}bump {&amp;else}Spawn --name|Giant Ape&nbsp; --qty|1 --size|2,2 --layer|object {&amp;end} That runs a TokenMod command on a result of 1, a Bump command on 2-5, or a Spawn command for everything else. 2 For a slightly more complex setup, you could use APILogic + ZeroFrame + Fetch. Fetch would let you stash in attributes or abilities the API commands you intend to run. Because they are referenced by a Fetch construction, they are retrieved during the metascript processing... *after* Roll20 has at the command line. For instance, if you took the TokenMod command, above, and put it in an ability named IncrementBar2 on the character, and you made sure the token representing that character were selected, you could reference it like: %(selected.IncrementBar2) *note: requires the Fetch 2.0 beta !{&amp;if [[1d10]].value = 1}%(selected.IncrementBar2) {&amp;elseif ... 3 Finally, for a more complex setup (let's say 5 or more potential outcomes), you could use Muler + ZeroFrame. Muler would store your commands as retrievable variables in a mule -- an ability on a character sheet structured like: 1=token-mod --set bar2|+1 2-5=bump &gt;=6=Spawn --name|GiantApe --qty|1 --size|2,2 --layer|object So all of your commands could be recorded in one place. Alternately, you could have an individual line reference an attribute or ability as necessary: 1=%(character name.IncrementBar2) *note: use the character's name, here, because selected tokens aren't a part of script-generated messages. Orrrrr.... include SelectManager (so we're now up to ZeroFrame, SelectManager, Muler, and Fetch) to be able to write that mule variable entry as: 1=%(selected.IncrementBar2) 4 Muler is currently in a refactor that should be done in a couple of days. The current public release will do the above just fine. However, the upcoming v2 will be able to use your Roll20 rollable table as a mule, so the actual location where you store your option will get more flexible for you.
Thanks&nbsp;timmaugh!