Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save p4535992/0ced73ebeca8b54ee28d344818d622da to your computer and use it in GitHub Desktop.
Save p4535992/0ced73ebeca8b54ee28d344818d622da to your computer and use it in GitHub Desktop.
async function determineWeather(currentWeather) {
//roll the dice and get the result
let diceRoll = await new Roll("1d20").evaluate()
let diceResult = await diceRoll.result
// selects the table to roll based on current weather input from Dialog
let tableToRoll
switch (currentWeather) {
case "no":
tableToRoll = "noWind"
break
case "low":
tableToRoll = "lowWind"
break
case "high":
tableToRoll = "highWind"
break
}
//roll on the correct table
const weatherResult = await game.tables.getName(tableToRoll).getResultsForRoll(diceResult)[0].data.text
//content
const content = `
<p style="font-size:22px;">Weather Result:<\p> <span>${weatherResult}</span>
`
//display the content just for the loremaster (or anyone who triggered this macro)
ChatMessage.create({ content, whisper: [game.user] })
}
//Dialog
let weatherPrompt = await Dialog.prompt({
content: `
<h1>Current Weather</h1>
<select id="currentWeather">
<option value="no">No Winds</option>
<option value="low">Low Winds</option>
<option value="high">High Winds</option>
</select>
`,
callback: html => {
let currentWeather = html.find('[id="currentWeather"]:checked').value
determineWeather(currentWeather)
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment