Last active
October 22, 2020 02:49
-
-
Save etkirsch/8bc032452788735219c1cad048a37c29 to your computer and use it in GitHub Desktop.
Simple "Count Successes from Nd6" Macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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