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

[Request] [Script] Output macro to handout creation? + Table roll result concatenation?

There's an example on creating a handout here:&nbsp; <a href="https://wiki.roll20.net/API:Cookbook#Creating_a_Ha" rel="nofollow">https://wiki.roll20.net/API:Cookbook#Creating_a_Ha</a>... But I can't seem to find a way to create a simple handout based on a macro I've created. The macro looks like:&nbsp; !power {{ --format|default --name|World Profile --Name|~C[[ t[first-name] ]] [[ t[second-name] ]]~C --Starport|~R[[ t[starport] ]]~R&nbsp; --Size|~R[[ 1t[size] ]]~R --Atmosphere|~R[[ 1t[atmosphere] ]]~R --Hydrographics|~R[[ 1t[hydrographics] ]]~R --Population|~R[[ 1t[population] ]]~R --Government|~R[[ 1t[government] ]]~R --Law|~R[[ 1t[law] ]]~R --Tech|~R[[ 1t[tech] ]]~R }} The goals is to add a line or script somehow that would split the output to the chat channel and create a handout with the results and name the handout per the --Name parameter on line 4.&nbsp; Also, is it possible to concatenate the results from the two tables? Right now it shows at two separate results next to each other.&nbsp;
1478447006
The Aaron
Pro
API Scripter
So, you're trying to create a handout that has for the body the output of a Powercards command? &nbsp;And takes it's name from that Powercard's --Name argument?&nbsp;
The Aaron said: So, you're trying to create a handout that has for the body the output of a Powercards command? &nbsp;And takes it's name from that Powercard's --Name argument?&nbsp; Thanks for replying my good sir.&nbsp; Things I'd like to do: At the end of the powercards script have something that outputs the data from the script to a handout automatically: Handout Name: --Name|~C[[ t[first-name] ]] [[ t[second-name] ]]~C (or a parameter specified) The body: Name = [{Name:"value"}];\n; World Profile;\n; [{Starport:"value", Size:"value", Atmosphere:"value", Hydrographics:"value", Population:"value", Government:"value", Law:"value, Tech:"value}] &lt;--in a table if possible. Sorry, not a java guy :) Concatenate the first-name with second-name from the name table rolls.&nbsp; I've been trying to find a way to group matching dice rolls and count them as successes. Example: Roll 10d6sd and match pairs; count each pair as a success So a result of 6655544321 would output as: 3 Successes! My current World Gen Script: !power {{ --format|worldgen --name|World Profile --Name|~C[[ t[first-name] ]] [[ t[second-name] ]]~C --Starport|~R[[ t[starport] ]]~R&nbsp; --Size|~R[[ 1t[size] ]]~R --Atmosphere|~R[[ 1t[atmosphere] ]]~R --Hydrographics|~R[[ 1t[hydrographics] ]]~R --Population|~R[[ 1t[population] ]]~R --Government|~R[[ 1t[government] ]]~R --Law|~R[[ 1t[law] ]]~R --Tech|~R[[ 1t[tech] ]]~R }} The output in chat: An example of the Handout: Tags : worlds Access : In all players journals Directory Structure:
1478540644
The Aaron
Pro
API Scripter
So, it would probably be easier to write something that worked this the other direction. &nbsp;The proposed script would start by generating the world name and each of the attributes of the world, would create a handout with the right name and contents, then would invoke power cards with the right data.
The Aaron said: So, it would probably be easier to write something that worked this the other direction. &nbsp;The proposed script would start by generating the world name and each of the attributes of the world, would create a handout with the right name and contents, then would invoke power cards with the right data. Me:
1478546217
The Aaron
Pro
API Scripter
=D &nbsp;Honestly, if you just want Powercards for the output, it would probably be easier all around to just make your own output rather than rely on Powercards.
1478562657

