Reroll multiple times the same dice

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Reroll multiple times the same dice

Post by Irrlicht »

I didn't know how to better put the title, but here it is: as many of you may know, when you score a critical hit in D&D/Pathfinder the inflicted damage is multiplied by a given number dependant on the weapon you're wielding, but while the bonus to damage goes directly multiplied, the base damage of the weapon is not to be rolled and then multiplied, but instead to be rolled a total of times equal to the multiplier.
For example, say I have a Halberd: its base damage is 1d10 and its crit multiplier is x3. Suppose that I have a +4 damage bonus and I score a critical hit; I'll deal a total of 3d10 + (4 * 3).
Now, I have a macro designed to build weapon-macros, in which I imput all the base values of the weapon. I could give it a base damage of 1d8, 2d6, 3d100 or whatever; and I could give it any crit multiplier: x2, x3, x100 or whatever again.

Now, in the macros resulting from that previous one, if I put it as such:

Code: Select all

[h: BaseWpnDmg = 2d6]
[h: CritMultiplier = 2]
[r: CritResult = BaseWpnDmg * CritMultiplier]
...I'll get that the variable damage is first rolled once, and then multiplied; rather, I'd need that the base damage is rerolled a number of times equal to CritMultiplier... how may I do it without adding tons of unnecessary code?
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Reroll multiple times the same dice

Post by CoveredInFish »

A simple solution would be this.

Code: Select all

[h: BaseWpnDmg = "2d6"] <!-- we need the dice type as string -->
[h: CritMultiplier = 2]
[h: CritResult = 0]
[h, count(CritMultiplier): CritResult = CritResult + eval(BaseWpnDmg)]
[r: CritResult]
I'm not sure if this suits all your needs as i have seen much more elaborate d&d crit macros around here.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Reroll multiple times the same dice

Post by Rumble »

The following code disassembles the dice expression and rebuilds it to be the proper number of dice rolled on a critical. It also pulls in a notional damage bonus, just to complete the example (also, most of the stuff displayed is just error-checking, so you can see what's being done).

As I understand it, for a 2d6 weapon, with a x2 multiplier and a +4 damage bonus, the final expression is:

4d6 + 8

The following code should arrive at that result.

Code: Select all

[h: BaseWpnDmg = "2d6"]
[h: CritMultiplier = 2]
[h: DmgBonus = 4]
		
[h: numDice = number(substring(BaseWpnDmg, 0, indexOf(BaseWpnDmg, "d")))]
[h: numSides = number(substring(BaseWpnDmg, indexOf(BaseWpnDmg, "d")+1))]
[h: finalNumDice = CritMultiplier * numDice]
[h: finalDiceExpression = finalNumDice+"d"+numSides]
[h:CritResult = eval(finalDiceExpression) + (CritMultiplier * DmgBonus)]

Number of base weapon dice: [r:numDice]<br>
Dice type: d[r:numSides]<br>
Total dice rolled on crit: [r:finalNumDice]<br>
Final Dice expression: [r:finalDiceExpression]<br>
Final Damage Amount: [r:CritResult] damage

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: Reroll multiple times the same dice

Post by Irrlicht »

Rumble, thanks for the time, but I didn't understand your suggestions too well (I'm not so advanced in macro writing)... on the other hand, CoveredInFish solved my problem. Thanks.
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."


train850
Kobold
Posts: 12
Joined: Fri Aug 13, 2010 10:06 pm

Re: Reroll multiple times the same dice

Post by train850 »

I cut a lot of the dead weight out of my macros by simply making a universal roller for 3.5e. Instead of making different macros for every roleplaying situation I run across. I made one macro to roleplay the motion of rolling the dice. I can roleplay the rest, part of being a dm.

Here is the link to the other post explaining the details http://forums.rptools.net/viewtopic.php?f=5&t=2396

Post Reply

Return to “MapTool”