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

Random NPC HPs

I need an easy way to randomly roll NPC hps. The API I used previously is not currently and I have found a number of options, but I cant seem to get any of them to work for me. In an ideal world, I want something that functions on drag and drop to the map. That is what I had working before. Previously I was using RollHPs.. I think. I have installed it, but nothing is happening when I bring an NPC to the map. I do have MonsterHitDice installed as well, hoping that would do the same thing for me. But it just gives the HPs on the sheet, no random roll. I am also using the roll20 OGL companion which has a feature called npchp, but when I make a macro and click it or type the command in chat nothing happens. I realize this one required an extra click.. I can live with that. I just want a way that works for my needs :) In all cases, I have the NPC tokens set up to use bar 1 as HPs and there is no attribute selected.
1573821042

Edited 1573821083
Here's a small script that will roll random hit points for any npc dropped or copy/pasted onto the map that does not have the HP bar linked to the character sheet. const RandomNPCHP = (() => { const HIT_POINT_BAR = 1; // FUNCTIONS const handleTokenDrop = function (obj) { setTimeout(function () { if (obj.get("type") === "graphic" && obj.get("subtype") === "token" && obj.get("represents") !== "" && obj.get("layer") !== "map") { if (Boolean(Number(getAttrByName(obj.get("represents"), "npc"))) === false) return; if (obj.get("bar" + HIT_POINT_BAR + "_link") !== "") return; let CharID = obj.get("represents"); let HPF = getAttrByName(CharID, "npc_hpformula") || "0d0+0"; let HitDie_Count = parseInt(HPF.split("d")[0], 10) || 0; let HitDie_Size = parseInt(HPF.split("d")[1], 10) || 0; let HitDie_Mod = parseInt(HPF.split("+")[1], 10) || 0; let RandomHP = parseInt(Math.floor(Math.random() * ((HitDie_Count * HitDie_Size) - HitDie_Count + 1), 10) + HitDie_Count + HitDie_Mod); obj.set(`bar${HIT_POINT_BAR}_link`, ""); obj.set(`bar${HIT_POINT_BAR}_value`, RandomHP); obj.set(`bar${HIT_POINT_BAR}_max`, RandomHP); } }, 500); } on("ready", function () { //registerEventHandlers(); on(`add:graphic`, handleTokenDrop); }); })();
Thank you much! Works perfectly :)
Why the 500ms delay?
Michael G. said: Why the 500ms delay? Has to happen after the default game settings are applied or it causes problems.
I use TokenMod and: !token-mod --set bar1_max|[[@{selected|hitdice}]] !token-mod --set bar1_reset| When I set up the sheets I use "X"D"Y" (5D8) for the Hit dice, then each new monster gets a tap of the macro and "Bob's your uncle."
1573945649
The Aaron
Roll20 Production Team
API Scripter
You can actually shorten that: !token-mod --set bar1 |[[@{selected|hitdice}]] Using bar1 will set current and max to the same value in one go. =D