Handyfon / roll-of-fate

Roll of fate for FoundryVTT, for GM's who don't want to be blamed.
GNU General Public License v3.0
5 stars 5 forks source link

Placeholder Macro for v10 #19

Open rmasoni opened 1 year ago

rmasoni commented 1 year ago

For anyone that misses this module in v10, here's a macro that has the same basic functionality of displaying a random selected token on chat.

With the token image:

const tokens = canvas.tokens.controlled;
const rand = Math.floor(Math.random() * tokens.length);
const name = tokens[rand].document.name;
const image = tokens[rand].document.texture.src;
ChatMessage.create({
 content: "<div style='font-size: 1.8em; margin: 1em 0; text-align: center;'><img src='" + image + "' style='max-width:6em;'><br>" + name + "</div>",
 whisper: [game.user.id]
});

And without the token image:

const tokens = canvas.tokens.controlled;
const rand = Math.floor(Math.random() * tokens.length);
const name = tokens[rand].document.name;
ChatMessage.create({
 content: "<div style='font-size: 1.8em; margin: 1em 0; text-align: center;'>" + name + "</div>",
 whisper: [game.user.id]
});

Credits to Zhell#9201 on Discord for the code. I just styled the message and added the option with the token image.

Fridan99 commented 1 year ago

Another variant, with the selected targets and public chat for all players:

const tokens = canvas.tokens.controlled;
const rand = Math.floor(Math.random() * tokens.length);
const selected = tokens[rand];
const content = `
<p style="color:#007fff; font-weight: bold; font-size: 1rem;">Wheel of destiny.  (Selected targets)</p> <i>${tokens.map(t => t.actor.name).join(", ")}.</i></p>
<p><strong>The randomy chosen one is:</strong> <h3>${selected.actor.name}</h3><p><img src="${selected.document.texture.src}" style="width: 50px; height: 50px; border: none;"></p>`;
await ChatMessage.create({content});

Credits to @Zhell and @Freeze on Discord Foundry VTT #macro-polo for the code and help.

I have only stylised it to make it look "prettier" in the chat.