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 - same roll for two target numbers

I've tried to make a single roll macro that check against two increasing target numbers. But so far I've not been able to misuse the reuse of roll thing. I'm guessing I'm not good enough in writing it yet. Or they've fixed it? Here is the macro. Its trying to first check how many dice is at 4 or higher. But I also want it to tell me how many of them are 6. Possible? &{template:default} {{name=Dådslag}} {{[[?{Antall terninger|2}d6>4]](#)=Suksesser.}} {{[[?{Antall terninger|2}d6>6]](#)=Fremganger.}} {{[[[?{Antall terninger|d6]]](#)=}}
1612990636
GiGs
Pro
Sheet Author
API Scripter
Unfortunately this isnt something you can do with a macro. The Reusing Rolls method can only be usefd for rolls you can do in sequence, you cant use a roll and compare it to two different target numbers. Someone could write a custom API script for this.
Thanks for answering. Good to know it won't work, so I can stop trying to get it to behave as I want =D Not sure if I'll bother enough to write an API script for this....  Then again maybe one day at work I'll find some time =D Thx again!
1613000986

Edited 1613001517
Oosh
Sheet Author
API Scripter
I had a few minutes to spare, see if this is any good. You can change the success number at the top, and also the text string which will trigger the script. It will only trigger when it finds the search term and finds inline rolls with a d6. And the sendChat() line at the end, you probably want to localise to your language - I'm not sure how familiar you are with Javascript, but leave the surrounding ` backticks ` and everything inside ${ variable references } alone, but you can change the rest of the template like "results" "successes" and "sixes", or add more to the output. Oh, and you probably want to shorten the rolling macro to something like &{template:default} {{name=Dådslag}} {{[[?{Antall terninger|2}d6}} on('ready', () => { const successNumber = 4; // success number, equal or greater than const searchTerm = '{{name=Dådslag' // search string to trigger script on('chat:message', (msg) => { let rxContent = new RegExp(`${searchTerm}`,'i'); if (msg.content.match(rxContent) && msg.inlinerolls && msg.inlinerolls.length) { let rollData = msg.inlinerolls; let totalSixes = 0, totalTargetNum = 0; rollData.forEach(roll => { if (roll.expression && roll.expression.match(/\d+d6/)) { roll.results.rolls.forEach(subRoll => { let sixes = 0, targetNum = 0; if (subRoll.results) subRoll.results.forEach(die => { if (die.v >= successNumber) targetNum++; if (die.v === 6) sixes++; }); totalSixes += sixes; totalTargetNum += targetNum; }); } }); sendChat(msg.who,`&{template:default}{{name=Results}}{{=Successes: ${totalTargetNum}<br>Sixes: ${totalSixes}}}`); } }); });
Wow! Fantastic. This does indeed do what I'm looking for. The second output gives me both how many are 4 or and above, as well as how many are 6s. That it also give an output above with the total of the dices rolled I can easily live with i guess =D Two thumbs up dude
You can also do something like this with macros but instead of having two checks, use one check AND change the crit chance of the die roll to account for the occurrence of the other required number such that you’re looking for a green numeral and/or a successful check result.
1613138745
David M.
Pro
API Scripter
Looks like Oosh's solution was perfect, though if this kind of thing is something that comes up again I would also recommend checking out the new scriptcards script (the successor to powercards), which would allow you to re-use rolls, have conditional statements, and even implement loops and function calls in macros without having to write javascript or install additional custom scripts, making it more easily portable to new games. I've written a bunch of one-off scripts for folks, but I find myself transitioning to scriptcards more and more for these reasons, especially as Kurt keeps adding new features.