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: roll hp and apply to bar 1 of an npc token.

1495844230

Edited 1500678128
Simple script I wrote this afternoon, full of holes but whatever. Probably already exists but it was fast to write so again whatever. - just click on a token that represents a monster/npc that uses the 5e ogl sheet(npc option only). - type !hpgen (or make a macro button) voila the script rolls the npc health by reading the hit point formula and then assigns the roll result to bar 1's max/current as a number value (not directly attached to the sheet's hit point value). Keep your players guessing! no more figuring out that the gerblins all have 7 hp! on('chat:message',function(msg){     if(msg.type == 'api'){         if(msg.content == '!hpgen'){             if(msg.selected == null){                 sendChat('HP Gen','/w gm Nothing selected');             }else{                 msg.selected.forEach(function(Sel){                     var tokenObj = getObj('graphic',Sel._id);                     //log(tokenObj);                     var CharObj = getObj('character',tokenObj.get('represents'));                     //log(CharObj);                     var diceRoll = getAttrByName(tokenObj.get('represents'),'npcd_hpformula');                     //log(diceRoll);                     sendChat('', '/r '+diceRoll, function(ops) {                         //log(ops);                         //log(ops[0].content);                         //log(JSON.parse(ops[0].content).total);                         var Hp = JSON.parse(ops[0].content).total;                         //log(tokenObj);                         tokenObj.set('bar1_value',Hp);                         tokenObj.set('bar1_max',Hp);                         //log(Hp);                         //log(tokenObj);                         //log(ops.content.total);                     });                     //log(maxHealth);                 });             };         };     }; });
Thank you.  This is exactly what I wanted.