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

PC Auto Hit Dice" problems

I found an API that automatically adds hit dice rolled to your character sheet as well as deduct the hit die and informs you if you have no hit die or if you are at max hp. I have 2 problem the first and most sever is that for some reason that I can not find it does not work on all of my players character sheets. it works on 3 of the 4. I have tried this API in a completely different game and 2 out of 10 character sheet in that game did not work and by not working I mean that there is no evidence that the API is even in the game. there is no errors or wrong exsiccation just a normal hit die roll. the second and far more miner is that it it does not work with the show hit die per class option at all. I assume because it is displayed completely differently and I do not possess the skill or knowledge to change the character sheet or adapt the API. any help would be appreciated. the API is as fallows: on('chat:message', function(msg) { // ROLL LISTENER     if(msg.playerid.toLowerCase() != "api" && msg.rolltemplate) {         var cnamebase = msg.content.split("charname=")[1];         var cname = cnamebase ? cnamebase.replace('}}','').trim() : (msg.content.split("{{name=")[1]||'').split("}}")[0].trim();         var character = cname ? findObjs({name: cname, type: 'character'})[0] : undefined;         if(["simple"].indexOf(msg.rolltemplate) > -1) {             if(_.has(msg,'inlinerolls') && msg.content.indexOf("^{hit-dice-u}") > -1 && character) {                 handlehd(msg,character);             }         }     } }); // CHECK CURRENT HD, DECREMENT HD, THEN APPLY HP var handlehd = function (msg,character) {     var hd = findObjs({type: 'attribute', characterid: character.id, name: "hit_dice"}, {caseInsensitive: true})[0];     var hp = findObjs({type: 'attribute', characterid: character.id, name: "hp"}, {caseInsensitive: true})[0];     if(!hd || hd.get("current")==="" || hd.get("max")==="") {         log("CHARACTER HAS NO HIT_DICE ATTRIBUTE OR HD CURRENT/MAX IS NULL");         sendChat(msg.who, "<div class='sheet-rolltemplate-simple' style='margin-top:-7px;'><div class='sheet-container'><div class='sheet-label' style='margin-top:5px;'><span>" + "HD attribute on " + character.get("name") + " is missing or current/max values are not filled out, Hit Points were not applied." + "</span></div></div></div>");         return;     }     else if(!hp || hp.get("current")==="" || hp.get("max")==="") {         log("CHARACTER HAS NO HP ATTRIBUTE OR HP CURRENT/MAX IS NULL");         sendChat(msg.who, "<div class='sheet-rolltemplate-simple' style='margin-top:-7px;'><div class='sheet-container'><div class='sheet-label' style='margin-top:5px;'><span>" + "HP attribute on " + character.get("name") + " is missing or current/max values are not filled out, Hit Points were not applied." + "</span></div></div></div>");         return;     }     else {         var curhd = parseInt(hd.get("current"));         var newhd = curhd - 1;     }          var maxhp = parseInt(hp.get("max"));     var curhp = parseInt(hp.get("current"));              if (curhd === 0) {         sendChat(msg.who, "<div class='sheet-rolltemplate-simple' style='margin-top:-7px;'><div class='sheet-container'><div class='sheet-label' style='margin-top:5px;'><span>" + character.get("name") + " has no HD remaining, HP were not applied." + "</span></div></div></div>");     } else if (curhp === maxhp) {         sendChat(msg.who, "<div class='sheet-rolltemplate-simple' style='margin-top:-7px;'><div class='sheet-container'><div class='sheet-label' style='margin-top:5px;'><span>" + character.get("name") + " already at full HP, no HD used." + "</span></div></div></div>");     }     else {         hd.set({current:newhd});         var result = msg.inlinerolls[2].results.total ? msg.inlinerolls[2].results.total : false;         var newhp = curhp + result;         if(result === false) {             log("FAILED TO GET HD RESULT");         }         else if (newhp > maxhp) {             hp.set({current:maxhp});         }         else {             hp.set({current:newhp});         }     } };
1642433992
timmaugh
Forum Champion
API Scripter
There is some weirdness in that script in how it is detecting the character... and possibly a problem with the inline roll for the HP being the correctly identified on in the order of inline rolls. I can tweak it for you, but to make sure we get it right, can you post the actual template message you are sending through the chat to trigger this script?
I am sorry I am new to this hole API deal. I do not know what you mean by " post the actual template message you are sending through the chat to trigger this script?" my best guess is that you are talking about a chat command, the things that start with ! but there is not one for this. if you could dumb down the steps you need me to take I will try my best. 
1642452752

Edited 1642452763
timmaugh
Forum Champion
API Scripter
No worries, tenebris. I can tell from reading the script that it isn't looking for a command that actually starts with an exclamation point. It's instead picking up on a message that is sent as a template (containing the text: &{template:<templatename>} But that template will have other parts in the form of: {{label=data}} Those are the parts that I want to see. So if this is coming from a button on your sheet, you might be able to send the command, then put your cursor in the chat box and arrow up to see what was just sent. Copy that and paste it here. If the result of that isn't a template statement, it will likely be an attribute or ability. Find that on your sheet and the "current" value will be the template statement we're looking for. Once we can see the template statement we can make sure it fits all of your characters. For instance, copy it from a working character and from a non-working character. I bet something in the components of the template in the message is throwing things off.
NOT working @{Kilskan |wtype}&{template:simple} {{rname=^{hit-dice-u}}} {{mod=D@{Kilskan |hitdieroll}+[[@{Kilskan |constitution_mod}[CON]]]}} {{r1=[[1d@{Kilskan |hitdieroll}+[[@{Kilskan |constitution_mod}]][CON]]]}} {{normal=1}} @{Kilskan |charname_output} WORKING  @{Lyria Dawnbringer|wtype}&{template:simple} {{rname=^{hit-dice-u}}} {{mod=D@{Lyria Dawnbringer|hitdieroll}+[[@{Lyria Dawnbringer|constitution_mod}[CON]]]}} {{r1=[[1d@{Lyria Dawnbringer|hitdieroll}+[[@{Lyria Dawnbringer|constitution_mod}]][CON]]]}} {{normal=1}} @{Lyria Dawnbringer|charname_output}
I'm not a scripter, but I'm noticing a space after the name of Kilskan before the vertical pipe and attribute in each of those examples - try editing the Kilskan character sheet and removing any extra space after the name to see if that might be causing an error.
How would I edit those?
1642460282
timmaugh
Forum Champion
API Scripter
It would be the character name field on the character sheet you would need to edit to lose the extra white space.
Thanks for the help. It was literally just a space after the character name.