Die Rolling Macro - Reroll just one "1" once

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
maplealmond
Kobold
Posts: 1
Joined: Mon Jun 25, 2012 5:20 pm

Die Rolling Macro - Reroll just one "1" once

Post by maplealmond »

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?

the_meek
Cave Troll
Posts: 99
Joined: Fri Aug 01, 2008 9:18 am

Re: Die Rolling Macro - Reroll just one "1" once

Post by the_meek »

Try 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]
}]
[Total] 
For powers with 3[W] or 4[W], increase DiceNumber.

DevoDog
Dragon
Posts: 456
Joined: Sat Jul 12, 2008 9:56 am

Re: Die Rolling Macro - Reroll just one "1" once

Post by DevoDog »

I created a function in my campaign file:

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]
Define the function as R1Roll and then call it via R1Roll(3,6).

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: Die Rolling Macro - Reroll just one "1" once

Post by Jagged »

Interesting to see other peoples code for the same problem.

This link shows how I added it to Rumble's Slim framework

User avatar
rpotor
Kobold
Posts: 8
Joined: Fri Mar 06, 2009 4:01 pm
Location: Szekesfehervar, Hungary
Contact:

Re: Die Rolling Macro - Reroll just one "1" once

Post by rpotor »

the_meek wrote:Try 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]
}]
[Total] 
For powers with 3[W] or 4[W], increase DiceNumber.
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).

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.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Die Rolling Macro - Reroll just one "1" once

Post by aliasmask »

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]  

Post Reply

Return to “Macros”