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

count number of times the highest number of a die

1605393395

Edited 1605394145
bocatrapa
Plus
Sheet Author
Hello, my question is this. I need to count the number of times the highest number is rolled on a roll of several d6 dice, and then add +1 to that result. For example, if we roll 4d6 and the roll is 4,1,2,4 ... the final result would be 5, because the highest result is 4 and it is repeated. Another example, if we roll 5d6 and the roll is 5,4,5,1,5 ... the final result is 6, because the highest result is 5 and it is repeated. The last example, if we roll 4d6 and the roll is 4,3,2,1...the final result would be 4, because the highest result is 4 and is not repeated. what I have currently done is: {{roll = [[{@ {HAB1} d6k1}]]}}, and there I get the highest roll, but I don't know how to make it count if that roll is repeated. Thanks a lot
1605398927

Edited 1605400314
David M.
Pro
API Scripter
Don't think that is going to be possible without the api. It's a pretty simple script, though. This doesn't have the prettiest output, but it seems to work. Syntax: !nD6 # where # is the number of d6 you want to roll. You'd want put a query in your macro. const nD6 = (() => { const version = '0.1.0'; const checkInstall = () => { log('-=> nD6 v'+version); }; const handleInput = (msg) => { const macroName = 'nD6'; let rolls = []; let highestCount = 0; let rollMod = 0; let result; let displayRolls = ''; if(msg.type=="api" && msg.content.indexOf("!nD6") === 0 ) { try { who = getObj('player',msg.playerid).get('_displayname'); let args = msg.content.split(/\s+/); let numDice = parseInt(args[1]); let highestRoll = 0; for (i=0; i<numDice; i++) { let roll = randomInteger(6) rolls.push(roll); if (roll>highestRoll) { highestRoll = roll; } } rolls.sort((a,b)=>b-a); for (i=0; i<numDice; i++) { displayRolls = displayRolls + '[[' + rolls[i] + ']] '; if (rolls[i] === highestRoll) { highestCount++; } } if (highestCount > 1) { rollMod = 1; } result = highestRoll + rollMod; let output = `&{template:default} {{name=${macroName}}} {{Rolls=${displayRolls}}} {{Roll Mod=[[${rollMod}]]}} {{Result=[[${result}]]}}`; sendChat('', output); } catch(err) { sendChat('',`/w "${who}" `+ 'Error: ' + err.message); } }; }; const registerEventHandlers = () => { on('chat:message', handleInput); }; on('ready', () => { checkInstall(); registerEventHandlers(); }); })();
1605401684
bocatrapa
Plus
Sheet Author
thank you very much, i'm going to try it!