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

[Help] API to Style Emotes for each Character

1455212633

Edited 1455212650
I am unclear on how we might be able to use API to interact with Emotes in the chat window, or whether it's even possible. I'd like to set up an API to style Emotes according to the character who is emoting to make it easier to identify who is speaking but also make it look cooler, taking better advantage of our Token Images to be expressive in the chat area. This means the API would override the normal Roll20 emote stying, which is always orange and always begins with the Character/Player's Name. What the API would do: 1. Each player character is assigned a color (e.g. one character is blue, another is red, then green, etc.), which is persistent; 2. Whenever the player uses the /emote command or maybe the API's !emote call, it is placed into a style Template where: 2a. API gets the Token Image & Token Name, (or Character Sheet's Profile Image & Name) along with the Assigned Color; 2b. API outputs the items within the Template (Token Image, Token Name & Assigned Color, along with the actual emoted text); 2c. Bonus: API checks the Token's turn order, and if the Token is now "up" the API adds a small icon onto the chat template (not shown in my example below).  Here's an example of what I have in mind: CHAT WINDOW Obviously, this depends on how the API is permitted to interact with commands like /emote or other methods for typing into the chat area. What do you think?
1455215832
Lithl
Pro
Sheet Author
API Scripter
You wouldn't be able to replace /emote, but you could create an API command like !emote to achieve the output you want. The API is capable of outputting pretty much arbitrary HTML to the chat with /direct (which is a chat command you can't  use without the API), so it would pretty much be a matter of deciding on the style(s) and associating them with players or characters.
Thanks Brian! I did not know that /desc is available to the API. Is this how things like Power Cards are carried off? If anyone could point me to a script that is already introducing html to the chat, I would be grateful for the help. That would be a good head start.
1455217952

Edited 1455218007
The Aaron
Pro
API Scripter
Here's a little script I cobbled together for a friend a while back: var ColorNote = ColorNote || (function() {     'use strict';       var version = '0.2.0',         lastUpdate = 1432818056,       ch = function (c) {     var entities = { '<' : 'lt', '>' : 'gt', "'" : '#39', '@' : '#64', '{' : '#123', '|' : '#124', '}' : '#125', '[' : '#91', ']' : '#93', '"' : 'quot', '-' : 'mdash', ' ' : 'nbsp' };   if(_.has(entities,c) ){ return ('&'+entities[c]+';'); } return ''; }, checkInstall = function(){         log('-=> ColorNote v'+version+' <=-  ['+(new Date(lastUpdate*1000))+']'); },   showHelp = function(who) {         sendChat('',             '/w '+who+' ' +'<div style="border: 1px solid black; background-color: white; padding: 3px 3px;">' +'<div style="font-weight: bold; border-bottom: 1px solid black;font-size: 130%;">' +'ColorNote v'+version +'</div>' +'<div style="padding-left:10px;margin-bottom:3px;">' +'<p>ColorNote provides the <b>!note</b> command, which looks like /em but but colored differently.</p>' +'</div>' +'<b>Commands</b>' +'<div style="padding-left:10px;">' +'<b><span style="font-family: serif;">!note '+ch('<')+'message'+ch('>')+'</span></b>' +'<div style="padding-left: 10px;padding-right:20px">' +'<p>Sends a message in the same manner as <i>/em</i> does, but with dark green text on a light green background.</p>' +'<ul>' +'<li style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;">' +'<b><span style="font-family: serif;">'+ch('<')+'message'+ch('>')+'</span></b> '+ch('-')+' The message to output as part of the note.' +'</li> ' +'</ul>' +'</div>' +'</div>' +'</div>'             );     }, getBrightness = function (hex) { var r,g,b; hex = hex.replace('#', ''); r = parseInt(hex.substr(0, 2),16); g = parseInt(hex.substr(2, 2),16); b = parseInt(hex.substr(4, 2),16); return ((r * 299) + (g * 587) + (b * 114)) / 1000; }, handleInput = function(msg) { var args, who, color, txcolor; if (msg.type !== "api") { return; } who=getObj('player',msg.playerid).get('_displayname').split(' ')[0]; args = msg.content.split(/\s+/); switch(args[0]) { case '!note': if(1 === args.length) { showHelp(who); } else { color=getObj('player',msg.playerid).get('color').split(' ')[0]; txcolor = (getBrightness(color) < (255 / 2)) ? "#FFF" : "#000"; sendChat('','/direct ' +"<div style=\"" +" background-color: "+color+";" +" color: "+txcolor+";" +" display: block;"                             +" margin-left: -40px;" +" font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;" +" font-size: 14px;" +" font-style: italic;" +" font-weight: bold;" // +" position: relative;"                         // +" right: 21px;" +" line-height: 17.0625px;" +" padding-top: 7px;" +" padding-bottom: 7px;" +" padding-left: 5px;" +" padding-right: 5px;" +" text-align: center;" +" word-wrap: break-word;" +" zoom: 1;" +"\">" +_.rest(args).join(' ') +"</div>" ); } break; } },   registerEventHandlers = function() { on('chat:message', handleInput); };   return { CheckInstall: checkInstall, RegisterEventHandlers: registerEventHandlers }; }());   on("ready",function(){ 'use strict';   ColorNote.CheckInstall(); ColorNote.RegisterEventHandlers(); }); It mimics the format of /em but with custom coloring.  In this case, I believe it colors based on the player color of the person executing the command.  I'd be happy to fully productize it and add in your suggestions. None of what you're asking for is beyond what the API is capable of doing. example execution command: !note This is a colored message!
Thanks Aaron! That is beyond what I'd hoped for. I would appreciate if you could do that for me. Using the Player Color to set the background would be great. I hadn't even considered that.
1455219288
The Aaron
Pro
API Scripter
I'll try to take a look at that over the weekend.  If you want to PM me your thoughts the notification will act as a reminder to work on it. =D
Will do! Thanks Aaron.
1455593047
The Aaron
Pro
API Scripter
Created this script! &nbsp; <a href="https://app.roll20.net/forum/permalink/2972233/" rel="nofollow">https://app.roll20.net/forum/permalink/2972233/</a> I'm afraid that Roll20 strips out gradients (sadly) so I wasn't able to give you quite the background you showed, but hopefully it works for you!
Thanks @The Aaron! I am very excited to see it in action and will try it out tonight. From what I can see of your description so far, it looks great.
1455695226

Edited 1455695241
The Aaron said: Created this script! &nbsp; <a href="https://app.roll20.net/forum/permalink/2972233/" rel="nofollow">https://app.roll20.net/forum/permalink/2972233/</a> I'm afraid that Roll20 strips out gradients (sadly) so I wasn't able to give you quite the background you showed, but hopefully it works for you! Yeah, it sucks... character sheets and roll templates can use gradients but the api cannot.&nbsp;