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] Health Levels

1560168269

Edited 1560288764
AndrielChaoti
API Scripter
Just like in the old CRPGs, you could mouse over any creature on the battlefield and get a "wound levels" themed readout of their hit points in 25% increments. That's what this script does. Right now it only uses the Roll20 5e OGL character sheet template, but could be expanded to add more template support (when I learn how to :P) Here it is on GitHub . Let me know what you think or report any bugs. Using the script is pretty simple, it only has one command. !hp [token_id] This will show in the chat window a readout of the token's current HP, expressed as a descriptive word, instead of an exact value. Works easiest if you use it in a macro (currently): !hp @{target|token_id} Here's what it looks like in chat:
So it looks like it gets the target token and spits out one of a few options for how healthy it is.  I assume it uses targeting so your players can look at NPCs?
1560169068

Edited 1560171108
AndrielChaoti
API Scripter
Yeah, I meant to add the command and a screenshot of what it does, you just beat me to it :P Edit: I should also mention it does take into account the dead  status icon on tokens and will report "dead" or "unconcious" depending on that, too...
I like this!
1560193850

Edited 1560193898
GiGs
Pro
Sheet Author
API Scripter
Nice idea. I havent looked closely at the script but I notice your respond function is a bit inefficient (unless there's some subtlety I'm missing - totally possible!). The issue is this bit: var characters = findObjs({_type: 'character'}); var speaking; characters.forEach(function(chr) { if(chr.get('name') == msg.who) speaking = chr; }); You loop through all the characters, and get character name there, when you can do it in the findObjs function var character = findObjs({_type: 'character', name: msg.who})[0];         // this will be empty if no character of that name exists. // if the character exists, use character id, otherwise player id var speaking = character ? 'character|' + character.id: 'player|' + msg.playerid; This allows a simpler sendChat - no if statement: sendChat(speaking, out, null, {noarchive: true}); Both of these methods might not work properly if you have multiple characters with the same name, which is unfortunately possible. best avoid that! Also, I personally wouldnt pass the whole msg object to the function, I'd just pass the msg.playerid and msg.who parts, but that would require a bigger rewrite. One other point. You might have issues with this line if bar1_max is empty, or if the bars contain text: var bar1_percent = (tokens[0].get('bar1_value') / tokens[0].get('bar1_max')) * 5; I'd grab the value and max as variables and test them first, like var value = tokens[0].get('bar1_value'); var max = tokens[0].get('bar1_max'); // check bars aren't empty, and that they are numbers if(value === '' || max === '' || isNaN(value) || isNaN(max) { // an error message here return; } // proceed with the calculation
Thanks for the constructive criticism! The first version is basically just what I am using in my game. I planned to do something of a rewrite to make it more configurable for other people and their games for sure.