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

Is there a way to reduce Current health by an amount?

What i'm trying to fix is making it so that when i use my HTML only sheet(, I don't have the time/energy to make a CSS sheet for it rn,) I want it to  be able to lower current health by an amount.  Whenever players roll Magic damage, i want them to lose hp equal to a cost the spell asks.  So i.e when they have 22 hp, and they use firespell, i want it to cost 1 hp and thus automatically lower their current hp to 21, so they (and my enemies) have to keep up with less actions.  Currently i have  <button type="roll" name="roll_dmgmag" value="/roll @{dmg_equipment1} +@{Magic}" effect="{@Current_Health} -@{channel_cost1}" > MagDmg </button> as the code, but idk what to use instead of effect, is there a word that allows this function? Thanks in advance!
1671054668
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
To do this, you'd need to use custom roll parsing, action buttons, and sheetworkers. Something like: <input type="number" name="attr_health"><!-- Changed this to just health so that you can use the roll20 max syntax for the max health and have it link to the token correctly --> <input type="number" name="attr_health_max"><!-- the max health attribute --> <fieldset class="repeating_magic"> <input type="number" name="attr_dmg_equipment"> <input type="number" name="attr_magic"><!-- Lowercased your attribute names as capitalized attribute names cause problems for sheetworkers --> <input type="number" name="attr_channel_cost"> <button type="action" name="act_damage"> MagDmg </button><!-- Switched the damage attribute name to be a little simpler with the repeating section --> </fieldset> <script type="text/javascript"> // Listen for a click on the action button on('clicked:repeating_magic:dmgmag',(event) => { const row = event.sourceAttribute.replace(/(repeating_.+?_.+?)_.+/,'$1'); //Extract the row info from the attribute name. getAttrs( ['health',`${row}_dmg_equipment`,`${row}_magic`,`${row}_channel_cost`], // We're going to use async so that we can use the custom roll parsing functions more easily async (attributes) => { const roll = await startRoll(`/roll ${attributes[`${row}_dmg_equipment`]} + ${attributes[`${row}_magic`]}`);//Send the roll to the parser finishRoll(roll.rollId); //Tell roll20 to release the roll to chat const setObj = {}; //Object to accumulate our changes in. const health = +attributes.health;//Convert the health to a number instead of a string setObj.health = health - attributes[`${row}_channel_cost`];//Calculate the new health setAttrs(setObj,{silent:true});//Apply the health change. } ) }) </script> I assumed that your magic stats are actually in a repeating section.
I am a scrub at this, so i don't know what a "repeating section" is  I just listed a bunch of stats like so: <h6> Health</h6> <input type="number" placeholder= "21" name="attr_health_max" title="@{health_max}">   <h6>Strength</h6> <input type="number" placeholder= "2" name="attr_strength" title="@{strength}">  <h6> Magic</h6> <input type="number" placeholder= "2" name="attr_magic" title="@{magic}">   <h6>Skill</h6> <input type="number" placeholder= "2" name="attr_skill" title="@{skill}">   <h6>Speed</h6> <input type="number" placeholder= "2" name="attr_speed" title="@{speed}">  <h6>Luck</h6> <input type="number" placeholder= "2" name="attr_luck" title="@{luck}">  <h6>Defence</h6> <input type="number" placeholder= "2" name="attr_defence" title="@{defence}"> <h6> Resistance</h6> <input type="number" placeholder= "2" name="attr_resistance" title="@{resistance}"> </div><hr> And then made the button just recall the stat, i did make them all lowerscore however, since i don't want things to break.  But if i understand correctly, there is no way to just reduce health without using all the advanced coding?  And i would have to add this to every equipment? (there's only 4, but still) Or is this more akin to a roll template that i just dump this at the end? 
1671067145

Edited 1671067171
GiGs
Pro
Sheet Author
API Scripter
As Scott indicates, the only way to do this in a character sheet is via custom roll parsing, which requires pretty deep knowledge of all of html, css, sheet workers, and rolltemplates. And if repeating sections are involedv, add those too. Up until earlier this year, this wasn't possible at all and you might be best off just having it show the cost, and expecting players to manually apply it.
We got it to work ( a friend and i)  Since we don't use repeating values, we fixed it as follows <script type="text/worker"> on("clicked:dmgmag", function(){ getAttrs(["health", "channel_cost1","dmg_equipment1","magic"], function(values) {  let hp=values.health; let channel=values.channel_cost1; startRoll("&{template:custom} {{title=@{equipment1}}} {{Damage =[[@{dmg_equipment1}+@{magic}]]}}",(results) => { finishRoll(results.rollId); });       setAttrs({            health: hp-channel       });    }); });
1671154883
GiGs
Pro
Sheet Author
API Scripter
Nice! and yeah, if you don't require a print to chat, you don't need the rolltemplate stuff. My bad!