Skip to content

Instantly share code, notes, and snippets.

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 johnstcn/a680d55bd91f382a5bef2a9c8cf77a11 to your computer and use it in GitHub Desktop.
Save johnstcn/a680d55bd91f382a5bef2a9c8cf77a11 to your computer and use it in GitHub Desktop.
Foundry VTT Macro for Starfinder RPG -- Mass Perception Check
/*
* Foundry VTT Macro for Starfinder RPG -- Mass Perception Check
*/
// Gets list of selected tokens, or if no tokens are selected then the user's character.
function getTargetActors() {
const character = game.user.character;
const controlled = canvas.tokens.controlled;
let actors = [];
if (controlled.length === 0) return [character] || null;
if (controlled.length > 0) {
let actors = [];
for (let i = 0; i < controlled.length; i++) {
actors.push(controlled[i].actor);
}
return actors;
}
throw new Error('You must designate at least one token as the roll target');
}
function massPerception() {
let targetActors = getTargetActors().filter(a => a != null);
if (targetActors.length == 0) {
throw new Error('You must designate at least one token as the roll target');
}
let id = "per";
let flavor = `<h2>Everybody roll ${game.sfrpg.config.skills[id]}</h2>`;
let messageContent = ``;
for (let a of targetActors) {
let name = a.name;
let mod = a.data.data.skills[id].mod;
messageContent += `<h3><b>${name}:&nbsp;</b><code>d20+${mod}</code> &rarr; [[1d20+${mod}]]</h3>`;
}
let chatData = {
flavor: flavor,
user: game.user.id,
speaker: game.user,
content: messageContent,
// Uncomment the following line if you want the results whispered to the GM.
whisper: game.users.filter(u => u.isGM).map(u => u._id)
};
ChatMessage.create(chatData, {});
}
massPerception();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment