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

[Script] Aura/Tint HealthColor

This could be made more universal if you made the break points for colors & death configurable.  That would be really nice for people who play in different game systems.  :-)
Ran into a script crash. It was crashing when I had a token set to controlled by "All Players". To fix it; I changed line 41 to: var type = (oCharacter.get("controlledby") === "" || oCharacter.get("controlledby") === "all") ? 'Monster' : 'Player'; This was pulled from github today. Don't know it that is the correct solution, but it worked for me.
Thank you I'm going to try that BP!
" (Thanks goes to The Aaron to pointing me in the direction to convert hex to hsl/hsv. He is an unending well of patience to help people.)" I second that!! and if it's already been seconded, then I third it and if it's been third-ed then well you get the point.......  
1444844858

Edited 1444845142
DXWarlock
Sheet Author
API Scripter
Anthony said: This could be made more universal if you made the break points for colors & death configurable.  That would be really nice for people who play in different game systems.  :-) What you mean by break points?  BP said: Ran into a script crash. It was crashing when I had a token set to controlled by "All Players". To fix it; I changed line 41 to: var type = (oCharacter.get("controlledby") === "" || oCharacter.get("controlledby") === "all") ? 'Monster' : 'Player'; This was pulled from github today. Don't know it that is the correct solution, but it worked for me. Ah I see the problem all is length of 1, so further down it was looking for a color for 'all'. Ill update it :) Edit: added that snippet, so it shouldn't fail on a player token only controlled by all..it will treat it as a 'monster' and do a white aura.
1444845068
The Aaron
Pro
API Scripter
Thanks Shaun!  I try!  =D Probably he means the thresholds, akin to the phrase " the break even point."
1444845320

Edited 1444845356
DXWarlock
Sheet Author
API Scripter
Ah I see, sort of... I think You mean where death kicks in other than 0? so they can say be -5 and not 'dead'. And for colors, do you mean where green would start? Or would 'death' middle cover it.. say it went from -10 to 10 0 would be 'yellow' then. 10 green, and -10 red (and dead marker)
1444847420

Edited 1444911346
The Aaron
Pro
API Scripter
Probably there are some games where you don't have hit points so much as wounds acquired, so dead might be at 10, where 0 is perfectly healthy.  Similarly, you might be "fine" as long as you are at 20% or more of your wounds, but in bad shape when you get lower.  No idea, just though ideas out there.  To be completely configurable, you'd want to be able to set the bands of colors similar to how you'd create gradients in Photoshop or GIMP.  Right now you have basically: Threshold Color Status Change 100% Green -Dead 50% Yellow -Dead 0% Red +Dead If you wanted to make it more generic, you'd want to be able to specify all the things about that: Set the percentage or set it as a number  For a number, calculate percentage on specific tokens allow negative numbers and percentages over 100% Set the color Set the status change Set how many rows and in what order That's my take on it anyway. =D
1444850272

Edited 1444850284
DXWarlock
Sheet Author
API Scripter
Hmm might be beyond what I could do. Ill give it a shot. It was all I could do with your help to cobble together the HSL formula to take 100 to 0% and make a gradient. making gradient, reverse gradients, and dynamic color ranges based off set numbers and still 'blend' will make my head explode :)
Actually, I didn't realize there was any 'blending' going on. What I was asking is basically as The Aaron described.  Discrete thresholds where the color changes.  In my case: Threshold Color Status 100% (1x HP_max) Green < HP_max, but >= 1/3 HP_max Yellow <1/3 HP_max, but >0 Orange <= 0, but > -5x HP_max Red <= -5x HP_max Black Dead Also, if there were some way to flag to chat when a character passes the (-1, -2, -3, -4) times HP_max thresholds that he has to make a Health roll or suffer death....that would be ideal.  Death is automatic at -5x HP_max.  :-)
1444937303

