Default item macro is overriding my custom item macro

I'm trying to create and assign an item macro to the hotbar. It's mostly working, but has one unexpected behaviour that I cannot figure out. Whenever I drag an item to the hotbar, it creates the macro successfully in the Macros Directory, however a "Display [item name]" macro is also created and that's assigned to the hotbar instead. I'm fairly sure this is the default Foundry item macro and it's overriding my hotbar assignment, as it's stil created and assigned when I comment out my createItemMacro function. Is there any way to disable the "Display [item name]" macro from being created for my items? Thanks in advance 🙂 My createItemMacro function, for reference:
async function createAvariceItemMacro(data, slot) {
// First, determine if this is a valid owned item.
if (data.type !== "Item") return;
if (!data.uuid.includes('Actor.') && !data.uuid.includes('Token.')) {
return ui.notifications.warn("You can only create macro buttons for owned Items");
}
// If it is, retrieve it based on the uuid.
const item = await Item.fromDropData(data);

// Create the macro command using the uuid.
const command = `game.cryptsofavarice.rollItemMacro("${item.name}");`;
let macro = game.macros.find(m => (m.name === item.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: item.name,
type: "script",
img: item.img,
command: command,
flags: { "cryptsofavarice.itemMacro": true }
});
}
game.user.assignHotbarMacro(macro, slot);
return false;
}
async function createAvariceItemMacro(data, slot) {
// First, determine if this is a valid owned item.
if (data.type !== "Item") return;
if (!data.uuid.includes('Actor.') && !data.uuid.includes('Token.')) {
return ui.notifications.warn("You can only create macro buttons for owned Items");
}
// If it is, retrieve it based on the uuid.
const item = await Item.fromDropData(data);

// Create the macro command using the uuid.
const command = `game.cryptsofavarice.rollItemMacro("${item.name}");`;
let macro = game.macros.find(m => (m.name === item.name) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: item.name,
type: "script",
img: item.img,
command: command,
flags: { "cryptsofavarice.itemMacro": true }
});
}
game.user.assignHotbarMacro(macro, slot);
return false;
}
4 Replies
lee1121
lee1121•15mo ago
Update: I've tried to assign the macro to two slots higher than the item was dragged to. I can see the macro being assigned to that slot for about a frame, after which it's removed and the "Display [item name]" appears in the slot the item was dragged to. No clue why this happens :S
Zhell
Zhell•15mo ago
Using the hook for dropping onto the hotbar, if you return false and then call your own system function, that should ignore the core macro's generation Basically send off a call to your async function, don't await it, and then immediately return false
lee1121
lee1121•15mo ago
Yep, that was it. Thank you very much @Zhell!
Leo The League Lion
Leo The League Lion•15mo ago
@lee1121 gave vote LeaguePoints™ to @Zhell (#53 • 49)
Want results from more Discord servers?
Add your server