Skip to content

Instantly share code, notes, and snippets.

@etkirsch
Last active October 22, 2020 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etkirsch/8bc032452788735219c1cad048a37c29 to your computer and use it in GitHub Desktop.
Save etkirsch/8bc032452788735219c1cad048a37c29 to your computer and use it in GitHub Desktop.
Simple "Count Successes from Nd6" Macro
const evaluateSuccesses = (html) => {
const formula = html.find('.formula').val();
const targetValue = html.find('.target').val();
const rolls = new Roll(formula).roll();
rolls.target
const successes = rolls.dice[0].rolls.filter((indivRoll) => indivRoll.roll >= targetValue).length;
const messageData = {
flavor: `There were ${successes} successes with this roll (must exceed or equal ${targetValue})!`,
};
rolls.toMessage(messageData);
};
new Dialog({
title: 'Count Successes',
content: `
<form class="flexcol">
<div class="form-group">
<label for="formula">Formula</label>
<input type="text" value="6d6" class="formula" placeholder="6d6">
</div>
<label for="target">Target Value</label>
<input type="number" value="3" class="target" placeholder="3">
</div>
</form>
`,
buttons: {
no: {
icon: '<i class="fas fa-times"></i>',
label: 'Cancel'
},
yes: {
icon: '<i class="fas fa-dice-d20"></i>',
label: 'Roll',
callback: (html) => evaluateSuccesses(html),
},
},
default: 'Roll'
}).render(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment