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 .
×
Advertisement Create a free account

[Request][Script] Create handout from macro?

Trying to figure this out but getting stuck.&nbsp; Here's my power cards macro: !power {{ --emote|Creating Character... --format|default --name|[[ [TXT] 1t[Occupation] ]] --leftsub|Birth Auger --rightsub|[[ [TXT] 1t[luckyRoll] ]] --Strength:|~R[[ 3d6 ]]~R --Agility:|~R[[ 3d6 ]]~R --Stamina:|~R[[ [$S] 3d6 ]]~R&nbsp; --Personality:|~R[[ 3d6 ]]~R&nbsp; --Intelligence:|~R[[ 3d6 ]]~R&nbsp; --Luck:|~R[[ 3d6 ]]~R&nbsp; -- ?? $S == 3 ?? Hit Points:|~R[[ 1d4 - 3]]~R -- ?? $S &gt;= 4 AND $S &lt;= 5 ?? Hit Points:|~R[[ 1d4 - 2]]~R -- ?? $S &gt;= 6 AND $S &lt;= 8 ?? Hit Points:|~R[[ 1d4 - 1]]~R -- ?? $S &gt;= 9 AND $S &lt;= 12 ?? Hit Points:|~R[[ 1d4 ]]~R -- ?? $S &gt;= 13 AND $S &lt;= 15 ?? Hit Points:|~R[[ 1d4 +1 ]]~R -- ?? $S &gt;= 16 AND $S &lt;= 17 ?? Hit Points:|~R[[ 1d4 +2 ]]~R -- ?? $S == 18 ?? Hit Points:|~R[[ 1d4 +3 ]]~R --Starting Copper:|~R[[ 5d12 ]]~R }} I'm trying to use the API to create a handout when the macro is ran or from the data in the macro itself. I can't figure a way of doing the variable interpolation + conditionals in a non power cards way.&nbsp; I can create a simple handout with this API script I found by searching the forum: on('ready',function(){ &nbsp; "use strict"; &nbsp; on('chat:message',function(msg){ &nbsp; &nbsp; var player,handout; &nbsp; &nbsp; if('api' === msg.type && msg.content.match(/^!handout/) ){ &nbsp; &nbsp; &nbsp; &nbsp; player=getObj('player',msg.playerid); &nbsp; &nbsp; &nbsp; &nbsp; if(player){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handout=createObj('handout',{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: 'Handout for '+player.get('displayname'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inplayerjournals: "all", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controlledby: (playerIsGM(msg.playerid) ? '' : msg.playerid) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('','/w "'+player.get('displayname')+'" Created a handout for you: &lt;a href="<a href="http://journal.roll20.net/handout/'+handout.id+" rel="nofollow">http://journal.roll20.net/handout/'+handout.id+</a>'" style="color:blue;text-decoration:underline;"&gt;Handout for '+player.get('displayname')+'&lt;/a&gt;'); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; }); }); Is there a way to getObj(#macroName) ? Or some way of kicking off the macro and then creating a handout based on the macro's output?
1479780856

Edited 1479786689
Silvyre
Forum Champion
Grognard said: --Stamina:|~R[[ [$S] 3d6 ]]~R&nbsp; -- ?? $S == 3 ?? Hit Points:|~R[[ 1d4 - 3]]~R -- ?? $S &gt;= 4 AND $S &lt;= 5 ?? Hit Points:|~R[[ 1d4 - 2]]~R -- ?? $S &gt;= 6 AND $S &lt;= 8 ?? Hit Points:|~R[[ 1d4 - 1]]~R -- ?? $S &gt;= 9 AND $S &lt;= 12 ?? Hit Points:|~R[[ 1d4 ]]~R -- ?? $S &gt;= 13 AND $S &lt;= 15 ?? Hit Points:|~R[[ 1d4 +1 ]]~R -- ?? $S &gt;= 16 AND $S &lt;= 17 ?? Hit Points:|~R[[ 1d4 +2 ]]~R -- ?? $S == 18 ?? Hit Points:|~R[[ 1d4 +3 ]]~R I can't figure a way of doing the variable interpolation + conditionals in a non power cards way. You could use a Rollable Table and then replace all of the above with --Hit Points:|~R[[ 1d4 + 1t[HP-mod] ]]~R, where 1t[HP-mod] is: Table Item Weight -3 1 -2 9 -1 46 0 104 1 46 2 9 3 1
1479785720
The Aaron
Forum Champion
API Scripter
That's not going to be terribly easy. &nbsp;What you would need to do is use the on('chat:message', ... ) event handler and catch when the type is not an api message and is the output you're interested in. &nbsp;Then you'll need to take the contents of the message and put those in the handout. &nbsp;There will be some translation problems (&lt;div&gt;s in the chat that are put in the handout will be improperly formatted, change to &lt;span style="display:block;"&gt;, etc). I suggest you start by making a handler that just logs the message to the API console and get a feeling for what messages occur. &nbsp; WARNING: Don't send a chat message whenever there is a chat message -- results in an infinite loop and problems. Good luck.
Thanks for the feedback. Much appreciated. To the macro-aboratory!