Advertisement Create a free account

[Script] [D&D 5e OGL Sheet] Fix for Hit Dice Helper

1584963431

Edited 1585227608
Hello there! I was trying to make Hit Dice Helper (by @Kevin&nbsp; <a href="https://app.roll20.net/forum/post/5581501/scriptlet-5e-ogl-hit-dice-helper" rel="nofollow">https://app.roll20.net/forum/post/5581501/scriptlet-5e-ogl-hit-dice-helper</a>) &nbsp;working for DnD 5e Roll20 Sheet with 5e OGL Companion script and I realised that HD Helper&nbsp;wasn't working properly. After some debugging I found out that, probably, the way character name is displayed in Dice Hit roll message was changed. Anyhow, I fixed the issue with editing fourth line of the script to properly split the {{ }} part and extract character's name. Let me know if you found any bugs, I'll be happy to fix them :) Here is the fixed script: <a href="https://gist.github.com/Kayne/207baef8da25c3002fb1612dd1d6eb9d" rel="nofollow">https://gist.github.com/Kayne/207baef8da25c3002fb1612dd1d6eb9d</a>
1585078203

Edited 1585078377
GKDM
Pro
Can you apply this fix on feid's fix of this same script, where he has it not reduce hit dice if the character is at max health? Link:&nbsp; <a href="https://app.roll20.net/forum/post/8057688/auto-hit-dice-script-broke-with-new-hit-die-layout-can-anyone-fix/?pageforid=8105010#post-8105010" rel="nofollow">https://app.roll20.net/forum/post/8057688/auto-hit-dice-script-broke-with-new-hit-die-layout-can-anyone-fix/?pageforid=8105010#post-8105010</a> I believe I did it by taking the first chunk of your fix and replacing the first chunk of his fix and ended up with: on('chat:message', function(msg) { // ROLL LISTENER if(msg.playerid.toLowerCase() != "api" &amp;&amp; msg.rolltemplate) { var cnamebase = msg.content.split("charname=")[1].split('{{')[0]; // Fixed line 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) &gt; -1) { if(_.has(msg,'inlinerolls') &amp;&amp; msg.content.indexOf("^{hit-dice-u}") &gt; -1 &amp;&amp; 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, "&lt;div class='sheet-rolltemplate-simple' style='margin-top:-7px;'&gt;&lt;div class='sheet-container'&gt;&lt;div class='sheet-label' style='margin-top:5px;'&gt;&lt;span&gt;" + "HD attribute on " + character.get("name") + " is missing or current/max values are not filled out, Hit Points were not applied." + "&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"); 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, "&lt;div class='sheet-rolltemplate-simple' style='margin-top:-7px;'&gt;&lt;div class='sheet-container'&gt;&lt;div class='sheet-label' style='margin-top:5px;'&gt;&lt;span&gt;" + "HP attribute on " + character.get("name") + " is missing or current/max values are not filled out, Hit Points were not applied." + "&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"); 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, "&lt;div class='sheet-rolltemplate-simple' style='margin-top:-7px;'&gt;&lt;div class='sheet-container'&gt;&lt;div class='sheet-label' style='margin-top:5px;'&gt;&lt;span&gt;" + character.get("name") + " has no HD remaining, HP were not applied." + "&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"); } else if (curhp === maxhp) { sendChat(msg.who, "&lt;div class='sheet-rolltemplate-simple' style='margin-top:-7px;'&gt;&lt;div class='sheet-container'&gt;&lt;div class='sheet-label' style='margin-top:5px;'&gt;&lt;span&gt;" + character.get("name") + " already at full HP, no HD used." + "&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"); } 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 &gt; maxhp) { hp.set({ current: maxhp }); } else { hp.set({ current: newhp }); } } }; GKDM (GM): <span class="userscript-inlinerollresult showtip tipsy-n-right fullfail" title=" Rolling 1d6+0[CON] = ( 1 )+0" style="font-size: 1.2em ; line-height: 12px ; background-color: transparent ; border: 0px ; padding: 0px ; cursor: help ; color: rgb( 179 , 21 , 21 )">1 HIT DICE&nbsp; (D6+ 0 ) Levi Levi already at full HP, no HD used.
1585227415

Edited 1585227795
It's funny :) I just reviewed his changes and actually they are better. Also, I tested his solution and it's working all just fine. He's fix is different because he updated the next line to the one I did and the outcome is the same, actually (at least as long as we are talking only about fetching correct character name). So you are good to just use his version and mine should be forgotten :) So topic is good to be closed/archived/deleted/whatever. (also, I don't know why, but in your post here you've also changed the second line, the one starting with " var cname = cnamebase ? cnam....". This is exactly the line which feid's solution is better then what I did)