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

Rollable Table Macros: Display both the !rtm result and the item itself

First of all, I want to thank Nathanael W. for this useful script.  I would like to know if there is a way of displaying both the !rtm result and the corresponding table item itself. I had previously found the issue that if there is an icon for a given item in a rollable table, then only the icon will be shown, not the title. The title will only be displayed when there is no icon. Then I started editing the icons so that they include the text I want to be displayed. Now, if it were possible to show both icon and text, AND roll the corresponding dice, it would be really great. I was wondering if there is an easy way to modify the script. Thanks in advance for any suggestions.
1501087599
The Aaron
Pro
API Scripter
I'm not overly familiar with Rollable Table Macros / !rtm and have confused it with my own RecursiveTable / !rt script.  I've been meaning to add image support to RecursiveTable, so possibly there is a solution there. Can you give a link to Rollable Table macros and a few screen shots and commands? I can take a quick look at the code...
Thank you very much,&nbsp; The Aaron .&nbsp; The script is quite simple. It takes a rollable table, converts the titles into strings, makes a list of those strings accounting for weight, and selects an item from the list. Then what comes to the chat is a string, so inline rolls are possible. The only command is the one doing that (there are two others to change the "from" of the chat input). So I think if the script somehow preserved the identity of the items of the rollable table when making the list, it could call the proper item later to be imputed along with the text. <a href="https://wiki.roll20.net/Script:Rollable_Table_Macr" rel="nofollow">https://wiki.roll20.net/Script:Rollable_Table_Macr</a>... <a href="https://github.com/Roll20/roll20-api-scripts/blob/" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/blob/</a>...
1501097613
The Aaron
Pro
API Scripter
Hmm. &nbsp;I don't actually see a way that it could display the table item's avatar image. &nbsp;Can you screenshot?
1501098226

