Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

NPC Sheet Inline Rolls

1662322863

Edited 1662329122
Liam
Pro
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.
1662324263
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Oh! This is a beautiful thing Liam! Cause I can't resist some feature creep, how about a "Campaign wide" command, and/or a "watch for compendium drop" mode?
1662325908

Edited 1662326896
Liam
Pro
Campaign-wide should be simple enough if you want to do it one time, by replacing "selectedCharacterSheetIds" with: var selectedCharacterSheetIds = findObjs({ type: 'character' }); As for "on compendium drop", I'm not sure - is there a specific event for that to listen to?
1662328394
David M.
Pro
API Scripter
Very handy, thanks!
1662330796
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
What a nifty idea!
1662335084

Edited 1662335137
vÍnce
Pro
Sheet Author
Very cool.  I recall using a browser extension ( AoN Attacker ) that did something similar for pathfinder2e stat blocks when browsing Archives of Nethys.
1662377250
David M.
Pro
API Scripter
Liam said: As for "on compendium drop", I'm not sure - is there a specific event for that to listen to? You can trigger when a token is dropped to the map with something like this: on("add:graphic", function(obj) {   //do the things } From the wiki : If added within the on('ready'...), it will only trigger for new graphics. If outside the on('ready'...), it will process existing tokens as well as new ones, though pretty sure that will fire every time the sandbox is restarted so probably not recommended in this case. 
1662561202
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Could an option be added to retain the original roll expression, in case a DM wishes to override the result or use the info for other purposes? Basically so it would read like the original: "5 (2d4) acid damage" but the "5" still be the inline roll result? ==> [[2d4]] (2d4)
I figured it'd be an option to keep that, but if it's been posted to chat you can just hover over the inline roll to see the roll expression in a tooltip which serves the same purpose.
Nice script! Another to add to my DM toolbox.