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

Trying to Add a Template to and Existing API

I'm using Brian's RealRollableTables API (with a tiny tweak or two) to roll these critical hit tables I have where you roll with modifiers. I also have critical fumble tables where you roll without modifiers, and I have those set up to output through macros and with Aaron's RecursiveTables script to the NPCActions template. I'd love to output the critical hit tables to the same template, but I THINK the only way to do that is to alter the script itself to output to the template. I don't know APIs pretty much at all, and haven't had much success. Here was my attempt. Can you tell me if this is possible? Original, with a slight tweak to alter the scripts name and because the script doesn't handle my roll modifiers in the text output well: sendChat('', '/r ' + roll, function(ops) { var rollresult = JSON.parse(ops[0].content), actualRoll = roll, displayTotal = rollresult.total, dieSize, tableItem, tableItemAvatar, tableItemIndex, tableItemName; if (rollresult.resultType === 'M') { // Math-only roll dieSize = Math.min(parseInt(items.length - rollresult.total), 0); actualRoll = '1d' + dieSize + ' + ' + roll; displayTotal = (dieSize > 0 ? randomInteger(dieSize) : 0) + rollresult.total; tableItemIndex = Math.max(Math.min(displayTotal - 1, items.length - 1), 0); } else { tableItemIndex = Math.max(Math.min(rollresult.total - 1, items.length - 1), 0); } tableItem = items[tableItemIndex]; tableItemAvatar = /*tableItem.get('avatar') ? '\n<img src="' + tableItem.get('avatar') + '" />' :*/ ''; //tableItemAvatar = tableItemAvatar.replace(/med|max/, 'thumb'); tableItemName = tableItem.get('name') ? '\n<span style="padding:3px;"><b>' + tableItem.get('name') + '</b></span>' : ''; sendChat(getPlayerCharacterFrom(msg.who), 'Rolling ' + ' (' + displayTotal + ') on table "' + args[0] + '":' + tableItemAvatar + tableItemName); }); }, My clumbsy attempt. sendChat('', '/r ' + roll, function(ops) { var rollresult = JSON.parse(ops[0].content), actualRoll = roll, displayTotal = rollresult.total, dieSize, tableItem, tableItemAvatar, tableItemIndex, tableItemName; if (rollresult.resultType === 'M') { // Math-only roll dieSize = Math.min(parseInt(items.length - rollresult.total), 0); actualRoll = '1d' + dieSize + ' + ' + roll; displayTotal = (dieSize > 0 ? randomInteger(dieSize) : 0) + rollresult.total; tableItemIndex = Math.max(Math.min(displayTotal - 1, items.length - 1), 0); } else { tableItemIndex = Math.max(Math.min(rollresult.total - 1, items.length - 1), 0); } tableItem = items[tableItemIndex]; tableItemAvatar = /*tableItem.get('avatar') ? '\n<img src="' + tableItem.get('avatar') + '" />' :*/ ''; //tableItemAvatar = tableItemAvatar.replace(/med|max/, 'thumb'); tableItemName = tableItem.get('name') ? '\n<span style="padding:3px;"><b>' + tableItem.get('name') + '</b></span>' : ''; sendChat(getPlayerCharacterFrom(msg.who), "&{template:npcaction} {{name=Critical Hit Result}} {{description= [[tableItemAvatar + tableItemName }}"); }); },
1535046497
The Aaron
Pro
API Scripter
That looks just fine, except you have an extra [[ after description= , which might be causing problems with the output, if you are having problems with the output.
1535046601
The Aaron
Pro
API Scripter
Actually, try this for that line: sendChat(getPlayerCharacterFrom(msg.who), `&{template:npcaction} {{name=Critical Hit Result}} {{description= [x](${tableItemAvatar}#.png) ${tableItemName} }}`);
Hmm. Not getting an output with that.
1535047791
The Aaron
Pro
API Scripter
Hmm.. were you before?
Whoops. Had two scripts conflicting. No, it's mostly working, but that png is coming through broken. The critical shows up fine, though. Do you know that that PNG is?
This version is working nicely. Thanks for your help! sendChat(getPlayerCharacterFrom(msg.who), `&{template:npcaction} {{rname=Critical Hit Result}} {{description=*Rolling ${displayTotal} on table ${args[0]}:* ${tableItemName} }}`);
1535052094
The Aaron
Pro
API Scripter
Ah.  That PNG was the Table Item Avatar.  Looks like that was in the original message, but commented out.  I had wrapped it in the image syntax to make it show up not realizing it was short circuited to the empty string.  If you want the image to show up, I can help you get that working.