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

need to subtract a value from a token bar

i made a custom spell that gives extra damage when the caster takes 5 damage. i also need this to work with a macro or an entire script for the damage of all my attacks. i have no idea how to write but can learn fairly quickly. any help is appreciated.
alright i found a script but i don't know how to use it. can i use it in a macro in some way or have something in the macro run this script? on("change:attribute", function(obj, prev) { if(obj.get("name") !== "HP") return; var damageTaken = 0; var currentHp =0; var oldHp = 0; var max = 0; var charName = getObj("character", obj.get("_characterid")); currentHp = obj.get("current"); oldHp = prev["current"]; max = obj.get("max"); if (currentHp > max) { currentHp = max; obj.set("current", currentHp); } damageTaken = currentHp - oldHp; if (damageTaken < 0 ) { sendChat(charName.get("name"), "/me has taken " + -1 * damageTaken + " damage"); } if (damageTaken > 0 ) { sendChat(charName.get("name"), "/me has healed " + damageTaken + " damage"); } }); on("change:graphic:bar1_value", function(obj, prev) { //Ignores players, handled above if(obj.get("represents") != "") return; if (Campaign().get("initiativepage") == false) return; var damageTaken = 0; var currentHp =0; var oldHp = 0; var max = 0; var charName = obj.get("name"); currentHp = obj.get("bar1_value"); oldHp = prev["bar1_value"]; max = obj.get("bar1_max"); if (currentHp > max) { currentHp = max; obj.set("bar1_value", currentHp); } damageTaken = currentHp - oldHp; if (damageTaken < 0 ) { sendChat(charName, "/me has taken " + -1 * damageTaken + " damage"); } if (damageTaken > 0 ) { sendChat(charName, "/me has healed " + damageTaken + " damage"); } });
1562962671
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That is an API script, not a macro. Unless your game was created by a user with a Pro subscription, you do not have access to that feature.
the game i am in was created by a pro user so i will be able to use i just don't know how to implement it correctly to be able to make a roll to deal damage to both the enemy and subtract 5 hp from my bar
1562967321
GiGs
Pro
Sheet Author
API Scripter
For scripts, the GM needs to install them in a special scripts tab only they have access to. This means you wont be able to test scripts.
i am working with the gm to do this so once i have one i give it to him and he tests it for me if it doesn't work i will do something about it i just need to know how to use it as this also a determining factor to whether or not i get a pro subscription myself.