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

Evaluating A Result In A Macro

I am sorry if this has been answered before, but I have been searching and not finding in the forums.

I am trying to write a macro (actually a series of macros) that will do a thing only if a roll evaluates to a certain threshold. Otherwise, they will do something else. For example, maybe the roll is 3d6, and the character will hit on a 12 or less and miss otherwise. I am trying to make a macro that will generate just the output of HIT or MISS. It would be great if the roll is visible, as well, but the main thing is getting the result after evaluation. Any way to do that?

May 16 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

Standard macros cannot do conditional effects, like having one thing happen if you roll above a threshold, and a different thing if you roll less.

You're a Pro user so if you're the GM, you can use API scripts, which can do that, but it requires an API script. And writing API scripts is not like writing macros: they serve specific uses, and you need to program for every condition. And you need to be familiar with Javascript.

With more specifics - like what do you want to happen on a HIT and a MISS - we could help more.

I appreciate the willingness to help. I was hoping for a rather open-ended tool for my toolbox so I could use it in a bunch of SUCCESS/FAIL scenarios. I could see such a generic thing being useful in a bunch of games. Input the test (i.e. 3d6), input the target (i.e. a number or an attribute from a character, like 12 or @{Bob|STR}), input the yes result (i.e. send this to the chat window, like /em succeeds), and input the no result (i.e. send this to the chat window, like /em fails).

I could see lots of uses for it.

May 16 (5 years ago)

Edited May 16 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

That could be done. You could have a script which you run something like

!yesno --test:[[3d6]] --target:@{Bob|12} --yes: whatever happens on yes --no:whatever happens on no

You might also need --origin:@{fred|character_id} depending on what yes/no actually does.

What sort if things do you foresee yes/no results including, to get an idea of how tricky it would be to program? If its essentially just a text message, this is a pretty easy script.

May 16 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

Here's a script that accepts the following syntax

!hitormiss --name: a name --roll:[[3d6]] --target:@{bob|AC} --hit: what happens on a hit --miss: what happens on a miss 

It returns the roll, and the relevant result of hit and miss, using the default template for simplicity.

    --name is optional, the others are required, and roll and target must resolve to numbers (dice rolls are fine, but referring to attributes that are not numeric will throw a warning).


It assumes you have to roll equal to or higher than the target. Is that correct?

https://gist.github.com/G-G-G/7993a0a72db66f8da49286bde7a1b790

Awesome. I can work with it, whether it is above or below with a little simple math, I believe.

Thanks!

May 17 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

Line 58 has the comparison >=. If your system is meant to be equal or less, just swap that to <=.

If you need to handle both, just say so and I'll tweak it so you can declare which on a case by case basis.

Thanks. I had looked at the code and found the compare. One thing I could not figure out, though, is how to unwrap the output. You made it nice and packaged, but what I was really looking for was something that could throw a macro or ability at the chat and have it fire off. I probably didn't communicate that very clearly.

My success and failure outputs might include #feeding-frenzy or %buff-bob or a chat command like /em trips over her own feet and stumbles past her target.

Is that difficult to do?

May 17 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

That gets a lot more complex. Scripts need to be programmed for specific kinds of output and cant handle just anything you'd throw at them.

I could change the outrput so its not packaged in a rolltemplate and just prints to chat whatever you put in the hit or miss sections. The difficulty is then how do you want to display the roll?



Displaying the roll is secondary. Many times, the roll won't necessarily even be a roll. Just a number. This tool is meant to be a generic answer to a lot of questions.

May 18 (5 years ago)

Edited May 18 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

I've made a quick-and-dirty update to the script to add the ability to just send the hit or miss results to chat. So you can do

!hitormiss --name: a name --roll:[[3d6]] --target:@{bob|AC} --hit: #A-MACRO --miss: %{character|an-ability}

And it will run those.

It wont print out the number when doing this. There's no way to tell what your hit or miss outputs will look like, so hard to know how to format the roll to fit those outputs. If you want to include a roll in a header that gets posted before those outputs, i can add it. I just need you to know what it should contain.


You can still get the old template view by adding --template in the command. It doesnt need a value: this is fine - 

!hitormiss --name: a name --roll:[[3d6]] --target:@{bob|AC} --hit: what happens on a hit --miss: what happens on a miss --template
!hitormiss --name: a name --roll:[[3d6]] --target:@{bob|AC} --hit: this is a multiline statement
it continues on this line --miss: what happens on a miss 


You can also now include multi-line statements in the hit or miss lines, but must enclose them within {{ }} brackets, like so:

!hitormiss --name: a name --roll:[[3d6]] --target:@{bob|AC} --hit: {{this is a multiline statement
it goes on 
and on
over multiple lines }} --miss: {{note that that the --miss statement
must be on the same line as the close brackets at the end of the hit statement.}}

If you want to include {{ }} characters within multi-line hit or miss results (such as when outputting another roll template), you must convert them into html entities. Calls to macros or abilities dont require editing.

If there's interest to be able to do this, and can handle it more elegantly.

Here's the script

https://gist.github.com/G-G-G/7993a0a72db66f8da49286bde7a1b790

Wow! Thank you much! I will give this script a test and see how it works. I appreciate your effort on this a lot.

I don't anticipate needing double brackets currently, but I'm learning at warp speed, so that might change.


Since you mentioned it, I was reading about roll templates, and I mostly get it, but I am wondering about creating my own properties. How does a roll get those properties?

I saw an example of {{atteffect}} or something like that. So, if I send an inline roll to the roll template, how does it know if the roll has atteffect? Do those properties have to be declared explicitly as part of the roll?

May 18 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

The mention of rolltemplates made me realise there's a script that might do what you want and more, called Power Cards. You can get it from the one click install. It is a very complex script so not easy to get started with, but does have a dedicated thread for help.


To answer your question: you can learn how rolltemplates work here: https://wiki.roll20.net/Roll_Templates

But basically, yes, each property has to be specifically programmed for. Character sheets include rolltemplates for that specific sheet, and prepare properties that they know the rolls for that system need. 

The rolltemplate function in the character sheet will have a section of code that tests specifically for atteffect, and knows what to do when it finds it. Every property that has a different effect will be tested, and handled differently.


Power Cards is a script that dates from before roll20 had rolltemplates, and was created to provide complex formatting applied to rolls and chat output, and is more flexible (and more complex) than rolltemplates. 


So if there is a small set of simple properties you want to use, I might be able to incorporate them in my script, but if you want full flexibility, power cards will likely do the job better.