AlterBars 2.0 - New and improved!

1488950856

Edited 1494507314
Sky
Pro
This simple API script allows you and your players to use a macro to adjust the value of the three bars of a token. The script has been updated to use a more aesthetically pleasing emote and eventually support triggering the FX and Aura changes from the Aura/Tint HealthColor written by DXWarlock. I have provided several macros below to highlight possible uses for this script and a list of the variables the GM can set within the script itself (some day I'll get a fancy chat menu and one click install). To Do List: Add chat menu for adjusting variables. Upgrade to a one-click install configuration. Figure out why FX animations aren't being triggered when changes to the token are sent to HealthColor. Make minor adjustments to left margin to center announcement properly. Add option to show red/green chat announcement per use instead of all the time off or on. Add option to color chat announcement using the Player Color instead of any other colors. Break out chat announcement css into a list of options DM can set, including background image. Add results of random rolls in the tooltip when mousing over the result in chat. Add logic to hide npc names if players would not normally be able to see them. March 21st, 2017 ~ 8:45 am eastern Version: 2.0.5 Link: https://gist.github.com/Sky-Captain-13/a503c359146... Bugfix: Added fix by TheAaron to catch token objects that might not be tokens. March 21st, 2017 ~ 8:45 am eastern Version: 2.0.4 Bugfix: Added logic to exit the script if there is no valid --target tag. Minor Update:  Altered the hide function to the following --show|all will announce the results in chat --show|GM will whisper the results only to the GM --show|none will not show any message at all March 8th, 2017 ~ 6:45 pm eastern Version: 2.0.3 Bugfix: Corrected logic for verifying a valid Bar was designated by number or barkey. March 8th, 2017 ~ 6:20 am eastern Version: 2.0.2 Bugfix: Added a -7px left margin to the announcement CSS to properly center the box and text in the chat window. March 8th, 2017 ~ 2:25 am eastern Version: 2.0.1 Bugfix:  FX Animations are now properly triggered by the Aura/Tint HealthColor script by DXWarlock. March 8th, 2017 ~ 12:00 am eastern Version:  2.0.0 Initial Release:  Please report any bugs you come across. Thanks! Variable Descriptions ALT_COLORS If set to true, AlterBars uses a dark green or dark red emote instead of the default orange color. PREVENT_OVERMAX If set to true, AlterBars will reset the bar's value to its maximum if it would be over that max value. STOP_AT_ZERO The opposite of prevent_overmax, this option will set a bar's value to zero if it would drop below that. ANNOUNCE_CHANGE Set to true to send a message to the chat window, showing which token gained or lost points and how much. ALTER_GM Change to true to send an alert to the GM instead of everyone. Bar Names & Designations A small upgrade to this script is the ability to provide the verb and singular and plural names of the bars. Formerly, the script simply used gained or loses, but now you can set these options per bar and whether it is a gain or a loss. The default settings assume Bar1 is being used for Hit Points (which is the default bar used for HP on tokens made for the built-in compendium for D&D 5e). Example: Paladin heals 5 hit points. var Bar1Gain = ["heals", "hit point", "hit points"]; var Bar1Loss = ["takes", "damage", "damage"]; var Bar2Gain = ["recovers", "mana", "mana"] var Bar2Loss = ["spends", "mana", "mana"] var Bar3Gain = ["heals", "hit point", "hit points"]; var Bar3Loss = ["takes", "damage", "damage"]; Sample Macros Drink a Potion of Healing !alter --target|@{selected|token_id} --bar|1 --amount|+2d4+2 Cast Cure Wounds on Ally !alter --target|@{target|token_id} --bar|1 --amount|+?{Cast at Level|1|2|3|4|5|6|7|8|9}d8 + @{CharacterName|wisdom_mod} Deal Damage to Enemy !alter --target|@{target|token_id} --bar|1 --amount|-?{Damage Dealt|0} Damage (Self) !alter --target|@{selected|token_id} --bar|1 --amount|-?{Damage Taken|0} Heal (Selected) !alter --target|@{selected|token_id} --bar|1 --amount|+?{Amount Healed|0} Heal (Target) !alter --target|@{target|token_id} --bar|1 --amount|+?{Amount Healed|0} Damage (Selected) !alter --target|@{selected|token_id} --bar|1 --amount|-?{Damage Taken|0} Damage (Target) !alter --target|@{target|token_id} --bar|1 --amount|-?{Damage Taken|0}
1488976496
The Aaron
Pro
API Scripter
var Previous = {   "bar1_value": Target.get("bar1_value"),   "bar2_value": Target.get("bar2_value"),   "bar3_value": Target.get("bar3_value")  }; could be replaced with: var Previous = JSON.parse(JSON.stringify(Target)); to perfectly duplicate what gets passed in events as prev.
1488978327
Sky
Pro
Of course it can be done in one line... silly me for thinking my solution was easy and simple, lol. Thanks. Made the change to futureproof the script, just in case someone down the line needs more info from the previous object.
1488981165
The Aaron
Pro
API Scripter
HAHAHAHA, well, you could write it as var Previous = JSON.parse( JSON.stringify( Target ) ); to get the line count up. =D
1489006532

Edited 1489007300
Looks great SkyCap! Am I miss reading your notes? The Health Aura script doesn't seem to be updating after using alterbars to change a targets health.
1489006710
Sky
Pro
Dustin C. said: Looks great SkyCap! I anxiously waiting the support for Aura health, Love the simplicity of your Alterbars but im torn over the fun Blood spurts from the Arua mod lol :)  It's already in. I got that fixed this morning.
1489007316
Josh
Pro
I'm getting an error from this. I copied your macro, changing it to bar 3, and it throws the error "(From ERROR): (DM) That is not a valid bar."
1489007660
AH-HA... found my issue... DX updated yesterday (3/7/17) and I had an older version. Now it's working! Awesome job! Just FYI version 1.3.1 did the trick :)
1489007792

