RPTools.net

Discussion and Support

Skip to content

It is currently Thu Jan 18, 2018 5:03 pm 






Reply to topic  [ 10 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Giant
 
Joined: Thu May 13, 2010 12:52 pm
Posts: 125
 Post subject: Is there an expression to have a dice explode only once?
PostPosted: Fri Dec 15, 2017 12:24 pm 
Thanks


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri May 12, 2006 7:56 pm
Posts: 6347
Location: Middle of Nowhere, NM
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: 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.


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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri May 12, 2006 7:56 pm
Posts: 6347
Location: Middle of Nowhere, NM
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: 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.


Top
 Profile  
 
 Offline
Giant
 
Joined: Thu May 13, 2010 12:52 pm
Posts: 125
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: Sat Dec 16, 2017 12:08 pm 
UDF? Not sure what that is.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7983
Location: Bay Area
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: 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

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri May 12, 2006 7:56 pm
Posts: 6347
Location: Middle of Nowhere, NM
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: 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.


Top
 Profile  
 
 Offline
Giant
 
Joined: Thu May 13, 2010 12:52 pm
Posts: 125
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: 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


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 7983
Location: Bay Area
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: Sun Dec 17, 2017 7:17 am 
Create your lib Token, "lib:Test".
Create a macro called "onCampaignLoad"
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.
Add text to macro:
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"
Add text to macro:
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)

_________________
Downloads:


Top
 Profile  
 
 Offline
Giant
 
Joined: Thu May 13, 2010 12:52 pm
Posts: 125
 Post subject: Re: Is there an expression to have a dice explode only once?
PostPosted: Sun Dec 17, 2017 7:30 am 
Thank you, works great!


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 10 posts ] 

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

Search for:

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (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 2 guests





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman