Is there an expression to have a dice explode only once?
Posted: Fri Dec 15, 2017 12:24 pm
Thanks
Discussion and Support
https://forums.rptools.net/
Code: Select all
[H: defineFunction("rollDiceE","rollDiceE@"+getMacroLocation(),1,0)]
Code: Select all
<!-- rollDiceE(numDice,sides): result (hidden: dice.tooltip) -->
[h: dice.num = arg(0)]
[h: dice.sides = arg(1)]
[h: dice.rolls = ""]
[h, count(dice.num), code: {
[H: roll = roll(1,dice.sides)]
<!-- explode once -->
[H, if(roll == dice.sides): roll = roll + roll(1,dice.sides)]
[H: dice.rolls = listAppend(dice.rolls,roll)]
}]
[h: dice.result = eval(strformat("sum(%{dice.rolls})"))]
[h: dice.tooltip = strformat('<span title="<html><b>%{dice.num}d%{dice.sides} :</b> %{dice.rolls}</html>">%{dice.result}</span>')]
[h: macro.return = dice.result]
Code: Select all
[H: defineFunction("rollDiceE","rollDiceE@"+getMacroLocation(),1,0)]
Code: Select all
<!-- rollDiceE(numDice,sides): result (hidden: dice.tooltip) -->
[h: dice.num = arg(0)]
[h: dice.sides = arg(1)]
[h: dice.rolls = ""]
[h, count(dice.num), code: {
[H: roll = roll(1,dice.sides)]
<!-- explode once -->
[H, if(roll == dice.sides): roll = roll + roll(1,dice.sides)]
[H: dice.rolls = listAppend(dice.rolls,roll)]
}]
[h: dice.result = eval(strformat("sum(%{dice.rolls})"))]
[h: dice.tooltip = strformat('<span title="<html><b>%{dice.num}d%{dice.sides} :</b> %{dice.rolls}</html>">%{dice.result}</span>')]
[h: macro.return = dice.result]
Code: Select all
[H: result = rollDiceE(1,8)]
[H: tooltip = dice.tooltip]
[R: strformat("Roll 1d8: %{tooltip}")]
Code: Select all
[H: result = rollDiceE(1,8)]