Edited 1489008678
Sky
Pro
Josh said: I'm getting an error from this. I copied your macro, changing it to bar 3, and it throws the error "(From ERROR): (DM) That is not a valid bar." I will look at this when I get a chance. Leaving for work soon. -edit- I have an idea where the error is happening, but don't have time to fix it before work. Will try and look at it at work, but can't promise anything.
1489016911
Sky
Pro
March 8th, 2017 ~ 6:45 pm eastern Version: 2.0.3 Link: https://gist.github.com/Sky-Captain-13/a503c359146... Bugfix: Corrected logic for verifying a valid Bar was designated by number or barkey.
1489017467
Sky
Pro
Aaron, if you see this... would you happen to know why the 3D dice aren't rolling automatically? // Main process... sendChat("", "/r " + AlterValue, function (outs) { AlterValue = parseInt(JSON.parse(outs[0].content).total); var Tooltip = "Rolling " + Expression + " = " + AlterValue + "' class='a inlinerollresult showtip tipsy-n'"; if (Operand1 != "-") { // Add to bar... if (PREVENT_OVERMAX) AlterValue = (AlterValue + CurrentValue > MaxValue) ? MaxValue - CurrentValue : AlterValue; if (ANNOUNCE_CHANGE) sendChat("", "/desc <div style='" + AlertGainStyle + "'>" + Target.get("name") + " " + BarGain[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarGain[1] : BarGain[2]) + "." + "</div>"); if (ALERT_GM || NoAnnounce) sendChat(who, "/w GM <div style='" + AlertGainStyle + "'>" + Target.get("name") + " " + BarGain[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarGain[1] : BarGain[2]) + "." + "</div>"); Target.set("bar" + Bar + "_value", CurrentValue += AlterValue); } else { // Subtract from bar... if (STOP_AT_ZERO && (CurrentValue - AlterValue < 0)) AlterValue = CurrentValue; if (ANNOUNCE_CHANGE && !NoAnnounce) sendChat("", "/desc <div style='" + AlertLossStyle + "'>" + Target.get("name") + " " + BarLoss[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarLoss[1] : BarLoss[2]) + "." + "</div>"); if (ALERT_GM || NoAnnounce) sendChat(who, "/w GM <div style='" + AlertLossStyle + "'>" + Target.get("name") + " " + BarLoss[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarLoss[1] : BarLoss[2]) + "." + "</div>"); Target.set("bar" + Bar + "_value", CurrentValue -= AlterValue); } if ('undefined' !== typeof HealthColors && HealthColors.Update) HealthColors.Update(Target, Previous); }, {use3d: true})
1489372744
Can this be used to 'heal' or 'damage' multiple tokens at once?
1489380542
Sky
Pro
eastwood said: Can this be used to 'heal' or 'damage' multiple tokens at once? Currently no.  That would require some re-writing of the script, but might be something much easier done once the new jsnode update is pushed from the dev server to the production servers.
1489381624
SkyCaptainXIII said: Currently no.  That would require some re-writing of the script, but might be something much easier done once the new jsnode update is pushed from the dev server to the production servers. Roger that! Still a great script, thanks!
1489492475
Thorsten B.
KS Backer
Love this, and seconding the ask for the ability to damage / heal multiple tokens. Groupcheck + AlterBars = dead easy AoEs :)
1489493790
Sky
Pro
Thorsten B. said: Love this, and seconding the ask for the ability to damage / heal multiple tokens. Groupcheck + AlterBars = dead easy AoEs :) Not sure how it will interact with GroupCheck...
1489516683
Thorsten B.
KS Backer
SkyCaptainXIII said: Not sure how it will interact with GroupCheck... Manually :). GroupCheck reduces saving throws from N to 1 click. AlterBars could then reduce HP adjustment to a few clicks, depending on how many NPCs did or did not make their saving throw.  It's not that GroupCheck and AlterBars interact, it's that both take a separate part of resolving an AoE attack and simplify it.
1489518098