Edited 1444940350
DXWarlock
Sheet Author
API Scripter
Hmm I can TRY, see what I can make it do. Cant promise anything, I'm no 'The Aaron' when it comes to coding :)  I think it would take rewriting it all to stop using gradients and allow picking the colors for each stage (and how many stages maybe?). Right now its making a gradient, using a scale like this And working out % of it, so green is 100% health red is 0%. I could perhaps get it close to what you want, just by letting you define a max negative to be 'dead'. that would make it not turn red until it hit that number. So say they have 20 HP, green would be 20, -100 would be red...but then that would push yellow and orange into around the -60 area... You would need it to be like this I think (but reverse with yellow at around 3/4): But no clue how to shift the center, or how to define by character where that would be dynamically. Also got to figure out a way that it will work 'best' for everyone. Like some systems the max negative before actually dead is your constitution, others its a set amount by the rules, yours is 5x max, And some its a percentage of total. Then again maybe I'm overthinking it, and trying to over engineer it :P
I haven't looked at your code, so I don't know how much of a change it would be, but I'd probably go about it by letting users define reference points (a pair consisting of absolute or percentage HP and color) and then interpolating between them. With that system, your default could have two reference points: (100%, #00FF00) and (0, #FF0000). Something like Anthony's request for discrete bands could be done with several more reference points: (100%, #00FF00), (99.99%, #FFFF00), (33.34%, #FFFF00), (33.33%, #FF8000), (1, #FF8000), (0, #FF0000), (-499.99%, #FF0000), (-500%, #000000). To implement it, I'd multiply out the percentages for the token in question (so everything is absolute), sort, then figure out which range you're in.  If you're higher than the highest, use the highest; if you're lower than the lowest, use the lowest; if you're exactly at a reference point, use that; otherwise interpolate between the one above you and the one below you.
So, I've tried using your script today and it is awesome, but it seems that the tint/aura only appears when I manually change the bar. My group has been using an older script (<a href="https://app.roll20.net/forum/post/1216260/script-alter-bar-on-token/" rel="nofollow">https://app.roll20.net/forum/post/1216260/script-alter-bar-on-token/</a>) to &nbsp;add/remove HP because it goes much quicker.. Is there anything that can be altered in your script so the tint changes when we use a macro to change the HP bar?
1445825990

Edited 1445826075
DXWarlock
Sheet Author
API Scripter
manveti Im trying to get it to work in my spare time around work (it gets busy this time of year), but think that might be a bit beyond my level of code-fu. What I can get working even vaguely in that direction is ugly, cumbersome, and anyone with good JS coding skills would look at it and scream "Oh my GOD my EYES!". But&nbsp;Ill keep poking at it, its good practice trying to figure it out. Veronica P. Not that I know of. Unless alter bars has a function that I can watch for (I think The Aaron was talking about how I could do that if they had one), I cant get it to update when API changes the token, since it doesn't trigger a 'token change' for me to see. As far as its concerned nothing has changed until someone touches the token by hand for it to look at the token again. IE moves it, changes a value, opens the settings on it..etc. If anyone has worked out a way around this, I'll be happy to hear it and use it :D
Alright, thanks! Gonna see if any of my coding savy friends can take a look at that :D
1446037270
Alicia
Sheet Author
I think I saw somewhere where you can force another script to be called as part of the function. Might be something to add to the Alter Bars script to force the Tint script to run rather than waiting for the API to recognize a change to the tokens.
1446040639
The Aaron
Pro
API Scripter
There are definitely ways to handle it. &nbsp;It would require changes to both scripts. &nbsp;Look at the relationship between GroupInitiative and Bump & TurnMarker for examples of how this can be done.
Alicia G said: I think I saw somewhere where you can force another script to be called as part of the function. Might be something to add to the Alter Bars script to force the Tint script to run rather than waiting for the API to recognize a change to the tokens. I've made PowerCards so you can call it from other scripts and have used that to make small scripts for other people that wanted a complex roll or something that Roll20 by itself couldn't handle. I believe AlterBars also is written the same way.
And yes... AlterBars can be called from other scripts quite easily. It is however a much older script that was one of the first I wrote. It's got some issues, but it works I suppose. var NewMsg = "tokenid # amount"; AlterBar.Process(NewMsg, Who);
1446058256
The Aaron
Pro
API Scripter
I think the issue is largely that the Aura/Tint HealthColor script needs to know when AlterBar changes the bars of a token.&nbsp;
1446066184

Edited 1446066345
DXWarlock
Sheet Author
API Scripter
The Aaron said: I think the issue is largely that the Aura/Tint HealthColor script needs to know when AlterBar changes the bars of a token.&nbsp; Yea, I think it would take me and badger working out some sort of connection between the 2 like you said. Maybe a exposed process in mine it can call? or something in it that sends out a universal 'i ran' type of message I can catch? Not sure if you can make custom 'on' things. Like&nbsp; on("chat:message", function(msg), but a&nbsp; on("Alterbar:barchange", function(msg). It might be able to be done, but I have NO clue how. Be happy to work with you badger if you know a way to get to work, or can understand hows Aaron's 2 work together better than I can. I tried looking yours from above Aaron, but you know how that goes when I try to decipher your scripts. Its like giving a 5th grader a calculus problem. They go "I know it uses math, somehow..but I barely can do long division". If they had a show "can you code better than a 5th grader" I would lose...a lot. LOL Maybe adding a simple on chat:message (whatever alterbars !command is) to mine so we both catch it would work?
You could just copy the alterbars script stuff and add it to the tint script.
Question for all the code wizards here... how can I modify this for damage bars that count up towards a death threshold (like in Shadowrun)? &nbsp;
1446860341
Silvyre
Forum Champion
[For SR5] I would track the number of unfilled Physical Condition Monitor boxes within one of the token bars.
I was going to go that route, but the new character sheet incorporates wound modifiers. &nbsp;So starting with a "full" bar means wound modifiers would apply when they shouldnt. &nbsp;:)
1446868287
The Aaron
Pro
API Scripter
Would it work to just reverse the colors do that green is empty and red is full? &nbsp;That should be easily done in the code if i remember correctly. &nbsp;
I'll take a look. &nbsp;There is also the issue of characters with a empty (no damage take yet) bar having the Red X applied to them. &nbsp;I'm not a coder, but will see if there is something in there I can flip in the logic. :)
Aaron, &nbsp;I think your way would be best, I just cant figure it out. &nbsp;:( &nbsp;I did manage to get the Red X to appear when the current health equalled the max health. &nbsp;If anyone could lend a hand, I would be very grateful. &nbsp;
1447034991
The Aaron
Pro
API Scripter
Ed A. said: Aaron, &nbsp;I think your way would be best, I just cant figure it out. &nbsp;:( &nbsp;I did manage to get the Red X to appear when the current health equalled the max health. &nbsp;If anyone could lend a hand, I would be very grateful. &nbsp; Find this line in the function NewColor(): var color = hsl2rgb(ratio, 100, 50); Try it like this: var color = hsl2rgb( 120-ratio , 100, 50); I think that should work... &nbsp;:)
Works like a champ! &nbsp;Thanks Aaron! &nbsp;:)
1447116687
The Aaron
Pro
API Scripter
Sweet! &nbsp;:)
1447850524

