Skip to content

Instantly share code, notes, and snippets.

@jenthura
Last active January 24, 2022 07:27
Show Gist options
  • Save jenthura/095dd141b94c7a4be30f0911fc4436f7 to your computer and use it in GitHub Desktop.
Save jenthura/095dd141b94c7a4be30f0911fc4436f7 to your computer and use it in GitHub Desktop.
DC randomizer for Foundry VTT
function postToChat(num, label){
var plusOrMinus = Math.random() < 0.5 ? -1 : 1;
console.log(plusOrMinus)
let DC = num+plusOrMinus*(Math.floor(Math.random()*4));
console.log(DC)
let chatData = {
user: game.user._id,
speaker: {alias: "DC"},
content: `The ${label} DC is: <b>${DC}<b>`,
whisper : ChatMessage.getWhisperRecipients("USERNAME_OF_GM")
};
ChatMessage.create(chatData, {});
};
let d = new Dialog({ //dialog object creates the window with all the buttons
title: "Difficulty Class",
content: `<h2>Choose a difficulty.<h2>`,
buttons: {
one: {
label: "Trivial",
callback: () => {postToChat(5,"Trivial")}
},
two: {
label: "Easy",
callback: () => {postToChat(10,"Easy")}
},
three: {
label: "Moderate",
callback: () => {postToChat(15,"Moderate")}
},
four: {
label: "Hard",
callback: () => {postToChat(20,"Hard")}
},
five: {
label: "Very Hard",
callback: () => {postToChat(25,"Very Hard")}
},
six: {
label: "Nearly Impossible",
callback: () => {postToChat(30,"Nearly Impossible")}
}
},
default: "one",
render: html => console.log("Register interactivity in the rendered dialog"),
close: html => console.log("This always is logged no matter which option is chosen")
});
d.render(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment