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

[Sheet Worker] Custom tailor roll commands from a set of settings

1455099890

Edited 1455100176
Welcome to this little "How to custom tailor roll commands from a set of settings using Sheet Workers" Before Sheet Workers it was super annoying if you had different options leading to a different roll on the same button. There were various ways how to deal with this (API, different buttons, etc) but now you can easily stitch roll commands together by using Sheet Workers. This allows you to apply options for all buttons instead of having to duplicate functionality. As an example how I used this for my shadowrun 5 sheet: Some rolls are affected by injury modificators (e.g. (5-injurymod)d6>5) Some rolls are affected by an edge attribute. Those rolls will explode (e.g. 5d6!>5) Both options are toggleable and can be used at the same time or none can apply. The solution now: simply store the parts in hidden attributes and set those to empty strings or the value you require depending on the setting (e.g. enable injury modificators/enable use of edge). <!--We will use those attributes to stitch our roll command together --> <input class="hidden" type="text" name="attr_cmd_use_edge_token"/> <input class="hidden" type="text" name="attr_cmd_use_edge_text"/> <input class="hidden" type="text" name="attr_cmd_use_edge_mod"/> <input class="hidden" type="text" name="attr_cmd_injury_mod"/> <input class="hidden" type="text" name="attr_cmd_injury_text"/> <!-- This is our simple charactersheet --> <span>Edge:</span> <input class="shown" type="text" name="attr_edg"/> <span>Injury Modifier:</span> <input class="shown" type="text" name="attr_injury_mod"/> In this case I just use a checkbox but you can use any arbitrary attributes a SheetWorker can react on to set those settings. <!-- This is on our settings tab or wherever you want to be able to activate those checkboxes. You will likely want to style those (see CSS Wizardry) --> <input  type="checkbox" name="attr_use_injury_mod"></input> <input  type="checkbox" name="attr_use_edge"></input> Now you need your event listener: on("sheet:opened change:use_edge", function() { getAttrs(["use_edge"], function(v) {   use_edge = (v.use_edge == "on") if(use_edge){ /* If the checkbox is set*/ setAttrs({  'cmd_use_edge_token': "!", /*This will let our roll explode*/  'cmd_use_edge_text' : "{{edge=Edge @{edg}}}", /* This is a template attribute only shown if edge is enabled*/  'cmd_use_edge_mod' : "+@{edg}" /*This is a modifier for template attributes as well as dice pools */ }); }else{ /* If the checkbox is not set*/ setAttrs({  'cmd_use_edge_token': "", /* Empty strings allow us to stitch the commands together*/  'cmd_use_edge_text' : "",  'cmd_use_edge_mod' : "" }); }          }); }); on("sheet:opened change:use_injury_mod change:injury_mod", function() { getAttrs(["use_injury_mod","injury_mod"], function(v) {   use_injury = (v.use_injury_mod == "on") mod = parseInt(v.injury_mod) if(use_injury && mod > 0){ /* If there is a injury mod >0 we want to substract it from the dice pool if injury mods are enabled */ setAttrs({  'cmd_injury_mod': "-@{injury_mod}", /* This is our dice pool modifier as well as template attribute modifier*/  'cmd_injury_text': "{{injurymod=-@{injury_mod}}}"/*This is a custom template attribute only shown if injury mods are used*/  }); }else{ setAttrs({  'cmd_injury_Mod': "",  'cmd_injury_text': ""  }); }      }); }); And all we need now is our roll button. I will use the default template to show the functionality, but obviously I used a own styled roll template. With the default template you should be able to copy/paste the code into your sheet and try it. Beware I haven't tested this simplified version :) <button type='roll' name='roll_something' value="/em &{template:default}{{mod=[[3@{cmd_use_edge_mod}@{cmd_injury_mod}]]}}{{successes=[[(?{Dicepool?}+3@{cmd_use_edge_mod}@{cmd_injury_mod})d6@{cmd_use_edge_token}sacs5cs6>5]]}}@{cmd_use_edge_text}@{cmd_injury_text}"></button> This button now rolls the number of d6 specified by the user with a constant modifier +3. It will explode the roll if the checkbox use_edge is set. If this is true it will also modify the dicepool by the number specified in the attr_edg input field. If use_injury_mod is checked it will also substract the number specified in attr_injury_mod from the dicepool. Also in both cases one additional template attribute is passed, which you can use to also build roll templates using conditions cooler and more complex than the build in roll template conditional logic.
1455109092
Finderski
Pro
Sheet Author
Compendium Curator
This is pretty cool.  May request you consider adding it to the  Sheet Workers Wizardry thread? I'm hoping if it gets enough traction it may be stickied like the CSS Wizardry to keep a thread of useful sheet worker tidbits, making it easier to find this type of thing.
1455109313

Edited 1455109335
Ok! I will copy and paste it over there. A stickied thread would be really helpful yes indeed! This thread can be closed now.