# RPTools.net

Discussion and Support

It is currently Tue Feb 20, 2018 10:40 am

 Page 1 of 1 [ 10 posts ]
Author Message
 Zandel   Giant Joined: Thu May 13, 2010 12:52 pmPosts: 125
 Post subject: Is there an expression to have a dice explode only once?Posted: Fri Dec 15, 2017 12:24 pm
Thanks

 Phergus   Deity Joined: Fri May 12, 2006 7:56 pmPosts: 6381Location: Middle of Nowhere, NM
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Fri Dec 15, 2017 1:50 pm
I assume you checked the wiki?

Dice_Expressions

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

 Zandel   Giant Joined: Thu May 13, 2010 12:52 pmPosts: 125
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Fri Dec 15, 2017 8:48 pm
I did, no luck

 Phergus   Deity Joined: Fri May 12, 2006 7:56 pmPosts: 6381Location: Middle of Nowhere, NM
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Sat Dec 16, 2017 8:39 am
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 Joined: Thu May 13, 2010 12:52 pmPosts: 125
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Sat Dec 16, 2017 12:08 pm
UDF? Not sure what that is.

 aliasmask   Deity Joined: Tue Nov 10, 2009 6:11 pmPosts: 8009Location: Bay Area
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Sat Dec 16, 2017 1:51 pm
I rewrote an old function to explode each die once. Original here: viewtopic.php?f=20&t=23687&p=241200#p241200
Code:
[H: defineFunction("rollDiceE","rollDiceE@"+getMacroLocation(),1,0)]

Code:
<!-- 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 Joined: Fri May 12, 2006 7:56 pmPosts: 6381Location: Middle of Nowhere, NM
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Sat Dec 16, 2017 6:52 pm
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 Joined: Thu May 13, 2010 12:52 pmPosts: 125
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Sun Dec 17, 2017 6:15 am
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

 aliasmask   Deity Joined: Tue Nov 10, 2009 6:11 pmPosts: 8009Location: Bay Area
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Sun Dec 17, 2017 7:17 am
Edit macro and put:
Code:
[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.
Code:
<!-- 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"
Code:
[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:
[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 Joined: Thu May 13, 2010 12:52 pmPosts: 125
 Post subject: Re: Is there an expression to have a dice explode only once?Posted: Sun Dec 17, 2017 7:30 am
Thank you, works great!

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 10 posts ]

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: Jump to: Select a forum ------------------ General    Announcements    Ideas for New Applications    General Discussion    Developer Notes       Java Programming Info    User Creations       Requests for HELLLLP!       Tilesets, Token Libraries, and Complete Maps          Token Libraries          Tilesets/Graphics for Map-making          Complete Maps       Campaign Frameworks          D&D 5e Frameworks          D&D 4e Frameworks          [D&D3.5 + Pathfinder] Campaign Macros          Shadowrun 4e Frameworks          Savage Worlds Frameworks       Published Module Support       Tutorials          Graphics, Images, Tokens, Maps          Drop-In Macros and Scripts          Campaign Frameworks       Drop-In Macro Resources    Links & External Resources    Looking For Group       "Living" Campaigns       Dungeons and Dragons       Savage Worlds       WoD       Wargaming    Documentation Requests/Discussion    Session Report-Back Tools    MapTool       How To       Macros       Feature Requests          Resolved       Bug Reports          Resolved       WIP - User FAQ       Testing    MapTool 1.4    TokenTool    DiceTool    InitiativeTool    CharacterTool       Support: d20 D&D       Support: D&D 4e       Support: Hero System       Support: Savage Worlds       Support: GURPS Other    RPTools Sightings    Running Campaigns       Thiera's College of Adventurers       Age of Might       Scales of War       Renwold       Dead Men Walking       Dark Sun - 4th Edition       Warhammer Fantasy Roleplay       Return of Uchly Namen       Insert Campaign Here       Antium       The Mystic Moon       World of Lagal       GangerRun       FB Scales of War       Sellswords of Eberron          Archive       Orbs of Chaos       World of Omegus       Keep on the Shadowfell - 4E       Rise of the Runelords       Aurith In The Age Of Steam       Widdershins       Nos's Pathfinder Campaign       Falcons Hollow       Verwirrte Welten       With it or on it       Starter Set - Jeff

### Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest