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 for Colored Text and Box API

I would like to be able to enter a command in API that causes a text to appear in chat, but with dark green text and a light green text box (like an emote but green) I want to be able to trigger it with !note Is anyone able to put this together real quick?
1421706078
The Aaron
Pro
API Scripter
You could modify my emas script pretty quickly into that.
1421707093
The Aaron
Pro
API Scripter
Something like this might work... var ColorNote = ColorNote || (function() { 'use strict'; var version = 0.1, 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 ''; }, 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>' ); }, handleInput = function(msg) { var args, who; if (msg.type !== "api") { return; } args = msg.content.split(/\s+/); who=getObj('player',msg.playerid).get('_displayname').split(' ')[0]; switch(args[0]) { case '!note': if(1 === args.length) { showHelp(who); } else { sendChat('','/direct ' +"<div style=\"" +" background-color: #00cc00;" +" color: #003300;" +" display: block;" +" font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;" +" font-size: 14px;" +" font-style: italic;" +" font-weight: bold;" +" height: 26px;" +" 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 { RegisterEventHandlers: registerEventHandlers }; }()); on("ready",function(){ 'use strict'; ColorNote.RegisterEventHandlers(); });
1421708215
Gen Kitty
Forum Champion
Aaron, darling? How would you alter this script to use the player's color for the background? The real challenge is auto-changing the text to be black or white depending on how bright/dark the player's chosen color is :>
There might be a more elegant way to do this, but this is how it can work, at least as far as changing the background. var ColorNote = ColorNote || (function() { 'use strict'; var version = 0.1, 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 ''; }, 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>' ); }, handleInput = function(msg) { var args, who, color; if (msg.type !== "api") { return; } args = msg.content.split(/\s+/); who=getObj('player',msg.playerid).get('_displayname').split(' ')[0]; color=getObj('player',msg.playerid).get('color').split(' ')[0]; // Added this line switch(args[0]) { case '!note': if(1 === args.length) { showHelp(who); } else { sendChat('','/direct ' +"<div style=\"" +" background-color: "+color+";" // So this can call the color +" color: #000;" +" display: block;" +" font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;" +" font-size: 14px;" +" font-style: italic;" +" font-weight: bold;" +" height: 26px;" +" 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 { RegisterEventHandlers: registerEventHandlers }; }()); on("ready",function(){ 'use strict'; ColorNote.RegisterEventHandlers(); });
I added the following under the color=getObj... then changed +" color: #000;" to +" color: "+txcolor+";" It will change the color to white or black, depending on the brightness of someone's player color. function getBrightness(hex) { hex = hex.replace('#', ''); var c_r = hexDec(hex.substr(0, 2)); var c_g = hexDec(hex.substr(2, 2)); var c_b = hexDec(hex.substr(4, 2)); return ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000; } var txcolor = (getBrightness(color) < (255 / 2)) ? "#FFF" : "#000";
1421711773
Gen Kitty
Forum Champion
Cool!
1421712048
The Aaron
Pro
API Scripter
I'm in the process of migrating all my scripts to a github repo. When I finish, I'll make a better version of this script. :) Nice additions Sean!
1421712514

Edited 1421712575
Also, if you want to make your note longer than 26 pixels in length, delete or comment out: // +" height: 26px;" If you're OCD like me (who really likes everything centered in the chat area), you can pretty much center it by adding this into any part of the formatting area: +" position: relative;" +" right: 21px;" Thanks Aaron -- I'm not much for an actual script writer, I typically just hack something close to what I need, in order to make it work... :)
1421712917
Gen Kitty
Forum Champion
I only saw the player-color edit, you snuck in the color-changing text, so I didn't see it until you made your later comments. I shall be leaping upon this like a starving lioness upon a gazelle and dragging it back to my campaign. Giving the ability to have their emotes stand out is something I hope my players will appreciate. I think this version of the script (player color, auto-changing text-color) should be released as its own forum thread so it can be advertised to people running text-based games. Great job! ^_^
You people are wonderful.
1421735342
Gen Kitty
Forum Champion
Sorry to have to ask for this, but... Sean/Aaron, would you post the version of the script with the player-color-background AND text-colorchanging added? I can make very very tiny changes to scripts, but this isn't a tiny change (for me). :/
1421737086

Edited 1421737128
Here you go. I commented out the parts that I used to center the div layer, so it is reset back to the original distance from the right side. var ColorNote = ColorNote || (function() { 'use strict'; var version = 0.1, 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 ''; }, 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>' ); }, handleInput = function(msg) { var args, who, color; if (msg.type !== "api") { return; } args = msg.content.split(/\s+/); who=getObj('player',msg.playerid).get('_displayname').split(' ')[0]; color=getObj('player',msg.playerid).get('color').split(' ')[0]; function getBrightness(hex) { hex = hex.replace('#', ''); var c_r = hexDec(hex.substr(0, 2)); var c_g = hexDec(hex.substr(2, 2)); var c_b = hexDec(hex.substr(4, 2)); return ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000; } var txcolor = (getBrightness(color) < (255 / 2)) ? "#FFF" : "#000"; switch(args[0]) { case '!note': if(1 === args.length) { showHelp(who); } else { sendChat('','/direct ' +"<div style=\"" +" background-color: "+color+";" +" color: "+txcolor+";" +" display: block;" +" 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 { RegisterEventHandlers: registerEventHandlers }; }()); on("ready",function(){ 'use strict'; ColorNote.RegisterEventHandlers(); });
1421738461
Gen Kitty
Forum Champion
It works, it works, it works!! Woohoo! Thank you!!!
You're welcome, though the thanks for the hard work goes to The Aaron.
1421766284
The Aaron
Pro
API Scripter
A cake only tastes good. Someone has to frost it for it to look good. Thanks for the frosting Sean!
1421791640
Gen Kitty
Forum Champion
I'm delighted with both of you; so there! ^_^