Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account
This post has been closed. You can still view previous posts, but you can't post any new replies.

[Useful Macro] Creating Simple Target Number Conditionals in Dice Representation

1427348514

Edited 1427349010
I run D&D 3.5e and use the Players Roll All The Dice variant and the Roll20 built-in D&D 3.5e character sheet. Because players roll a lot more dice using this variant than normal, it's important for them to know their roll modifiers for those new rolls. As such, I wanted to create a tool for my players that allows them to look up all of their roll modifiers at any time. Likewise, I wanted the tool to tell me what all of the various NPC/monster "scores" are that oppose those rolls, so I needed it to calculate the simple number which a player would need to beat. That is, I needed something that would output something like this: Flat-Footed AC for Bob: +4 = 14 (Subtract lost Dodge bonus) A number of these values have "conditionals" in them. For example, for Flat-Footed AC, you lose your Dex bonus (if you had one), but keep a Dex penalty. I needed to represent these conditions in my tool, but the only tool I had available was macros/abilities because I can't afford Mentor level (for custom character sheets). I can't do something like... [[ @{selected|dexmod} < 1 ? @{selected|dexmod} : 0 ]] ...because there's no "conditional" syntax available in macros/abilities (although it would be really nice if you could). That meant that I had to use Dice Representation to display all of these modifiers and all of their innate conditionals, which I could represent in-game through a GM whisper. /w gm Flat-Footed AC for @{selected|character_name}: +[[ @{selected|modifier} ]] = [[ @{selected|modifier} +10 ]] (Subtract lost Dodge bonus) Through experimentation, I found the following formulas for creating very simple conditionals using only Dice Representation. I figure they might be very useful to some people on here. Assume that in the formulas all ALL_CAPS variables are integers that you plan on replacing with actual integers (or attributes that are integers) when you implement them. ( Note: if you replace a variable with an explicit negative number, Roll20 Order of Operations must have that negative number in parentheses.) [[ ( 1 - ( floor( ( MINIMUM_VALID_NUMBER - 1 - ATTRIBUTE ) / ( abs( MINIMUM_VALID_NUMBER - 1 - ATTRIBUTE ) + 0.001 ) ) + 1 ) ) ]] ...returns 1 for all integers MINIMUM_VALID_NUMBER or more, and returns 0 for all other integers. This means that I can do... [[ ATTRIBUTE * ( 1 - ( floor( ( MINIMUM_VALID_NUMBER - 1 - ATTRIBUTE ) / ( abs( MINIMUM_VALID_NUMBER - 1 - ATTRIBUTE ) + 0.001 ) ) + 1 ) ) ]] ...and it'll return ATTRIBUTE when it's an integer that is greater than or equal to the MINIMUM_VALID_NUMBER and will be 0 for all other integers. Likewise, for a situation where above a certain maximum you should ignore that value (such as ignoring a Dex Bonus when flatfooted but keeping a penalty), you can use... [[ ( floor( ( MAXIMUM_VALID_NUMBER - ATTRIBUTE ) / ( abs( MAXIMUM_VALID_NUMBER - ATTRIBUTE ) + 0.001 ) ) + 1 ) ]] ...to return 1 for all integers MAXIMUM_VALID_NUMBER or less, and return 0 for all other integers. Inside a macro, you'd write... [[ ATTRIBUTE * ( floor( ( MAXIMUM_VALID_NUMBER - ATTRIBUTE ) / ( abs( MAXIMUM_VALID_NUMBER - ATTRIBUTE ) + 0.001 ) ) + 1 ) ]] ...and it'll return ATTRIBUTE when it's an integer that is less than or equal to the MAXIMUM_VALID_NUMBER and will be 0 for all other integers. Thus, to accomplish ignoring a Dex Bonus but keeping a Dex Penalty, I can write the following (using the default template and the Defense Bonus variant ): /w gm &{template:default} {{name=AC Roll Modifiers for @{selected|character_name} }} {{Flat-Footed=+[[ @{selected|DefenseBonus}-(@{selected|DefenseBonus}*@{selected|Is Wearing Physical Armor?}) + @{selected|acitembonus} + @{selected|shieldbonus} + @{selected|size} + @{selected|armorclassnaturalarmor} + @{selected|armorclassdeflectionmod} + @{selected|armorclassmiscmod} + @{selected|dexmod} * ( floor( ( (-1) - @{selected|dexmod} ) / ( abs( (-1) - @{selected|dexmod} ) + 0.001 ) ) + 1 ) ]] = [[ @{selected|DefenseBonus}-(@{selected|DefenseBonus}*@{selected|Is Wearing Physical Armor?}) + @{selected|acitembonus} + @{selected|shieldbonus} + @{selected|size} + @{selected|armorclassnaturalarmor} + @{selected|armorclassdeflectionmod} + @{selected|armorclassmiscmod} + @{selected|dexmod} * ( floor( ( (-1) - @{selected|dexmod} ) / ( abs( (-1) - @{selected|dexmod} ) + 0.001 ) ) + 1 ) +10 ]] (Subtract lost Dodge bonus)}} In the above example we also see a different kind of conditional in the math for the Defense Bonus: @{selected|DefenseBonus}-(@{selected|DefenseBonus}*@{selected|Is Wearing Physical Armor?}) In my version of the Defense Bonus variant, Immaterial Armor stacks with the Defense Bonus, so I can't just use the @{selected|acitembonus} attribute to determine whether the Defense Bonus applies. As such, I created a custom attribute for all creatures called "Is Wearing Physical Armor?" which is a boolean 1 or 0 depending on whether or not that's the case (admittedly, the formula could be made simpler if the attribute was "Is NOT Wearing Physical Armor", but that's splitting hairs). Anywho, I wanted to point out this other kind of conditional because with this math formula many useful applications could exist for non-mentors where you have an attribute which is a boolean 1 or 0.
1427366512

Edited 1427366542
Ziechael
Forum Champion
Sheet Author
API Scripter
Nice use of the macros and a good concise guide thanks :) I'd encourage you to add this as a subsection of the 3.5 specific wiki !
Ziechael said: I'd encourage you to add this as a subsection of the 3.5 specific wiki ! Is that a thing anyone can just do, or is there some kind of approval process?
1427403966
Ziechael
Forum Champion
Sheet Author
API Scripter
Not at all, it is very much community driven (although i'm sure it is moderated to prevent naughty people ruining it for everyone)... some handsome fellow recently added a bulk of info to the 3.5 page, building on what some kind soul had already started. I really think your work could add another level and use for macros that isn't currently represented :)
1427404844

Edited 1427421654
I abstracted this out a little and made it a little more compact for my own uses. In ternary syntax here are the versions I came up with x >= A ? T : F -floor((A-x-0.1)/(abs(A-x-0.1)+0.001))*T - floor((x+0.1-A)/(abs(x+0.1-A)+0.001))*F x > A ? T : F -floor((A-x+0.1)/(abs(A-x+0.1)+0.001))*T - floor((x-0.1-A)/(abs(x-0.1-A)+0.001))*F You can see that x <= A ? T : F is equivalent to x > A ? F : T and correspondingly with x < A ? T : F it is equivalent to x >= A ? F : T x == A ? T : F is equivalent to ((x >= A) ? T : F) - ((x > A) ? (T-F) : 0) x != A ? T : F is equivalent to x == A ? F : T This gives a pretty complete ternary operation which should be effectively full branching support for integer operations(it would be much nicer if we could store variables such as dice rolls)