Last active
March 27, 2024 08:53
-
-
Save chrisjbrown/e9a129e34d52ccdbe426945d9365470c to your computer and use it in GitHub Desktop.
foundryvtt name giver macro
This file contains hidden or 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
async function setName(type) { | |
const token = canvas.tokens.controlled[0] | |
if (!token) { | |
return; | |
} | |
if (type === "Dragon") { | |
const dragonTable = game.tables.getName(`Dragon Name`); | |
let dragonName = await dragonTable.roll(); | |
return token.document.update({name: `${dragonName.results[0].text}`}); | |
} else { | |
const name1 = game.tables.getName(`${type} First Name`); | |
const name2 = game.tables.getName(`${type} Last Name`); | |
let n1 = await name1.roll(); | |
let n2 = await name2.roll(); | |
token.document.update({name: `${n1.results[0].text} ${n2.results[0].text}`}); | |
return | |
} | |
} | |
const buttons = ["Dragon", "Dwarf", "Elf", "Gnome", "Goblin", "Halfling", "Human", "Orc", "Tiefling"].reduce((acc, type, index) => { | |
acc[type] = { | |
label: type, | |
callback: () => setName(type), | |
icon: `<i class="fas fa-check"></i>` | |
} | |
return acc; | |
}, {}); | |
new Dialog({ | |
title: "My Dialog Title", | |
content: "My dialog content", | |
buttons: buttons | |
}).render(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment