Created
December 19, 2019 19:21
-
-
Save birdbrainiac/ade55dfa293ef880b132a42d5c0487c6 to your computer and use it in GitHub Desktop.
roll a bunch of stats and sum their total
This file contains hidden or 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
/* | |
Roll a bunch of stats and total them. Use syntax like this: | |
!sumstatrolls --{{name= Stat Rolls 4d6k3}} {{Strength= [[4d6k3]]}} {{Dexterity= [[4d6k3]]}} {{Constitution= [[4d6k3]]}} {{Intelligence= [[4d6k3]]}} {{Wisdom= [[4d6k3]]}} {{Charisma= [[4d6k3]]}} | |
or | |
!sumstatrolls --{{name= Stat Rolls 4d6k3}} {{Rolls=**[[4d6k3]] [[4d6k3]] [[4d6k3]] [[4d6k3]] [[4d6k3]] [[4d6k3]]**}} | |
*/ | |
on("ready", () => { | |
const template = '&{template:default}', | |
sumheader = 'Average Score', | |
macroname = 'roll-6-stats', | |
processInlinerolls = function (msg) { | |
if (_.has(msg, 'inlinerolls')) { | |
return _.chain(msg.inlinerolls) | |
.reduce(function(previous, current, index) { | |
previous['$[[' + index + ']]'] = current.results.total || 0; | |
return previous; | |
},{}) | |
.reduce(function(previous, current, index) { | |
return previous.replace(index, current); | |
}, msg.content) | |
.value(); | |
} else { | |
return msg.content; | |
} | |
}, | |
totalInlinerolls = function(msg) { | |
let total = 0; | |
if (_.has(msg, 'inlinerolls')) { | |
total = msg.inlinerolls.reduce((total,current) => total + current.results.total ||0,0); | |
}; | |
return total > 0 ? Math.floor((total / msg.inlinerolls.length)*10)/10 : total; | |
}; | |
on("chat:message", msg_orig => { | |
if(msg_orig.type == "api" && (msgMatch = msg_orig.content.match('!sumstatrolls --'))){ | |
const msg = processInlinerolls(msg_orig); | |
const sum = totalInlinerolls(msg_orig); | |
let output = msg.split('--')[1].trim(); | |
output = `${template} ${output} {{${sumheader}=${sum >= 12 ? sum : `[${sum}: Reroll](!&13;#${macroname})`}}}`; | |
sendChat("", output); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment