I think you're going to have to come up with a convention for what represents the "left-most die" in a roll. For me, I would assume that to be the first die in the array of dice that are rolled AND which contribute to the roll value. In the case of your 2d6-with-advantage-becoming-a-3d6 example, if the dice rolled: ( 2, 4, 6) The first die would be dropped (2), leaving (4,6). In that case, 4 is in the position of what represents the "left-most", so it has the chance to explode. It does not explode. The 6, although it could have exploded were it considered the left-most, also does not explode. ScriptCards rolls its own dice based on equations you give it, and I believe that it offers up the values of the dice rolled for you to manipulate. (If it doesn't you could build a loop of rolling 1d6 some number of times, allowing you to generate the correct number of values). So I think your approach should be to have a procedure to generate your roll that collects the values of the dice; then you check for how many you should be keeping/dropping and trim the set accordingly; then you have a check for any explosion, consulting the correct value in the array; finally, you use any result from exploded dice to generate another call to your rolling procedure, with appropriate looping in any applicable parts (does it continue to have advantage? does it continue to explode? etc.).