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

Report HP script

I'm learning Java now, but integrating it into Roll20 is another matter all together. Suffice to say, I'm in over my head. What I'm looking for is a small script that would allow players to type something into chat("!myhp" maybe) that would look at the hit point bar / circle (#1 in my game... #1 meaning the one in the middle) and report in chat "Player X has n hp out of max which equals percentage". So if my Ranger Bjorn had a max of 42 hp and was currently at 30, the player could type '!myhp' into chat and you would see a return of "Bjorn has 30hp out of 42, which is 71%" . This would greatly help teh cleric as well as giving each player a running glimpse whenever they wanted, especially if you make a macro for it. A one-click status update. Any help would be appreciated.
1393472373

Edited 1393530455
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
{REMOVED CODE} This likely has all the "parts" you would need.
1393472431
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
That is not EXACTLY what you are looking for but everything you need is in there.
Stephen, I wish you were at my house so i could make you breakfast. I'm making pancakes for everyone this morning, you'd be in luck. But seriously, thank you. :) Now, what are the keys / input needed to make this thing run? Also, are you 'DarokinB'? Because I use the name Darokin all the time in my games. Weird.
1393511567

Edited 1393511639
Alex L.
Pro
Sheet Author
Kim H. said: Stephen, I wish you were at my house so i could make you breakfast. I'm making pancakes for everyone this morning, you'd be in luck. But seriously, thank you. :) Now, what are the keys / input needed to make this thing run? Also, are you 'DarokinB'? Because I use the name Darokin all the time in my games. Weird. That script doesn't use a command (this is why he said it doesn't do exactly what you want) it just outputs the value of bar1 when it is changed or when an attribute called "HP" is changed. This script isnt ready for production use, it will for instance say something twice if you have bar1 linked to HP, I expect Stephen just wanted to give you an example of how to track when hp has changed.
1393511674
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
I will tweak it to meet your needs. Wasn't sure if you just wanted a starting point or a script. Look for it later today.
Good. I'm learning. I looked it over and thought to myself, "Self, this doesn't seem to have a 'keyword' or trigger anywhere. Hmmm." I feel good because I was correct. One step closer to ultimate Javascripting. I used the script in my game (well, tested it) and it is pretty cool. I think I can change it around and see what happens. Thanks, Alex. Pancakes for you, too.
Stephen S. said: I will tweak it to meet your needs. Wasn't sure if you just wanted a starting point or a script. Look for it later today. Oh, that's pretty nice of you. I'm assuming the allure of pancakes is what turned the tide. I'm going to poke around with it as well and see what I can break. But please continue your work because I'm about 73% sure I will screw it up. Thanks. :)
1393513552
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
That is what we all do... then Brian, Alex, and Badger fix it.
1393521194
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Set up a marco that is token action (or in the bar... up to you.) The action should be: !percenthp on("chat:message", function(msg) {if(msg.type == "api"){processMessage(msg)};}); processMessage = function(msg) {if(msg.type !== "api"){return}; if(msg.content == "!percenthp"){percenthp(msg)}; }; percenthp = function(msg) { var currentHP = new Array(); var count = 0; var selectedObjs = msg.selected; _.each(selectedObjs, function(obj) { var token = getObj('graphic', obj._id); if(token.get("represents").length > 0){ currentHP[count] = "<tr><td>"; currentHP[count] += token.get("name"); currentHP[count] += "</td><td>"; currentHP[count] += (parseInt(token.get("bar1_value")) / parseInt(token.get("bar1_max")) * 100).toFixed(2) currentHP[count] += "%</td></tr>"; count ++; }; }); var hpReport = "/direct <table><tr><td>Name</td><td>% Health</td></tr>"; for(var i=0, len=currentHP.length; i < len; i++){ hpReport += currentHP[i]; }; hpReport += "</table>"; sendChat("API", hpReport); }; This will return the HP in a table for all named tokens selected (just 1 token or however many you select.) I hope this helps =P
1393525442

Edited 1393526128
Hey, you are awesome. I had written in here that I couldn't get it to work, But it is working now. Select token on the screen, do not type the name after !percenthp. That's the ticket. Thanks again, brother.
1393530419
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
No worries... nice thing about this is you can select the entire group, and they all snow up..... the table could be formatted better.. but this works.
Like a charm. And I'm poking around at it and learnin' some stuff.
This probably isn't productive, or all that applicable to the discussion... but now I want pancakes.. That being said.. something that actually applies to this: I do like the idea that players can call information with commands like that. I think that if this were to be a starting point for something bigger, it could turn into a way to have a player inquire about their own information (Such as HP, Surges, Power Points, money, number of alchemical items left, potions, arrows, daggars... pretty much anything someone could want to know..).. or that of a party member. I'm sure there are plenty of other uses for this, but that's just what I'm getting at the moment.
1393712911
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Not sure its worth it... but you can get a nice bar graph in chat.
How did you do that, Stephen? That's awesome. Also, does that show up in everyone's chat? I've never seen chat with a gray background that begins, "API".
1393724561
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Everyone sees that: var divtag = "<div style='\ position:relative; \ margin:2px; \ padding-top:4px; \ padding-bottom:4px; \ padding-right:4px; \ padding-left:4px; \ width:99%; \ '>" var tabtag = "<table style='width:100%; height:20px; border-collapse:collapse;'><tr>" var tdhpend = "color:white; \ text-align:right; \ background: rgb(169,3,41); \ background: red; \ '>" var tblend = "background: blue;'></td></tr><table><hr>" on("chat:message", function(msg) {if(msg.type == "api"){processMessage(msg)};}); processMessage = function(msg) {if(msg.type !== "api"){return}; if(msg.content == "!percenthp"){percenthp(msg)}; }; percenthp = function(msg) { var currentHP = new Array(); var playerBar = new Array(); var count = 0; var selectedObjs = msg.selected; _.each(selectedObjs, function(obj) { var token = getObj('graphic', obj._id); if(token.get("represents").length > 0){ var percentHealth = (parseInt(token.get("bar1_value")) / parseInt(token.get("bar1_max")) * 100).toFixed(0) currentHP[count] = token.get("name"); currentHP[count] += tabtag; currentHP[count] += "<td style='width:" + percentHealth + "%; " + tdhpend; currentHP[count] += percentHealth + "%</td>" currentHP[count] += "<td style='width:" + (100 - percentHealth) + "%; "; currentHP[count] += "background: DarkGray;'></td></tr><table>" count ++; }; }); var hpReport = "/direct " + divtag; for(var i=0, len=currentHP.length; i < len; i++){ hpReport += currentHP[i]; }; hpReport += "</div>"; sendChat("API", hpReport); }; I haven't check that code very closely.
That's pretty amazing.