Edited 1478609641
The Aaron
Pro
API Scripter
Here's a first second pass version: // on('ready',function(){ &nbsp; &nbsp; 'use strict'; &nbsp; &nbsp; var nameRoll='[[1t[first-name] ]]-[[1t[second-name] ]]', &nbsp; &nbsp; &nbsp; &nbsp; attrs={ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Starport: &nbsp; &nbsp; &nbsp;'[[1t[starport] &nbsp; &nbsp; &nbsp;]]', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Size: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'[[1t[size] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Atmosphere: &nbsp; &nbsp;'[[1t[atmosphere] &nbsp; &nbsp;]]', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hydrographics: '[[1t[hydrographics] ]]', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Population: &nbsp; &nbsp;'[[1t[population] &nbsp; &nbsp;]]', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Government: &nbsp; &nbsp;'[[1t[government] &nbsp; &nbsp;]]', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Law: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '[[1t[law] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]]', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tech: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'[[1t[tech] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;]]' }, &nbsp; &nbsp; &nbsp; &nbsp; rowColor=['#ffffff','#eeeeff'], &nbsp; &nbsp; &nbsp; &nbsp; clear='&lt;span style="display:block;clear:both; margin-bottom: 0 !important;"&gt;&lt;/span&gt;', &nbsp; &nbsp; &nbsp; &nbsp; dataStyle="display:block;min-width: 2em; border:1px solid #A79D65; border-radius:1em; padding: .1em .3em; text-align: center; background-color: #FEF0A2 !important; float: right; margin-bottom: 0 !important;", &nbsp; &nbsp; &nbsp; &nbsp; rowStyle=(color)=&gt;`display:block;vertical-align: middle;border-top: 1px solid #A79D65; font-family: sans-serif; padding: .1em; font-weight: bold; background-color: ${color} !important; margin-bottom: 0 !important;`, &nbsp; &nbsp; &nbsp; &nbsp; rowMaker=(label,data,color)=&gt;`&lt;span style="${rowStyle(color)}"&gt;${label}&lt;span style="${dataStyle}"&gt;${data}&lt;/span&gt;${clear}&lt;/span&gt;`, &nbsp; &nbsp; &nbsp; &nbsp; titleMaker=(title)=&gt;`&lt;span style="display:block;font-weight: bold; font-size: .6em; font-family: sans-serif;margin-bottom: -.3em !important;"&gt;World&lt;/span&gt;&lt;span style="font-weight: bold; font-family: monospace; font-size: 2em; text-align:center;"&gt;${title}&lt;/span&gt;`, &nbsp; &nbsp; processInlinerolls = function(msg) { &nbsp; &nbsp; &nbsp; &nbsp; if(_.has(msg,'inlinerolls')){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return _.chain(msg.inlinerolls) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .reduce(function(m,v,k){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var ti=_.reduce(v.results.rolls,function(m2,v2){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(_.has(v2,'table')){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m2.push(_.reduce(v2.results,function(m3,v3){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m3.push(v3.tableItem.name); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m3; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },[]).join(', ')); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m2; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },[]).join(', '); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },{}) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .reduce(function(m,v,k){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m.replace(k,v); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },msg.content) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .value(); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return msg.content; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }; &nbsp; &nbsp; on('chat:message',function(msg){ &nbsp; &nbsp; &nbsp; &nbsp; if('api' === msg.type && msg.content.match(/^!worldgen/) && playerIsGM(msg.playerid) ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let roll = _.union([`Name: ${nameRoll}`],_.map(attrs,(v,k)=&gt;`${k}: ${v}`)).join('####'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('WorldGen',roll,function(msgs){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let vals=_.map(processInlinerolls(msgs[0]).split(/####/),(o)=&gt;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let s=o.match(/^(.*?): (.*)$/); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; label: s[1], &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: s[2] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name=_.first(vals).value, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handout=createObj('handout',{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vals=_.rest(vals); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text=`&lt;span style="display:block;border:1px solid #A79D65;background-color:#eeeeee;"&gt;${titleMaker(name)}${ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.map(vals,(data,key)=&gt;rowMaker(data.label,data.value,rowColor[key%2])).join('') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }`; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handout.set( {notes: text}); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('WorldGen',text); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }); }); Needs some formatting, but check and see if this does basically what you're after. Added some formatting. &nbsp;See what you think! !worldgen
1478605879
The Aaron
Pro
API Scripter
Are you basically trying to go for something like this: &nbsp;<a href="http://donjon.bin.sh/scifi/tsg/" rel="nofollow">http://donjon.bin.sh/scifi/tsg/</a>
The Aaron said: Are you basically trying to go for something like this: &nbsp; <a href="http://donjon.bin.sh/scifi/tsg/" rel="nofollow">http://donjon.bin.sh/scifi/tsg/</a> OMG this is awesome! Thank you so much for working on this. Just tried it in my campaign and it works like a charm. Yeah, I'm trying to do what donjon does. I haven't filled out my worldgen tables completely and just have the codes. This is a great script to build upon. Should I submit a different post for the dice pair matching = success thing?
1478621393
The Aaron
Pro
API Scripter
I don't know what you mean by "dice pair matching = success," can you go into more detail? &nbsp; Honestly, it's your post, so you can pretty much put whatever you like in it. =D
The Aaron said: I don't know what you mean by "dice pair matching = success," can you go into more detail? &nbsp; Honestly, it's your post, so you can pretty much put whatever you like in it. =D Cool. So, in Traveller if you have an automatic weapon with an Auto rating of 2 or higher you get to roll that many dice and each pair counts as an attack that you can allocate however you want. If my Auto rating is 6; I roll 6d6; count matches as successes; each success == an attack.&nbsp; Example : I roll 6d6sd. The result is 665541. This amounts to 2 attacks (66, 55). The 4 and 1 are not counted.&nbsp; This is my work around for now since I can't seem to find any other way of doing it: !power {{ --tokenid|@{selected|token_id}&nbsp; --emote|@{selected|character_name} checks number of attacks from auto fire --format|autopair --name|Auto Pairs --Roll:|~C[[ [NH] [XPND] ?{Auto Rating:| 2,2d6sd | 3,3d6sd | 4,4d6sd | 5,5d6sd | 6,6d6sd} ]]~C~~~ --|Each pair is an attack. ^^^^Auto-fire attacks can be allocated to as many different targets as you have attacks provided all the targets are within six metres of each other. ^^^^Auto-fire attacks cannot benefit from a skill any higher than level 1. Weapon skills of 2 or higher only count as 1 when making auto-fire attacks. ^^^^Auto-fire uses a number of rounds equal to 3 X the Auto rating. }} Chat output: Goal : In the above case, instead of "(5+4+4+2+2+1)=18", I'd like to just display "2 Attacks available. "
1478626750
The Aaron
Pro
API Scripter
Ok, that would definitely be a custom script. &nbsp;I've actually written several like that in the past (Cthulutech Dice, Zombie Dice, Bash Dice, Mutant Year Zero Dice, etc). Go ahead and post a fresh thread about it with a full breakdown on the rolls traveller needs (might as well address all of them) and I'll see what I can do. =D
The Aaron said: Ok, that would definitely be a custom script. &nbsp;I've actually written several like that in the past (Cthulutech Dice, Zombie Dice, Bash Dice, Mutant Year Zero Dice, etc). Go ahead and post a fresh thread about it with a full breakdown on the rolls traveller needs (might as well address all of them) and I'll see what I can do. =D Awesome. Thanks for the help. I'll post in just a few.&nbsp;