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

5e OGL Sheet, Hit Dice API

I found this API for 5e OGL Sheet, but it seems to be not working anymore:&nbsp; <a href="https://app.roll20.net/forum/post/5581501/slug%7D#newtopic" rel="nofollow">https://app.roll20.net/forum/post/5581501/slug%7D#newtopic</a> Is there other API that may substitute this one?
Try this on('chat:message', function (msg) { // ROLL LISTENER if (msg.content.includes("hit-dice-u") &amp;&amp; msg.playerid.toLowerCase() != "api" &amp;&amp; msg.rolltemplate) { var cname = msg.content.split("charname=")[1].split('{{')[0].trim().replace(/}}/, '').trim(); log("cname: " + cname) 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") + " alread 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 }); } } };
1585770959

Edited 1585771680
Tried, but nothing happened as well. Should I use a "!" command? I'm testing simply rolling the hitdice from the character sheet and verifying if the hitpoints are added (and if the total hitdie number decreases).&nbsp; However, this error message is prompting in the chat: " No attribute was found for @{Bellami Madrazzo|licensedsheet}". Bellami Madrazzo is the character's name and it has an attribute named "hit_dice". The error message only prompts if I try to roll a hit dice from a macro instead of the character sheet (though I simply dragged the roll from the sheet itself to the macro bar). EDIT: It worked now (don't know why), although it keeps prompting the error message. Thanks btw
it is so odd that the script is working for me but not for you. For some reason the 5e sheets do have different outputs.&nbsp; can you look at the api log for the name line? is it right?
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 }); } } }; Try this!
1585781034

Edited 1585783172
I figured it out that it only prompts the error message if I roll hitdie through the macro dragged from the sheet. If the roll is made through the sheet, it works perfectly. The script seems to be correct. By the way, the way it is, that's just fine, it its working. No need for you guys to spend more time on this. Thank you very much. EDIT: @ Anthony V. &nbsp;I just tested yours as well, but it seems to have the same problem.&nbsp;
Maurício Garcia said: I figured it out that it only prompts the error message if I roll hitdie through the macro dragged from the sheet. If the roll is made through the sheet, it works perfectly. The script seems to be correct. By the way, the way it is, that's just fine, it its working. No need for you guys to spend more time on this. Thank you very much. EDIT: @ Anthony V. &nbsp;I just tested your as well, but it seems to have the same problem.&nbsp; If you have the alter bars script you can use this macro and just adjust he bar accordingly !alter --target|@{selected|token_id} --bar|1 --amount|?{What Size Hit Dice?|1d6|1d8|1d10|1d12}+@{constitution_mod} !setattr --sel --mod --hit_dice|-1