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

Script To Re-Roll Matching Dice

Hello,

I've never written an API and know nothing about coding. I want to be able to roll 2d6, and if the numbers match, have the macro roll an additional dice. For example, if each dice rolls a 3, the macro will keep rolling dice until it rolls something other than a 3, then add the result together. The exploding dice macro only triggers on the maximum dice roll, so that won't work. Any help would be appreciated, thanks!

This is possible with the ScriptCards Mod. It may be possible other ways as well but I'll show a quick example of one way ScriptCards could do this.

!scriptcard {{
  --&DieSize|d6
  
  --#title|Matching Dice Example

  --=OriginalRoll|2[&DieSize]

  --=NewTotal|[$OriginalRoll]
  --~|array;define;RollArray;[$OriginalRoll.RolledDice(1)];[$OriginalRoll.RolledDice(2)]
  --?[$OriginalRoll.RolledDice(1)] -eq [$OriginalRoll.RolledDice(2)]|>RollAdditionalDie;OriginalRoll;NewTotal

  --~RollList|array;stringify;RollArray;,
  --+Rolls|[&RollList]
  --+Total|[$NewTotal]
  --X|

  --:RollAdditionalDie|FirstRoll;ResultingRoll
    --=AddedRoll|1[&DieSize]
    --~|array;add;RollArray;[$AddedRoll.Raw]
    --=[%2%]|[$[%1%]] + [$AddedRoll]
    --?[$AddedRoll] -eq [$OriginalRoll.RolledDice(1)]|>RollAdditionalDie;[%2%];[%2%]
  --<|
}}

In that test run, the original 2d6 roll was 2 5's and then rolled another die which was a 5 and then rolled again for a 4.

I suspect there may be other ways to accomplish what you want that might even be better fits but I thought I would add a ScriptCard option for you.

Let me know if you have any questions about the ScriptCard here and I'll do my best to explain them.

well golly, this is just fantastic! thanks for the help friend :)