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 .
×

Specific Roll Macro Help Request

I have a roll macro I'm trying to create, but I'm unable to figure out how to design it myself. Roll 2d10. Compare to an attribute. If the lower of the two dice is equal or less than the attribute, output the sum of the dice. If the lower of the two dice is greater than the attribute, output only the highest die. Thanks in advance for any advice! :)
1597966707
Oosh
Sheet Author
API Scripter
You'll need a custom API script for that. As soon as you get to the Attribute comparison with regular dice, you're losing the ability to add or multiply them. I'm pretty sure this is  the closest you can get with a regular macro: &{template:default}{{name=Roll Stuff}} {{[0](#)=Multiply the numbers}} {{[1](#)=Add the numbers}} {{[[[{[[1d10]],[[1d10]]}kl1>?{Attribute?|5}]]](#)=$[[0]] and $[[1]]}} Very hacky, and it can't do the sum or multiply for you.
1597973757

Edited 1597977385
Thanks, Oosh.  Your macro is better than mine, so that's a step in the right direction! I'll have to consider whether I will work on a custom API script. (Edit): Well, I tried fiddling with that macro and still couldn't get it to work out that well.  I guess I'll have to try to work a script.
1597980224
David M.
Pro
API Scripter
Here's a really quick & dirty script. Not the prettiest output, but seems like it works. on('ready',function() { on('chat:message',function(msg){ if(msg.type=='api' && msg.content.indexOf('!2d10')==0) { try { const macroName = '2d10'; let result; who = getObj('player',msg.playerid).get('_displayname'); let args = msg.content.split(/\s+/); args.shift(); let r = [randomInteger(10), randomInteger(10)].sort((a,b)=>a-b); let displayRolls = '[[' + r[0] + ']] & [[' + r[1] + ']] vs. target [[' + args[0] + ']]'; if (r[0] <= parseInt(args[0])) { //lowest roll less than or equal to target, output sum result = '[[' + (r[0] + r[1]) + ' Using sum of dice]]'; } else { //lowest roll greater than target, output highest die result = '[[' + r[1] + ' Using highest die]]'; } let output = `&{template:default} {{name=${macroName}}} {{Rolls=${displayRolls}}} {{Result=${result}}}`; sendChat('', output); } catch(err) { sendChat('',`/w "${who}" `+ 'Error: ' + err.message); } } }); }); Call it like this: !2d10 @{charName|attribute}
Wow, David, thanks so much for taking the time to write up that script.  It's fantastic.  It's doing just what I need!
1598030969
David M.
Pro
API Scripter
Great! No worries, didn't take long since I just modified it from an older script. 
I've been fiddling with the output, and there's something I don't understand how to do. I'd like to display the name of the Attribute that it uses as the target, but I can't figure how how your script works to identify that so I can add it to the output.
1598036422

Edited 1598036547
David M.
Pro
API Scripter
Only the value of the attribute is passed to the script, not the actual name. Here is another version that accepts an optional argument for attribute name that will show up as a tooltip when you mouse over the target number. on('ready',function() { on('chat:message',function(msg){ if(msg.type=='api' && msg.content.indexOf('!2d10')==0) { try { const macroName = '2d10'; let result; let displayRolls who = getObj('player',msg.playerid).get('_displayname'); let args = msg.content.split(/\s+/); args.shift(); let r = [randomInteger(10), randomInteger(10)].sort((a,b)=>a-b); if (args.length > 1) { displayRolls = '[[' + r[0] + '(1d10)]] & [[' + r[1] + '(1d10)]] vs. target [[' + args[0] + ' (' + args[1] + ')]]'; } else { displayRolls = '[[' + r[0] + '(1d10)]] & [[' + r[1] + '(1d10)]] vs. target [[' + args[0] + ']]'; } if (r[0] <= parseInt(args[0])) { //lowest roll less than or equal to target, output sum result = '[[' + (r[0] + r[1]) + ' (Using sum of dice)]]'; } else { //lowest roll greater than target, output highest die result = '[[' + r[1] + ' (Using highest die)]]'; } let output = `&{template:default} {{name=${macroName}}} {{Rolls=${displayRolls}}} {{Result=${result}}}`; sendChat('', output); } catch(err) { sendChat('',`/w "${who}" `+ 'Error: ' + err.message); } } }); }); args[1] is the array element that holds the name of the attribute, if you want it somewhere else in the output. You can now call the script in one of the following ways: !2d10 @{charName|attribute} !2d10 @{charName|attribute} attributeName !2d10 anyNumber anyText_no_spaces  
Cool.  Thanks, David :)