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

Increasing all monsters Max HP from their Median to their Maximum.

My group is currently playing Dungeon of the Mad Mage with significantly more players than typically recommended. The DM is looking to level the playing field by switching all the monster's HP values from their Median to their Maximum. (IE: A goblin goes from 7 hp to 12) But there are a lot of enemies in this module, and we're hoping to use an API/Macro to do the job for us. Trouble is, I'm a complete noob at writing for Roll20's API and I'm looking for some help. What I'm looking to do is create a macro (so I can use VTT to roll a bulk macro) that reads the selected token's npc_hpformula, make a roll where "d" is replaced with "*" (ex; 3d6+3 becomes 3*6+3), then write the result back to Bar 1's Max and Min. (I'd also like the code to not run in the case that the npc doesn't have an hp formula, so they don't wind up with Zero HP). I know how to call npc_hpformula. I don't know how to run the find and replace, and I don't know how to write a value directly to a token. Any help would be appreciated.
1616803134
The Aaron
Roll20 Production Team
API Scripter
Here's a script that will do that for all selected tokens.  It assumes you have the hitpoints in bar 1, but you can edit that on line 2 of the script below.  After installing it, just select the tokens to update and run: !max-hp code: on('ready',()=>{ const HP_BAR = 1; const HP_FORMULA_ATTRIBUTE = "npc_hpformula"; on('chat:message',msg=>{ if('api'===msg.type && /^!max-hp(\b\s|$)/i.test(msg.content) && playerIsGM(msg.playerid)){ (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .map(o=>({t:o,c:getObj('character',o.get('represents'))})) .filter(o=>undefined !== o.c) .map(o=>({...o,a:findObjs({type:'attribute',characterid:o.c.id,name:HP_FORMULA_ATTRIBUTE})[0]})) .filter(o=>undefined !== o.a) .forEach(o=>{ sendChat('',`[[${o.a.get('current').replace(/d/g,'*')}]]`,(r)=>{ o.t.set({ [`bar${HP_BAR}_value`]: r[0].inlinerolls[0].results.total, [`bar${HP_BAR}_max`]: r[0].inlinerolls[0].results.total }); }); }) ; } }); });
1616808383

Edited 1616830560
It worked like a charm. Thank you!