Edited 1447850559
This scripts relies on PC and NPC tokens to have a corresponding character sheet they are tied to as "represents" and that token assigned to the sheet, so it can differentiate between whats a mob/player and a random environment token. Is there any way you could add a functionality where one adds mook tokens once and the script maintains a list of all mooks because this is my biggest concern at the moment. I usually have like 6-7 mooks which are not linked to a character sheet as this would interfere with the scripts I am using and exactly they are the ones where I would need your script becaues for the big named guy players do remember if I tell them "yeah he is shot" but after 1 hour of combat no one remembers "was it mook 4 or mook 5 or mook 7 who got the arrow to the knee?" I am thinking of something like: Select all mooks, Issue a chat command, Mooks are now handled by Aura-Tint
I keep getting this error: (When I click save script, it works for about 5 min then stops again) /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ TypeError: Cannot call method 'get' of undefined at handleToken (evalmachine. :57:45) at eval ( This is in the output:&nbsp; /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ TypeError: Cannot call method 'get' of undefined at handleToken (evalmachine.&lt;anonymous&gt;:57:45) at eval (
1452110499
The Aaron
Pro
API Scripter
Are you running any other scripts? &nbsp;Try it with them disabled and see if you get the same behavior.
Is there anyway to remove the name control from this? My players love the auras but honestly the hide/show names almost never works for me and frankly every time I start the API I have to manually go into every token and turn off the names. I'd love to keep using this API, but the sanity of so many clicks is taking its toll! Love everything else about though! :D
1454898250
The Aaron
Pro
API Scripter
If you run !aura, you should be able to turn that feature to off. It's set in the state and should be persisted across API restarts.&nbsp;
My sanity thanks you sir! I never clicked that option because I assumed it meant the auras not names. Thank you!
1458187278

Edited 1458188037
Another question for Shadowrun, and this one is a TokenMod/AuraTint crossover! &nbsp;Since this is Shadowrun, death is when you "collect" damage and hit/exceed a damage threshold. &nbsp;Currently when I use TokenMod to apply damage equal to or greater than the character's max damage threshold (death), the Aura/Tint Health Color script does not cue up the dead condition where the red x is applied unless I pick up and move the token one space (damage is applied correctly, it just doesnt add the "X"). &nbsp;Any ideas? &nbsp;:)
1458217119
Alicia
Sheet Author
TokenMod hasn't been updated to update AuraTint script but the Alter Bars script&nbsp; by HoneyBadger has been. The Aaron actually helped in providing an alternate version of both scripts which allow them to talk to each other:&nbsp; <a href="https://gist.github.com/shdwjk/36025e18d770862abaa" rel="nofollow">https://gist.github.com/shdwjk/36025e18d770862abaa</a>... You'll need to add both scripts with the versions in the gist.
1458267928
The Aaron
Pro
API Scripter
I updated that gist to have a TokenMod that should cause the AuraHealth to update.
Once again, works amazingly well. &nbsp;You are the man!&nbsp;
1460300198
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hi DX, The script is amazing, but there is one issue I've run into. If you disable an option after already having it on, any currently active effects don't end. Thanks, Scott
1462180375
Zym
Sheet Author
I use this API, I think it is great ! I was wondering I use the Death Effect Sound, however I try to turn the volume of it down because it is very loud, not a huge problem, but everytime it plays it starts at max volume. (Not where I put the slider the last time)
1463726692
Zym
Sheet Author
This is sort off odd because of my last post praising this api. However great it is, I find myself re-saving the Script in order for it to work. Sometimes in the middle of a three hour game it stops working, and I have to go back into my settings and save the script again so it is "recognised" again. Its a small annoyance, which I have been just putting up with for three years, yes really, that long. However I would love to get this issue fixed so I never have to worry about the NPC names suddenly appearing halfway through a game, etc, etc. Please help!
1463744229
Alicia
Sheet Author
Alexander said: This is sort off odd because of my last post praising this api. However great it is, I find myself re-saving the Script in order for it to work. Sometimes in the middle of a three hour game it stops working, and I have to go back into my settings and save the script again so it is "recognised" again. Its a small annoyance, which I have been just putting up with for three years, yes really, that long. However I would love to get this issue fixed so I never have to worry about the NPC names suddenly appearing halfway through a game, etc, etc. Please help! As this script is only about a year old, maybe there's &nbsp;something else causing a conflict. I've used the script since it came out and didn't have problems with this one erroring out but another. Perhaps if you list out what ones you're using we can help you isolate the troublemaker.
1463762779
Zym
Sheet Author
Okay I will have a look, double check and see what's going on under the bonnet. If I can't solve it I'll be back here :-)
1463763955
Zym
Sheet Author
I deleted one possible conflicting scripit. Now I have these running: 5th Edition OGL by Roll20 Companion Aura.js 5e-shaped-scripts.js They seem to work no issues. How do I change PCPC, PCNPC, GMPC, and GMNPC to be turned OFF constantly.&nbsp;
1463768285
The Aaron
Pro
API Scripter
Running: !aura Will bring up a configuration menu that you can use to set things on or off as desired. &nbsp;The setting will be persisted in the state so once you set it, it will be fixed until you change it or install in a new Game, where you will need to configure it again.
Is there any easy way to substitute the back-pain status instead of the big red x?