Edited 1501098266
The table is opened so you can see the icons and titles. In the chat are results of repeatedly calling !rtm for that table. Notice how inline rolls on titles are actually rolled in the chat.
1501099320
The Aaron
Pro
API Scripter
So, to be clear, this script has never output the images, and that's what you'd like?
Yes, exactly. Do you think it would be possible? Also, is there an explanation of your&nbsp;RecursiveTable script? I can only get the code itself...
1501101543
The Aaron
Pro
API Scripter
RecursiveTable:&nbsp; <a href="https://app.roll20.net/forum/post/4954818/script-u" rel="nofollow">https://app.roll20.net/forum/post/4954818/script-u</a>... It is possible, and is a feature I want to add to RecursiveTable, so I'd most likely add it there and suggest using it, but if that doesn't work for you, I can probably hack it into !rtm.
As I see it, if the script takes the title of each item and makes a list of the strings, could it not take the items identity as well and make a list of two-item lists ([item title], [item id])? Then it can take the first item for !rtm purposes, and just call the second to the chat at the end. I still get lost with node. Do not know how to get item identities nor how to work with them.
Great! Thanks! I will take a look at Recursive Table (but only tomorrow). If it does not fulfill my needs, I will let you know so maybe you can try to modify !rtm.
1501102061
The Aaron
Pro
API Scripter
Actually, I just hacked it into RTM for now: // Rollable Table Macros // API Commands: // !rtm table-name(required) myself/from-name(optional) var RollableTableMacros = RollableTableMacros || ( function() { &nbsp; &nbsp; 'use strict'; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var commandListener = function() { &nbsp; &nbsp; &nbsp; &nbsp; // Listens for API command &nbsp; &nbsp; &nbsp; &nbsp; on( 'chat:message', function( msg ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( msg.type === 'api' && !msg.rolltemplate ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var params = msg.content.substring( 1 ).split( ' ' ), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; command = params[0].toLowerCase(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( command === 'rtm' ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var tableName = params[1] ? params[1].toLowerCase() : '', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msgFrom = getFrom( params, msg.playerid ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; findTable( msgFrom, tableName ); &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; getFrom = function( params, playerId ) { &nbsp; &nbsp; &nbsp; &nbsp; // Determine the sender of the messages. Defaults to table name (formatted to title case). &nbsp; &nbsp; &nbsp; &nbsp; var msgFrom = titleCase( params[1].replace( /-/g, ' ' ) ); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( params.length &gt; 2 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // If the optional third paramater was passed, assign sender to that string or original sender ('myself') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msgFrom = params.splice( 2 ).join( ' ' ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msgFrom = msgFrom.toLowerCase() == 'myself' ? ( 'player|' + playerId ) : msgFrom; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return msgFrom; &nbsp; &nbsp; }, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; findTable = function( msgFrom, tableName ) { &nbsp; &nbsp; &nbsp; &nbsp; // Finds the corresponding table, outputs error message to chat if not found &nbsp; &nbsp; &nbsp; &nbsp; var tables = findObjs({ type: 'rollabletable', name: tableName }, { caseInsensitive: true }); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( tables.length &lt; 1 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat( msgFrom, 'No such table exists.' ); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rollTable( tables[0].id, msgFrom ); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; rollTable = function( tableId, msgFrom ) { &nbsp; &nbsp; &nbsp; &nbsp; // Picks an item from the table &nbsp; &nbsp; &nbsp; &nbsp; var items = findObjs({ type: 'tableitem', rollabletableid: tableId }), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; weightedList = []; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( items.length &gt; 0 ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each( items, function( item ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Build a weighted list to draw from &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let weight = item.get( 'weight' ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _( weight ).times(function( ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; weightedList.push( item.id ); &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; var chosenItem = getObj( 'tableitem', weightedList[ randomInteger( weightedList.length ) - 1 ] ); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat( msgFrom, handleImage( handleMacro( chosenItem.get( 'name' ) ), chosenItem.get( 'avatar') ) ); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat( msgFrom, 'No items on this table.' ); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; handleImage = function ( message, image){ &nbsp; &nbsp; &nbsp; &nbsp; return /^https?:\/\//.test(image)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ? `&lt;div&gt;&lt;img style="max-height: 3em; max-width: 6em; float: left;" src="${image}"&gt;${message}&lt;div style="clear:both;"&gt;&lt;/div&gt;` &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : message &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; &nbsp; &nbsp; }, &nbsp; &nbsp; handleMacro = function( resultText ) { &nbsp; &nbsp; &nbsp; &nbsp; // Recursively handles any macro calls &nbsp; &nbsp; &nbsp; &nbsp; var resultLines = resultText.split( "\n" ); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each( resultLines, function( line, index, resultArray ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var lineArray = line.split( ' ' ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each( lineArray, function( word, index, parentArray ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( word[0] === '#' ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var macro = findObjs({ type: 'macro', name: word.substring( 1 ) }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parentArray[ index ] = macro.length &gt; 0 ? handleMacro( macro[0].get( 'action' ) ) : word; &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; resultArray[ index ] = lineArray.join( ' ' ); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return resultLines.join( "\n" ); &nbsp; &nbsp; }, &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; titleCase = function(str) { &nbsp; &nbsp; &nbsp; &nbsp; // returns the string in title case (each word capitalized) &nbsp; &nbsp; &nbsp; &nbsp; return str.toLowerCase().replace(/(^| )(\w)/g, function(x) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return x.toUpperCase(); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; return { &nbsp; &nbsp; &nbsp; &nbsp; CommandListener: commandListener &nbsp; &nbsp; }; &nbsp; &nbsp;&nbsp; }()); on( 'ready', function(){ &nbsp; &nbsp;'use strict'; &nbsp; &nbsp; &nbsp; &nbsp;RollableTableMacros.CommandListener(); });
1501102116
The Aaron
Pro
API Scripter
I'm still going to add this into RecursiveTable, but for now... =D
Wow, thanks! I will try it now :-)
Works perfectly. Also, I will compare both versions and understand a bit how all this is working. Thanks again!