Skip to content

Instantly share code, notes, and snippets.

@chrisjbrown
Last active March 27, 2024 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisjbrown/e9a129e34d52ccdbe426945d9365470c to your computer and use it in GitHub Desktop.
Save chrisjbrown/e9a129e34d52ccdbe426945d9365470c to your computer and use it in GitHub Desktop.
foundryvtt name giver macro
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