Skip to content

Commit

Permalink
Initial files
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniGrief committed Jun 19, 2023
1 parent 291c2ad commit 16ae171
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
18 changes: 18 additions & 0 deletions module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "hp-roller",
"title": "Hit Point Roller",
"description": "Rolls hit points, similar to Token Mold. But less clutter.",
"authors": [
{
"name": "Tomato"
}
],
"version": "1.0.0",
"compatibility": {
"minimum": "11",
"verified": "11.301"
},
"scripts": [
"scripts/main.js"
]
}
42 changes: 42 additions & 0 deletions scripts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var rollenabled = false;

Hooks.on("init", () => {
game.settings.register("hp-roller", "rolltochat", {
name: "Display roll to chat",
hint: "Displays the rolls in chat as a GM roll",
scope: "client",
config: true,
type: Boolean,
default: false
});
});

Hooks.on("getSceneControlButtons", (controls) => {
const hproll = {
icon: "fas fa-heart-circle-bolt",
name: "hproll",
title: "Toggle HP Rolling",
toggle: true,
visible: true,
onClick: toggled => rollenabled = toggled
};
controls.find((control) => control.name === "token").tools.push(hproll);
});

Hooks.on("preCreateToken", (token, data, options, userId) => {
const actor = game.actors.get(data.actorId);
if (rollenabled == true && data.actorLink == false && actor.type == "npc") {
const formula = getProperty(actor, "system.attributes.hp.formula");
if (formula) {
const roll = new Roll(formula.replace(" ", ""));
roll.roll({async: false});
const finalhp = Math.max(roll.total, 1);
if (game.settings.get("hp-roller", "rolltochat") == true) {
roll.toMessage({rollMode: "gmroll", flavor: data.name + " rolls for hp!"});
}
token.delta.updateSource({"system.attributes.hp.value" : finalhp, "system.attributes.hp.max": finalhp});
} else {
ui.notifications.warn("No HP formula set.");
}
}
});

0 comments on commit 16ae171

Please sign in to comment.