-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} | ||
}); |