Edited 1489518757
Jakob
Pro
Sheet Author
API Scripter
Thorsten B. said: SkyCaptainXIII said: Not sure how it will interact with GroupCheck... Manually :). GroupCheck reduces saving throws from N to 1 click. AlterBars could then reduce HP adjustment to a few clicks, depending on how many NPCs did or did not make their saving throw.  It's not that GroupCheck and AlterBars interact, it's that both take a separate part of resolving an AoE attack and simplify it. Not to hijack the thread, but if you look in the GroupCheck thread, you'll find a small ApplyDamage script I wrote just for this purpose (assuming you do not already know about it). It doesn't have a fancy output like AlterBars (nor is it very user-friendly unless used in a macro together with GroupCheck), but it's specifically adapted to interact with GroupCheck in a semi-automated way (i.e. apply full/half/no damage with one button click). With some changes, among them multiple targets, you could plug in AlterBars instead.
1490051533
Alicia
Pro
Sheet Author
Glad to see you're back. Couple things. Is it possible to throw in some error handling for when you don't have the tags in correctly.. I had to restart the API multiple times because it didn't like I didn't have "--" in there for one of the macros.  Also, before you could put 'hide' at the end of the string to have the alerts go to GM only. What's the equivalent now? Thanks for the update to include Aura/Health. I'm working on changing things over to work with the new updates and it's a relief to have support.
1490054801
The Aaron
Pro
API Scripter
SkyCaptainXIII said: Aaron, if you see this... would you happen to know why the 3D dice aren't rolling automatically? // Main process... sendChat("", "/r " + AlterValue, function (outs) { AlterValue = parseInt(JSON.parse(outs[0].content).total); var Tooltip = "Rolling " + Expression + " = " + AlterValue + "' class='a inlinerollresult showtip tipsy-n'"; if (Operand1 != "-") { // Add to bar... if (PREVENT_OVERMAX) AlterValue = (AlterValue + CurrentValue > MaxValue) ? MaxValue - CurrentValue : AlterValue; if (ANNOUNCE_CHANGE) sendChat("", "/desc <div style='" + AlertGainStyle + "'>" + Target.get("name") + " " + BarGain[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarGain[1] : BarGain[2]) + "." + "</div>"); if (ALERT_GM || NoAnnounce) sendChat(who, "/w GM <div style='" + AlertGainStyle + "'>" + Target.get("name") + " " + BarGain[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarGain[1] : BarGain[2]) + "." + "</div>"); Target.set("bar" + Bar + "_value", CurrentValue += AlterValue); } else { // Subtract from bar... if (STOP_AT_ZERO && (CurrentValue - AlterValue < 0)) AlterValue = CurrentValue; if (ANNOUNCE_CHANGE && !NoAnnounce) sendChat("", "/desc <div style='" + AlertLossStyle + "'>" + Target.get("name") + " " + BarLoss[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarLoss[1] : BarLoss[2]) + "." + "</div>"); if (ALERT_GM || NoAnnounce) sendChat(who, "/w GM <div style='" + AlertLossStyle + "'>" + Target.get("name") + " " + BarLoss[0] + " <span title='" + Tooltip + "'>" + AlterValue + "</span> " + ((AlterValue == 1) ? BarLoss[1] : BarLoss[2]) + "." + "</div>"); Target.set("bar" + Bar + "_value", CurrentValue -= AlterValue); } if ('undefined' !== typeof HealthColors && HealthColors.Update) HealthColors.Update(Target, Previous); }, {use3d: true}) Just saw this... My guess would be because the roll is intercepted by the API through the callback function, so it never gets sent to the Chat to get turned into 3d dice.  I've never actually used the use3d: setting beyond a "yep, that works" script when it first was released. 
1490075414

