One of the players in my 4e has the axe expertise feat, which allows him to reroll any one die that comes up with an "1" exactly once, but he has to use the second result. I don't see an easy way to do this with the existing die expressions. 2d10r2 would cause both dice to be rolled again (and to keep going as well.)
I'd like to give him a simple macro for his weapon damage which handles the "re-reoll any one 1 once" so he doesn't have to think about it and slow the game up. I have programming experience but I've never written a MapTool macro before. Thoughts?
Die Rolling Macro - Reroll just one "1" once
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
-
- Kobold
- Posts: 1
- Joined: Mon Jun 25, 2012 5:20 pm
Re: Die Rolling Macro - Reroll just one "1" once
Try this:For powers with 3[W] or 4[W], increase DiceNumber.
Code: Select all
[H: Total = 0]
[H: DiceNumber = 2]
[H: DiceSize = 10]
[H: ExpertiseTriggered = 0]
[H, C(DiceNumber, ""), CODE: {
[CurrentRoll = eval(strformat("d%{DiceSize}"))]
[ExpertiseTriggered = if(CurrentRoll == 1, 1, ExpertiseTriggered)]
[IF(ExpertiseTriggered): CurrentRoll = eval(strformat("d%{DiceSize}"))]
[Total = Total + CurrentRoll]
}]
[Total]
Re: Die Rolling Macro - Reroll just one "1" once
I created a function in my campaign file:
Define the function as R1Roll and then call it via R1Roll(3,6).
Code: Select all
[H:DieAmt=arg(0)]
[H:DieSize=arg(1)]
[H:RResults=""]
[H,COUNT(DieAmt),CODE:
{
[H:RResults=listAppend(RResults,roll(1,DieSize))]
}
]
[H,IF(listContains(RResults,"1")),CODE:
{
[RResults=listReplace(RResults,listFind(RResults,"1"),roll(1,DieSize))]
}
]
[H:Total=0]
[H,FOREACH(Item,RResults),CODE:
{
[H:Total=Total+Item]
}]
[H:macro.return=Total]
Re: Die Rolling Macro - Reroll just one "1" once
Interesting to see other peoples code for the same problem.
This link shows how I added it to Rumble's Slim framework
This link shows how I added it to Rumble's Slim framework
Re: Die Rolling Macro - Reroll just one "1" once
Sorry for resurrecting such an old topic, but I just needed such a macro and found my way here, so maybe someone else will need this, too. Anyway, this solution works fine, however we need to tweak it a little to be perfect. You see, in this version of the code, let's say the first die comes up as a 1, we set ExpertiseTriggered to 1 and reroll the die. We then roll the next die and it comes up as 4, for example, now on line 7, the if function evaluates to false, but we assign the ExpertiseTriggered variable its current value (which is 1), so on line 8 we reroll the second die (which is a 4, so it should not be rerolled).the_meek wrote:Try this:For powers with 3[W] or 4[W], increase DiceNumber.Code: Select all
[H: Total = 0] [H: DiceNumber = 2] [H: DiceSize = 10] [H: ExpertiseTriggered = 0] [H, C(DiceNumber, ""), CODE: { [CurrentRoll = eval(strformat("d%{DiceSize}"))] [ExpertiseTriggered = if(CurrentRoll == 1, 1, ExpertiseTriggered)] [IF(ExpertiseTriggered): CurrentRoll = eval(strformat("d%{DiceSize}"))] [Total = Total + CurrentRoll] }] [Total]
So, to fix this, we need to reset ExpertiseTriggered on each iteration, so the corrected code looks like this:
Code: Select all
[H: Total = 0]
[H: DiceNumber = 2]
[H: DiceSize = 10]
[H: ExpertiseTriggered = 0]
[H, C(DiceNumber, ""), CODE: {
[CurrentRoll = eval(strformat("d%{DiceSize}"))]
[ExpertiseTriggered = if(CurrentRoll == 1, 1, ExpertiseTriggered)]
[IF(ExpertiseTriggered): CurrentRoll = eval(strformat("d%{DiceSize}"))]
[Total = Total + CurrentRoll]
[ExpertiseTriggered = 0]
}]
[Total]
In the beginning, there was nothing.
And God said, LET THERE BE LIGHT.
And there was still nothing, but now you could see it.
And God said, LET THERE BE LIGHT.
And there was still nothing, but now you could see it.
Re: Die Rolling Macro - Reroll just one "1" once
Here's another way to do it :
Code: Select all
[H: numDice = 2]
[H: dieSides = 10]
[H: rolls = ""]
[H, c(numDice), code: {
[H: roll = roll(1,dieSides)]
[H, if( !(roll - 1)): rolls = listAppend(rolls,roll(1,dieSides)); rolls = listAppend(rolls,roll)]
}]
[H: total = eval(strformat("sum(%{rolls})"))]
[H: output = strformat('<span title="%{rolls}">%{total}</span>')]
[R: output]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools