Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This macro is used to generate a death reason when an NPC token drops to 0 HP
- console.log("+++++++++++++ DEATH REASONS CALLED =====================");
- if (args[0] === "on") {
- // let showingName = token.actor.token.data.name;
- let showingName = canvas.tokens.get(args[1]).data.name;
- await deathReason(showingName);
- }
- console.log("+++++++++++++ DEATH REASONS ENDED =====================");
- async function deathReason(showingName) {
- //This is the RollTable method. You should create a RollTable called 'DeathReasons' to make this work.
- let tableName = "DeathReasons";
- let table = game.tables.contents.find(t => t.name == tableName);
- // Roll the result, and mark it drawn
- if (table) {
- if (checkTable(table)) {
- let roll = await table.roll();
- let resultItem = roll.results[0];
- var reason = resultItem.data.text;
- console.log(reason);
- }
- }
- function checkTable(table) {
- let results = 0;
- for (let data of table.data.results) {
- if (!data.drawn) {
- results++;
- }
- }
- if (results < 1) {
- table.reset();
- ui.notifications.notify("Table Reset");
- return false;
- }
- return true;
- }
- game.togglePause();
- let result = await Dialog.prompt({
- title: showingName + ' has dropped to 0 HP',
- content: `<p><i>` + showingName + ` ` + reason + `</i></p><br /><p><strong>How do you want this to happen?</strong></p><p>Anything to add?</p><p><input type="text"></p>`,
- callback: (html) => html.find('input').val()
- })
- await ChatMessage.create({content: showingName + " " + reason + "<br /><br />" + result});
- game.togglePause();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement