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

Auto Hit Dice Script Broke with new Hit Die Layout Can anyone fix?

I have been using this script for a while now it is so convenient. It would auto reduce your hit die when you rolled them as well as heal your character the amount rolled.Can anyone help make this work again? 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; } 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 { hd.set({current:newhd}); var maxhp = parseInt(hp.get("max")); var curhp = parseInt(hp.get("current")); 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}); } } };
1579291492

Edited 1579291533
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
If you are using the companion script, this macro should work. I believe this is the old macro. The new macro that is built into the sheet does not. You will need to have the character's token selected in order to run it. @{selected|wtype}&{template:simple} {{rname=^{hit-dice-u}}} {{mod=D@{selected|hitdie_final}+[[@{selected|constitution_mod}[CON]]]}} {{r1=[[1d@{selected|hitdie_final}+[[@{selected|constitution_mod}]][CON]]]}} {{normal=1}} @{selected|charname_output}
1580891298

Edited 1581000327
I fixed it for myself but i'm no real dev :P But I've also added the function that no hitdice is used at full hp.  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             });         }     } };
Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: SyntaxError: Unexpected token . I keep getting this error when trying to install your script is there something i am doing wrong?
1580933534
GiGs
Pro
Sheet Author
API Scripter
One line is repeated twice, probably copy/paste error. Change this hd.set({ hd.set({ to hd.set({
Thanks! dont know how that happened :) Fixed it. 
feid said: Thanks! dont know how that happened :) Fixed it.  I am no longer getting the error but it doesn't seem to be doing anything when characters roll hit die.
thats odd. are u using the ogl 5e sheet? for me it's working if i copy it from here into a new game. did u try at full health?
feid said: thats odd. are u using the ogl 5e sheet? for me it's working if i copy it from here into a new game. did u try at full health? Yes I am using OGL sheet but its not working for me in a new game.
1585153705

Edited 1585153806
Bryn
Marketplace Creator
I also miss this scipt. Its been unavailable to me for months now like the OP. I have tried the updated script posted by Feid but it doesn't work for me either. I have the OGL character sheet. Also at full health it doesn't do anything. I was curious if I am missing a dependency ? FYI the macro posted by keithcurtis does work, and its a work around for now. But I love the automation of the script.
Just copied the script to see if I can work on it to get it to work and it's working for me without having to make anychanges.
I posted this a couple days ago, but the subject line was misleading, so I'll repost it here. This is a macro that automatically heals the character based on their hit dice value and Con mod, and decrements the HD number on the OGL character sheet. !token-mod --set bar1_value|[[{@{selected|bar1|max},[[@{selected|bar1}+[[1d@{selected|hitdietype}+[[@{selected|constitution_bonus}]]]]]]}kl1]] --report all|"/em {name} heals {bar1_value:change} points." !modbattr --sel --hit_dice|-1 --fb-public --fb-from @{selected|character_name} --fb-header Hit Dice Tracking --fb-content You have **_CUR0_ Hit Dice** remaining.