
This script works quite simply; select one or more NPCs and use the command "!npc-sheet-inline-rolls". After it has finished running, all rolls in the NPC's abilities will now be turned into inline rolls. This means that when showing the ability in chat, instead of either taking the average or manually making a roll, an inline roll will have already been made for you. Before: After: The API script: on('ready',()=>{
on('chat:message', (msg) => {
if(msg.type === 'api' && /^!npc-sheet-inline-rolls\b/i.test(msg.content)){
let player = getObj('player', msg.playerid);
if (!player || !playerIsGM(msg.playerid)) {
return;
}
var selectedCharacterSheetIds = (msg.selected || []).map(obj => getObj("graphic", obj._id))
.filter(x => !!x)
.map(token => token.get("represents"))
.filter(id => getObj("character", id || ""));
selectedCharacterSheetIds.forEach(function (characterSheetId) {
let attributes = findObjs({ type: 'attribute', characterid: characterSheetId })
.filter(attribute => /^repeating_([^_]*?)_([^_]*?)_description$/g.test(attribute.get('name')))
.filter(attribute => /\d+ \(\d+d\d+.*\)/g.test(attribute.get('current')))
attributes.forEach(attribute => attribute.set('current', attribute.get('current').replace(/\d+ \((\d+d\d+.*?)\)/g, "[[$1]]")))
let character = getObj("character", characterSheetId || "");
let characterName = character.get('name');
sendChat('NPC Sheet Inline Rolls', `/w "${player.get('displayname')}" **${characterName}** had ${attributes.length} abilities changed to use inline rolls.`);
});
}
});
});
I'm personally using this on my "setup NPC" macro to ensure whenever I use it, it'll ensure I have inline rolls everywhere needed - particularly when importing a monster or NPC from the compendium.