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 .
×
D&D 2024 has arrived! Pre-order the new core rulebooks now and get an exclusive pre-order bonus for free!
Create a free account

questions around a script to make a roll and adjust an attribute

When making a roll, players have the option of increasing the chances of success by spending LUK.  For each point of LUK they spend, the roll total increases by 5. I have a button on the character sheet similar to this: <button type="roll" name="roll_attr" value="&{template:BXDH}{{name=@{character_name}}}{{roll=[[1d20 + @{level} + ?{Luck Points?|0}*5]]]]}}"></button> The template and roll work just fine, but the player has to manually decrease their LUK score. What I'd like is for the LUK attribute to be decreased automatically (by the number entered), and from everything I've gathered I'd have to do this with an custom script.  I thought I might be able to get this to work with ChatSetAttr, but haven't had any luck (so to speak). My questions: 1) Is there a better/easier/any way to do this than creating a script? 2) Is this something I can actually accomplish with the api? a) player-clicked button on character sheet b) uses character attributes and player-entered values c) displays template in chat results d) modifies an attribute based on one of the player-entered values 3) Can anyone suggest any fairly simple scripts that do parts of what I'm looking to do?  I'm not particularly familiar with javascript, but if given something to work from I can usually pick things up from example. Thanks!
1698783663

Edited 1698858713
GiGs
Pro
Sheet Author
API Scripter
If you are able to edit the sheet, you could do it with Custom Roll Parsing (a special kind of Sheet Worker). Otherwise, you will need to use a Script. ChatSetAttrs is the obvious one to use, but it's probably not the only one.
Any thoughts on how to use ChatSetAttr in this case?  If i add the code to trigger it outside of the {{ }} I have no idea how to apply the value entered as part of the {{roll=}}, but if i include it inside the {{}} it makes the roll variable include the string as text.  I'll look into CRP more - i glanced over it but didn't see how that would apply, but I didn't dig that deeply.
holy crap!  Custom Roll Parsing plus CharSetAttr works like a champ! Thank you for pointing me in the right direction.  I'll post up final solution once i have it properly written up.
1698858680
GiGs
Pro
Sheet Author
API Scripter
If you are creating your own character sheet, custom roll parsing should be enough on its own - you don't need chatsetattr (unless you are trying to alter other characters. I have a guide to CRP here: <a href="https://cybersphere.me/guide-to-custom-roll-parsing/" rel="nofollow">https://cybersphere.me/guide-to-custom-roll-parsing/</a>
I'll check it out .. but for the moment, here is what I've got: The button &lt;button type="action" name="act_CONadv"&gt;+&lt;/button&gt; The script &nbsp; &nbsp; on('clicked:CONadv', (info) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; startRoll("&amp;{template:BXDH_General}{{calltype=[[2]]}}{{name=@{character_name}}}{{action=ABILITY CHECK}}{{detail=Constitution}}{{roll1=[[?{Character Advantage|None,1d20|Advantage,2d20kh1|Disadvantage,2d20kl1} + 5 + @{Level} - @{encpoints} + @{CONm} + ?{Any Additional Modifiers|0}]]}}{{roll3=[[?{Using any Fate?|0}]]}}!modattr --silent --charid @{character_id} --LUK|-{{roll2=[[?{Using any Luck?|0}]]}}!!!", (results) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const total = results.results.roll1.result &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const luck = results.results.roll2.result &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const fate = results.results.roll3.result &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const computed = total + (luck * 5) + (fate * 5) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finishRoll( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results.rollId, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; roll1: computed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); and it points to a template; simplified version for reference (variable of note in bold): &lt;rolltemplate class="sheet-rolltemplate-BXDH_General"&gt; &nbsp; &nbsp; &lt;div class="container"&gt; &nbsp; &nbsp; &nbsp; &nbsp; {{#rollTotal() calltype 2}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;h1&gt;{{name}}&lt;/h1&gt;&lt;/div&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;h2&gt;{{action}}{{#detail}}&lt;br&gt;{{detail}}{{/detail}}&lt;/h2&gt;&lt;/div&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div&gt;&lt;h3&gt;&lt;center&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{#rollGreater() roll2 0}}Luck Points: {{roll2}}&lt;br&gt;{{/rollGreater() roll2 0}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{#rollGreater() roll3 0}}Fate Points: {{roll3}}&lt;br&gt;{{/rollGreater() roll3 0}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Roll Total: {{computed::roll1}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/center&gt;&lt;/h3&gt;&lt;/div&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{#rollGreater() computed::roll1 19}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="success"&gt;&lt;h4&gt;Success&lt;/h4&gt;&lt;/div&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{/rollGreater() computed::roll1 19}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{#^rollGreater() computed::roll1 19}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="failure"&gt;&lt;h4&gt;Failure&lt;/h4&gt;&lt;/div&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{/^rollGreater() computed::roll1 19}} &nbsp; &nbsp; &nbsp; &nbsp; {{/rollTotal() calltype 2}} &nbsp; &nbsp; &lt;/div&gt; &lt;/rolltemplate&gt; and as I'm writing this i realize i don't need chatsetattr at all, but it works!