Edited 1490077008
Sky
Pro
Alicia G said: Glad to see you're back. Couple things. Is it possible to throw in some error handling for when you don't have the tags in correctly.. I had to restart the API multiple times because it didn't like I didn't have "--" in there for one of the macros.  Also, before you could put 'hide' at the end of the string to have the alerts go to GM only. What's the equivalent now? Thanks for the update to include Aura/Health. I'm working on changing things over to work with the new updates and it's a relief to have support. I'll work on this today. However, one of the things you want is already in there: --hide|true  I should probably do a little more work on that and use a better name and different options...  how about: --show|all (default if missing) --show|gm --show|none
1490100102
Sky
Pro
March 21st, 2017 ~ 8:45 am eastern Version: 2.0.4 Link: https://gist.github.com/Sky-Captain-13/a503c359146... Bugfix: Added logic to exit the script if there is no valid --target tag. Minor Update: Altered the hide function to the following... --show|all will announce the results in chat --show|GM will whisper the results only to the GM --show|none will not show any message at all
1490108991
Alicia
Pro
Sheet Author
Awesome thanks. I'll test when I get home.
1490110241
I really like AlterBar, but my players didn't. It would really be nice to be able to use AlterBar as an attack resolves. I tried adding the macro to an attack on 5e-Shaped but it asks for the info before you even do anything. I would like to have the attack resolve and then have the players alterbars without clicking a separate macro. I know they could get used to using a separate macro but they didn't seem happy with it when I tried using this API in my last session. Is there anyway to do this?
1490112053
Alicia
Pro
Sheet Author
Jerry F. said: I really like AlterBar, but my players didn't. It would really be nice to be able to use AlterBar as an attack resolves. I tried adding the macro to an attack on 5e-Shaped but it asks for the info before you even do anything. I would like to have the attack resolve and then have the players alterbars without clicking a separate macro. I know they could get used to using a separate macro but they didn't seem happy with it when I tried using this API in my last session. Is there anyway to do this? I know every group is different but I just manage it myself as a GM. Use as a decice to indicate their attack is done and final.
1490112922
Alicia G said: Jerry F. said: I really like AlterBar, but my players didn't. It would really be nice to be able to use AlterBar as an attack resolves. I tried adding the macro to an attack on 5e-Shaped but it asks for the info before you even do anything. I would like to have the attack resolve and then have the players alterbars without clicking a separate macro. I know they could get used to using a separate macro but they didn't seem happy with it when I tried using this API in my last session. Is there anyway to do this? I know every group is different but I just manage it myself as a GM. Use as a decice to indicate their attack is done and final. I think I like where you are coming from.
1490122512
Sky
Pro
Jerry F. said: I really like AlterBar, but my players didn't. It would really be nice to be able to use AlterBar as an attack resolves. I tried adding the macro to an attack on 5e-Shaped but it asks for the info before you even do anything. I would like to have the attack resolve and then have the players alterbars without clicking a separate macro. I know they could get used to using a separate macro but they didn't seem happy with it when I tried using this API in my last session. Is there anyway to do this? You can now... if you use powercards. But I don't see powercards being as popular these days due to the ease of making macros/attacks from character sheets.
1490124497
Ravenknight
KS Backer
SkyCaptainXIII said: Jerry F. said: I really like AlterBar, but my players didn't. It would really be nice to be able to use AlterBar as an attack resolves. I tried adding the macro to an attack on 5e-Shaped but it asks for the info before you even do anything. I would like to have the attack resolve and then have the players alterbars without clicking a separate macro. I know they could get used to using a separate macro but they didn't seem happy with it when I tried using this API in my last session. Is there anyway to do this? You can now... if you use powercards. But I don't see powercards being as popular these days due to the ease of making macros/attacks from character sheets. Powercards are marvelous. :)
1490128518
You know I just added the macro for the AlterBar as an attacher and I think it will work great.
1490130407
Sky
Pro
Jerry F. said: You know I just added the macro for the AlterBar as an attacher and I think it will work great. Only issue is that the macro has to resolve first before anything is sent to chat, so players won't see the damage until after its done.
1490134733
I did it as a clickable.
1490134869
Sky
Pro
Ah, nice.
1494507322
Sky
Pro
March 21st, 2017 ~ 8:45 am eastern Version: 2.0.5 Link: https://gist.github.com/Sky-Captain-13/a503c359146... Bugfix: Added fix by TheAaron to catch token objects that might not be tokens.
1494527685
I am using this script in my Vampire game and when I use the macro it always says "NPC spends xxxx" whatever it is. Is there a way to alter the script to show character name?
1494534987
Sky
Pro
The token needs to have it set so that the name is visible to players.
1494535713
Sky said: The token needs to have it set so that the name is visible to players. Thanks that worked
1494925213
Mal
Pro
It'd be very nice if this can be included and work in the Shaped Sheet's freeform. But right now it asks the alter bars change before the actual roll comes out.  Example: Click Cure Wounds > Should know how much it heals > then enter the number healed to change the bar of target. Other than that, this looks very promising, look forward to updates :)
1494926971
Sky
Pro
Mal said: It'd be very nice if this can be included and work in the Shaped Sheet's freeform. But right now it asks the alter bars change before the actual roll comes out.  Example: Click Cure Wounds > Should know how much it heals > then enter the number healed to change the bar of target. Other than that, this looks very promising, look forward to updates :) That's because of how macros work, period. Regardless of the sheet. Anytime you hit the button on a macro, it has to go through and fill out every query before it sends anything to chat.
1494948606
Mal said: It'd be very nice if this can be included and work in the Shaped Sheet's freeform. But right now it asks the alter bars change before the actual roll comes out.  Example: Click Cure Wounds > Should know how much it heals > then enter the number healed to change the bar of target. Other than that, this looks very promising, look forward to updates :) I just created a button using attacher and then once the roll has happened then the player can click that to apply it. Though I also reference my macro sheet I created for moving around from game to game.
1497662027
I am trying to setup some macros with a set character without having to select them. How would I do that?
1497662429
Sky
Pro
Get the token's id and replace @{target/selected|token_id} with that id.
1497662493

