This repository has been archived on 2026-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
vtt_sys_ravenous/module/macro.js

24 lines
848 B
JavaScript

/**
* Create a Macro from an attribute drop.
* Get an existing vtt_sys_ravenous macro if one exists, otherwise create a new one.
* @param {Object} data The dropped data
* @param {number} slot The hotbar slot to use
* @returns {Promise}
*/
export async function createvtt_sys_ravenousMacro(data, slot) {
if ( !data.roll || !data.label ) return false;
const command = `const roll = new Roll("${data.roll}", actor ? actor.getRollData() : {});
roll.toMessage({speaker, flavor: "${data.label}"});`;
let macro = game.macros.find(m => (m.name === data.label) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: data.label,
type: "script",
command: command,
flags: { "vtt_sys_ravenous.attrMacro": true }
});
}
game.user.assignHotbarMacro(macro, slot);
return false;
}