Is there an expression to have a dice explode only 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
Zandel
Giant
Posts: 133
Joined: Thu May 13, 2010 1:52 pm

Is there an expression to have a dice explode only once?

Post by Zandel »

Thanks

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Is there an expression to have a dice explode only once?

Post by Phergus »

I assume you checked the wiki?

Dice_Expressions

Don't see that option but I just glanced at it.

Zandel
Giant
Posts: 133
Joined: Thu May 13, 2010 1:52 pm

Re: Is there an expression to have a dice explode only once?

Post by Zandel »

I did, no luck

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Is there an expression to have a dice explode only once?

Post by Phergus »

Should be pretty straight-forward to do a macro that does what you need. Make it a UDF and then it would be easy to call from any other macro.

Zandel
Giant
Posts: 133
Joined: Thu May 13, 2010 1:52 pm

Re: Is there an expression to have a dice explode only once?

Post by Zandel »

UDF? Not sure what that is.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Is there an expression to have a dice explode only once?

Post by aliasmask »

I rewrote an old function to explode each die once. Original here: http://forums.rptools.net/viewtopic.php ... 00#p241200

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]
keyword: amsave dice

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Is there an expression to have a dice explode only once?

Post by Phergus »

UDF is User Defined Function (see Wiki: defineFunction()). That first bit of macro code that AM put in his post. This is normally put on a Library_Token in a onCampaignLoad macro.

Zandel
Giant
Posts: 133
Joined: Thu May 13, 2010 1:52 pm

Re: Is there an expression to have a dice explode only once?

Post by Zandel »

Got it, can one of you post what the syntax to call this UDF as written above would look like if say I wanted to do 1d8 exploding once?


Thanks

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Is there an expression to have a dice explode only once?

Post by aliasmask »

Create your lib Token, "lib:Test".
Create a macro called "onCampaignLoad"
Edit macro and put:

Code: Select all

[H: defineFunction("rollDiceE","rollDiceE@"+getMacroLocation(),1,0)]
Save macro and Run by clicking macro button so it is globally defined.

Edit and create new macro "rollDiceE".
Turn off player can edit in settings.
Add text to macro:

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]
Save macro.

Edit and create new macro in Campaign Window Frame called "Roll 1d8"
Add text to macro:

Code: Select all

[H: result = rollDiceE(1,8)]
[H: tooltip = dice.tooltip]
[R: strformat("Roll 1d8: %{tooltip}")]
Save and run macro.

---

Explanation of what's going on.

First you create a globally accessible library of macros. Included in this library is a special macro called onCampaignLoad that auto runs when you open the campaign. Since you just created it in this example you need to manually run it for the first time. Wiki: defineFunction() is just creating the reference to the macro you want to run using an alias, which happens to be the same name as the macro, but doesn't need to be.

Next you create the contents of that macro to be run. You need to turn off the Players can edit in the options of the macro which is defaulted to on. Personally, I think the default should be off because the token owner and gm can always edit the token anyway. At this point, it's just an annoying step.

Finally, you create a macro that everyone can use referencing the new function in the Campaign Window.

Code: Select all

[H: result = rollDiceE(1,8)]
This gives you the numeric value of the result to be used in formula or whatnot. There's a hidden result created called "dice.tooltip" which is a text based result that gives a tooltip when moused over showing the details of the roll. (see Wiki: defineFunction() for scope details)

Zandel
Giant
Posts: 133
Joined: Thu May 13, 2010 1:52 pm

Re: Is there an expression to have a dice explode only once?

Post by Zandel »

Thank you, works great!

Post Reply

Return to “Macros”