Created
May 21, 2022 15:54
-
-
Save johnstcn/a680d55bd91f382a5bef2a9c8cf77a11 to your computer and use it in GitHub Desktop.
Foundry VTT Macro for Starfinder RPG -- Mass Perception Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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}: </b><code>d20+${mod}</code> → [[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