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

Getting the maximum possible from a roll in script?

So I'm working on editing a sheet and making it custom. The way the sheet was set up originally you have to manually write what the crit damage would be. But with several characters, often changing weapons, different stats, and a whole bunch of other stuff to keep track of... that's just not convenient for anyone... So here's what I'd like to do: I'd like to calculate the crit so that the sheet automatically knows what the crit is. It's just the max possible damage roll for the weapon + a mod. But... how do I get that max possible roll? If they type into the sheet that a weapon does for example 1d6 + 1, how do I take that and in code get it to be 7 every time? Is there a convenient way? Basically, how can I get the maximum possible from a roll in the code?
No one? I feel like this should be possible
1605540092

Edited 1605550847
GiGs
Pro
Sheet Author
API Scripter
There isnt a convenient way to get a damage string like 1d6+1 and get the maximum damage. It is possible , using a sheet worker, to get it but the code is very complex and error-prone. It is better to change the way damage is entered to use three inputs instead of one. Instead of something like <input type="text" name="attr_damage" value=""> use something like <input type="number" name="attr_damage_numberdice" value="1"> d <input type="number" name="attr_damage_diesize" value="6"> <select name="attr_damage_direction" >     <option selected>+</option>     <option>-</option> </select> <input type="text" name="attr_damage_modifier" value="0"> Then the full damage roll is @{damage_numberdice}d@{damage_diesize}@{damage_direction}@{damage_modifier} and the maximum damage for dice is  @{damage_numberdice} * @{damage_diesize}
A shame there isn't one but that's actually not too bad of a solution! Thanks a lot! I'll work that into the sheets :)
1605550963
GiGs
Pro
Sheet Author
API Scripter
If you add a class to each of the elements, you can get it styled so that it looks pretty. I'd change the d to <span class="die-d">d</span> so you can style it to match the other elements too.
1605551686
Finderski
Plus
Sheet Author
Compendium Curator
GiGs said: If you add a class to each of the elements, you can get it styled so that it looks pretty. I'd change the d to <span class="die-d">d</span> so you can style it to match the other elements too. If this is a sheet that's going to be submitted to the repo for others to use, I'd also recommend adding internationalization to the die indicator something like: <span class="die-d" data-i18n="dice-indicator">d</span> Because some languages (such as German) use a different letter to indicate die/dice (example: 1W4 = 1d4, but for German).
Thanks a lot, guys! I'll keep that in mind when I work on the sheets