[Script] - autoButtons v0.8.1 autoButtons v0.8.1 repo This was a originally a wee, test scriptlet from another thread a while back. It's grown up since then... IMPORTANT : This script requires TokenMod to apply damage & healing to tokens. IMPORTANT: Custom Buttons are currently broken in the main version. Only the default buttons are usable. This is due to a security update to the sandbox, so it affects all versions of autoButtons. This post has a link to a test version which will hopefully get custom buttons working again - it's still very much a test version though, and may or may not work. Some details here So... what's all this then? The script reacts to roll templates posted to chat, and posts back some damage buttons for simple application of damage/healing to the selected token(s). It's dead simple, really. Some moving pictures: Where do the damage numbers come from? I couldn't figure out how to deconstruct a roll object, so they're just randomly generated. Really??? No, not really! The script comes with a preset for 5e by Roll20, but you can customise it to work with any sheet or roll template. If you need it to do anything tricky (like picking up spells & higher level casting on the 5e sheet), you will need Javascript skills. But trickier operations aside, you can set the script up to watch for whatever roll templates and template properties you like. Here is the script helpfully spitting out the default 5e settings: So the script will post buttons for any roll it finds on the templates listed in the first box, and it will grab the roll totals for each of
the template properties in the second box. These will then be available for the buttons to use to perform their own math on. In the case of the default 5e settings, the normal damage button will total all the damage from {{dmg1=...}} {{dmg2=...}} {{globaldamage=....}} and add on {{hldmg=...}} if a spell cast is detected. The crit button will add those crit fields on top for a new total. The default buttons for the 5e preset are: Crit: all damage and crit fields added together, plus upcast crit properties if applicable Full Damage: dmg1 + dmg2 + globaldamage, plus upcastDamage if applicable Half Damage: half of Full Damage, rounded down Healing: dmg1 + dmg2 + globaldamage, plus upcastDamage if applicable , applied as healing instead of damage There's a small title at the top - this is just to help identify the right buttons if two different rolls are close together or there's some chat lag. Those are the simplest buttons - there are more of them available, covered in the next post . If you wish to handle temporary HP, I recommend a slight modification to Aaron's script. I've covered that at the bottom of this post . Important Note on Advantage/Disadvantage/Crit damage:
Due to the way roll templates are constructed & displayed,
character sheets can potentially be rolling a whole bunch of dice which
don't end up being displayed in chat. This includes superfluous crit
dice in 5e, and the damage template showing crit damage when it wasn't
needed due to the player rolling two dice. This script has no way of reliably knowing whether
a crit has actually landed when crit dice show up, so there's no way to
automatically hide the crit button when it's not needed. You'll just
need to figure it out yourself. The crit button will more than likely
have some bizarre amounts on the tooltip, even when no crit damage is visible in the chat bar. Oosh, your buttons are stupid and you're stupid. How do I add buttons that don't suck? Aha!
There's the clever bit. You'd use the Command Line Interface to do
that. It follows the general Roll20 pattern of achieving stuff via
API... The CLI So it
turns out I'm both lazy and forgetful. I'm also not playing on Roll20
these days, so whenever I come back to a script (even my own) I've
totally forgotten the CLI commands. For this reason I've used regular
expression matches for all the commands, to make them easier for me to
guess 24 hours later when my mind has been scrubbed clean by a few
pan-galactic gargle blasters. If that makes no sense at all: end result
is that none of the commands are case-sensitive, and most of them can be
short-cut (or long-cut if you prefer!), or just out-right guessed if
you forget them. I also forgot to actually put any useful information
into the --help command. Although the commands are not case-sensitive , I'll stick to camelCase and full names for ease of reading. Important to note though: button names, template names and template property names are case-sensitive . These must be entered exactly. Keyword: !autoButton Commands: --listButtons / --buttons Generates a list of buttons currently available for use, e.g: !autoButton --buttons From
left to right, the controls are "Show button", "Hide button", "Delete
button". Controls are greyed out when nonsensical - you can't "Show" a
button which is already shown on the button template, and you cannot
"Hide" a button which isn't currently enabled. Buttons marked with an asterisk are default buttons - these cannot be deleted. Note that the asterisk is not part of the name - do not include it when referencing a default button (e.g. when trying to clone it) --showButton <button name>
The same as clicking the "Show" button on the button list: this adds
the button to the template spat out by the script after each damage
roll. You'll probably want to do this after creating a new button,
otherwise you can't click it. What good is a button that can't be
clicked? And what of the mental state of a button that isn't getting
clicked? --hideButton <button name >
Same as the "Hide" button in the list. Removes the button from the
button template, but leaves it in the button pool if you want to add it
back in later. --deleteButton <button name > Delete a button entirely. This will also remove it from the button template. Default buttons cannot be deleted. --createButton <button data>
Creates a new button to add to the pool. There's a button on the button
list which will do this for you via prompts, but if you'd rather enter
it in straight through the CLI, the required fields just need to be
entered in moustache/handlebars format, like a roll template macro. To use the more advanced features like queries or multiple content layers, you will need to use the command line to either create the button, or edit it afterwards. This is covered in detail in the next post . --editButton <button data> This is also covered in detail in the next post . -- cloneButton <existing button name> <new button name> Clone an existing button - existing button name must be an exact match and new button name must be unique, e.g. !autobut --cloneButton damage --renameButto n <existing button name> <new button name> The same as cloneButton, but will remove the old button if the cloning is successful. Cannot be used on default buttons. --reorderButtons / --order Reorder the buttons, left to right, with a comma-delimited list. The buttons are indexed from 1, left to right in their current order . So
in the screenshot above with the halfCrit button, we have buttons 1 to 5
from left to right. If we want the half crit button in the second
position (between the full crit and normal damage), we'd supply this: !autobut --order 1,5,2,3,4 (actually,
we could just supply "1,5" as the order - any unlisted indices will be
left in the current order and thrown on the end). -- listTemplates / --templates List the roll template names the script listens for in chat. These should be prefilled for 5e by Roll20. This list can also be accessed via the --settings menu. --addTemplate <template name> Add a roll template name to the listener list --removeTemplate <template name> Remove a template name from the listener list --listProperties / --props List the roll template properties the listener tries to grab inline rolls from. This can also be accessed via the --settings menu. --addProperty <prop category/prop name> Add a roll template property to monitor for inline rolls. IMPORTANT: properties must belong to a category, and cannot be added without one. If using the 5e sheet, all 4 categories above can be used, though the upcast ones are ignored if the damage didn't come from a spell. For custom sheets, only the damage and crit categories send data through to the button math functions, so you will want to use one of those.
For example, the screenshot above has a customDmg3 property added
(doesn't exist on the 5e sheet and won't actually do anything
obviously). To add that property, we'd type some letters thusly (with
some shortcut commands!): !autobut --addprop damage/customDmg3 In short: any property added or removed must
contain a forward slash '/' to denote the category and property. Any
further slashes are no use - there's no nesting of properties. --removeProperty <prop category/prop name> Remove a roll template property from the inline roll monitor . Subject to all the same conditions as --addProperty above. --hpBar / --bar < 1 | 2 | 3 > Set the token bar to affect with HP changes. Default is 1. --loadPreset <preset sheet name>
Load the preset settings for a game system. Currently doesn't do a
great deal since only 5e has settings coded in, though you can switch to
'custom' if you want a blank slate. Note that this will clear all
settings, including the template listener array. The script won't do anything until you've added some templates & properties to listen for. --reset Reload the current character sheet presets. Might be handy if something goes horribly wrong. --uninstall Remove all autoButton data from the [state] object. Restarting the sandbox will initiate a clean install of autoButtons. --help Really not very useful . Leads to this thread. --settings Opens the settings UI in the chat bar. This is the preferred way to modify the game settings. Toggles: these settings can be toggled by supplying no argument, turned on by supplying on, 1, or true or turned off with off, 0, or false. All of these can be modified via the --settings menu as of 0.6.0 --targetTokens Use @{target} clicks to direct damage and healing instead of @{selected} token. Requires TokenMod setting to allow players to use character IDs . Default is off . --bump Minor style edit to bump the buttons bar on top of the "who" chat message output, and reduce the bottom margin. Takes up less space. Default is on . --overkill Allow HP to drop below 0. Default is off . --overheal Allow HP to exceed max. Default is off . --ignoreAPI Ignore any rolltemplates generated by the API. Default is on . --gmOnly Button template is whispered to the GM. Default is on . Worth noting that the script only applies damage to selected
tokens, so there's generally no real risk in allowing players to use
it, though the buttons will post publicly if this setting is toggled
off, and some people don't like that chat spam. This does not allow players to use the CLI to change script settings - it merely posts the buttons to public chat so they can go click-crazy. Note that combining this with targetTokens would allow players to affect HP on tokens they don't own. --report This turns on chat reporting each time a change is made by TokenMod from an autoButtons button click. The 'Character' option in here will attempt to find a token or character owner to send the report to, but will always still send it to the GM. It's best to change this through the --settings UI, but the internal values are [ 'off', 'gm', 'control', 'all' ]. Default is off . --darkMode Switch on dark mode palette for the button bar. As with anything, this only affects button bars generated after toggling the setting. Default is off . --multiattack When a button bar is generated for an NPC, this will attempt to resolve the label on the button bar into a reference to the NPC action that generated it - this allows the GM to click on the label in the bar to generate another attack. Default is off . --allowNegatives Allow final values to be negative. This would allow a query modifier to turn a value negative (for example, HAM applying a 3 damage reduction on a 1 damage hit results in -2). The end result would be a damage that causes healing. Default setting is off which prevents this behaviour (and the inverse, of a modified healing spell causing damage). --autosort Automatically sort the buttons by Unicode order when generating the button bar. Note that this does not permanently change the order of the buttons like a --reorderButtons would, if you switch it back off the buttons should return to their normal order. Default is off . --autohide Automatically hide buttons where the value is 0. Note the limitations with the 5e sheet due to the way the sheet generates templates - crit is always rolled, so the crit buttons will never be hidden. --imageIcons This will render the button labels as images instead of fonts, which will fix font alignment issues on MacOS / ChromeOS. Default is off Updates v0.4.4: - fixed math functions not saving properly on buttons. The state object does not like storing functions! - fixed NaN error in spells - fixed bad reference to higher level casting fields, causing damage to not be added v0.4.5: - fixed bad reference causing --createButton to crash v0.5.1: - major rejiggifying of the scribbledywords. New structure, new
button store, new config layout, new UI elements. Still no --help
documentation! - added two toggles: targetTokens to use token targets instead of selected (requires tokenMod to allow players to use the --ids flag) bump nudges the button bar and reduces margins so it takes up less chat space. Turn this off if it conflicts with other CSS shenannigans you've got going on. - minor security validation added to createButton: the math function cannot contain the word 'state' or the operator '=' - crit.total and damage.total are no longer pre-added before being passed to buttons. So expressing full crit damage in a button now is (crit.total + damage.total), instead of just (crit.total) - or, put another way, the { crit } object keys contain only the bonus crit damage v0.5.2: - Bug fixes: bad default value in hpBar, issue with version number in checkInstall() preventing upgrade path v0.5.3: - Bug fix: wrong key name in upgrade path for old versions from previous thread v0.6.0 See v0.6.0 release post v0.7.0 See v0.7.0 release post v0.7.2 - added --imageIcons setting to fix font render issues with MacOS or ChromeOS v0.8.0 - added apiMeta data - --imageIcons now defaults to true - submitted to one-click