Edited 1497662598
Sky
Pro
It would look like... !alter --target| -KmncoclSF8BpARGzeeW --bar|1 --amount|+?{HP Gained|0} ...instead of... !alter --target| @{target||token_id} --bar|1 --amount|+?{HP Gained|0} ... but obviously you would need to get each token's individual id. Token ID's change from map to map though. So you it's not really something you can do.
1497662883
Sky said: It would look like... !alter --target| -KmncoclSF8BpARGzeeW --bar|1 --amount|+?{HP Gained|0} ...instead of... !alter --target| @{target||token_id} --bar|1 --amount|+?{HP Gained|0} ... but obviously you would need to get each token's individual id. Token ID's change from map to map though. So you it's not really something you can do. They change map to map?  So its not like character_id which is per game?
1497663428
Sky
Pro
Each and every token has its own unique id. Even on the same map.
1497664053
Sky said: Each and every token has its own unique id. Even on the same map. Thanks for the headsup
1501700625
Hey great script, thank you for that. Does someone has an idea why I get this: if I try one of the examples at the beginning (this one for example:!alter --target|@{selected|token_id} --bar|1 --amount|+?{Amount Healed|0})? Thank you 
1501701566
Sky
Pro
Dunno... it should work.
1502128921
My fault, outdated version of alterbar....  : )
1504287137

Edited 1504287197
I guess I should post this here instead of the PowerCards thread. Found a bug in the script. If a token_id has an underscore in it (see attached picture) the alterbars will throw an error when attempting to apply damage. Any possibility of a fix for it?
1504299311
Sky
Pro
Copy and paste the old token/character. Token ID's are unique per token even if they're for the same character sheet.
1505933967
Not sure what is wrong here please help if you can. !alter --target|@{target|token_id} --bar|1 --amount|+?{What type of potion|Healing, 2d4+2|Greater, 4d4+4 |Superior, 8d4+4 |Supreme, 10d4+20 |Full, +100} If I have the macro window open and test I get but if i click the macro for the tokens bar I get