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] 5e Script - Inspiration tracking

1506480111

Edited 1506606172
Giger
API Scripter
Howdy all, i'm hoping someone can help me here. I'm tired of players not realizing or forgetting they have inspiration, and having to check to see who, if anyone, has it. I looked around and couldn't find any APIs that would do anything like this, so i thought i'd give it a try  - turns out i'm not terribly good :P Determining if the right attribute is changed, to the right value was easy enough. Now i need to do more fancy things like, get the character's name, and figure out how to update a token with a status effect. I have a good idea how to approach all of that, but I for the life of me, can't seem to reach out to other objects, despite being able to pass around the ID, i pulled from the attribute obj. Help with pulling this off would be fantastic, although if anyone knows a script that would just do this, that also be great on("change:attribute", function(obj, prev) {     //Only do stuff is the inspiration attribute was changed.     var isupdated = obj.get("name");     var attr = obj.get("current");          if (isupdated =="inspiration" && attr=="on"){                 var id = obj.get("_characterid");                  var char = findObjs({_type: "character",_characterid: id})[0];         var cname = char["name"];          sendChat ("", cname+"");              }           });
1506483288
The Aaron
Pro
API Scripter
In general, I find it better not to preface with _ on property names (with the exception of registering for events on them, which requires the _). It looks like you're going along well until you get to the cname line.  (Note: "char" is technically a reserved name in Javascript, so using "character" instead would be better.).  The issue is likely this line: var cname = char["name"]; You can't index Roll20 Character Objects with array notation, you need to use the .get() method: var cname = char.get("name"); That should fix it.
I use TheAaron's TokenMod to help players remember Inspiration (and other buffs like Rage), adding one of the token status markers to display it on the tabletop.  This is what mine looks like: !token-mod {{   --set statusmarkers|!chained-heart   --ids     @{target|Bardic Inspiration|token_id} } When the bard casts the buff, he fires the macro and selects the character token he wants to buff. The API adds the status marker. I have another macro to roll the bardic inspiration die, and it removes the status marker. Note: you'll need to toggle on the "players can use on tokens they don't control" feature in TokenMod.
This isn't directly helpful to the API script in question, but on the subject of "how I handle inspiration in my game," I use this card I made in Photoshop as a 1-card, infinite-size deck in Roll20 and just drag cards onto players' portraits when they receive inspiration. That the card appears above their portrait is a nice visual cue to everyone.
1506518834
Giger
API Scripter
The Aaron said: In general, I find it better not to preface with _ on property names (with the exception of registering for events on them, which requires the _). It looks like you're going along well until you get to the cname line.  (Note: "char" is technically a reserved name in Javascript, so using "character" instead would be better.).  The issue is likely this line: var cname = char["name"]; You can't index Roll20 Character Objects with array notation, you need to use the .get() method: var cname = char.get("name"); That should fix it. Thanks Aaron!  and everyone else for their suggestions. I tried the token mod, but my macro button bar is pretty full already so i'm starting to have to find new ways to do things. If i can ever get it working ill be sure to share it.
1506524499

Edited 1506524997
Giger
API Scripter
So i got everything "working" until i need to find the characters token, so i can change the status icon. I'm pressuming i need to identify the "default token" of the character sheet, and then use that ID moving forward to update it with a new icon.      var Character = getObj("character", id);         var Token = Character.get["_defaulttoken"];         log (Character); The Character var is working, I think need to parse the string or something LOG {"name":"As Himself","bio":1505620692225,"gmnotes":"","_defaulttoken":1503974671085,"archived":false,"inplayerjournals":"all","controlledby":"-KtWQIVGMmFxlA0o7me0","_id":"-KsOpnYOYha1N3wLILze","_type":"character","avatar":"redacted"} Using v ar Token = Character.get("_defaulttoken"); generates the following error undefined
1506525073
The Aaron
Pro
API Scripter
Actually, it's easier to just find all the tokens that represent that character: const getCharacterTokens = (cid) => findObjs({type:'graphic'}).filter((t)=>t.get('represents')===cid); /* ... */ getCharacterTokens(character.id).forEach((t)=>t.set('status_skull',true));
1506526463
Giger
API Scripter
You're my hero, and brilliant! All i can offer is my Patronage in return!
1506527044
The Aaron
Pro
API Scripter
HAHAHA, No need or worry. =D  I'm happy to help.
1506535448

Edited 1506536190
Giger
API Scripter
Here's the proposed final solution.&nbsp; Credits to TheAaron for all the help, and Sky (as i stole some of his pretty css wizardry.[pending approval]) What am I missing? What are some considerations for code complete. AnnounceInspiration = function (id) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //character_ID is passed from on change &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //sendChat("",id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( _.isEmpty(id)) return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var character = getObj("character", id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log (character); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const getCharacterTokens = (cid) =&gt; findObjs({type:'graphic'}).filter((t)=&gt;t.get('represents')===cid); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; /* ... */ &nbsp; &nbsp; &nbsp; &nbsp; getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',true)); &nbsp; &nbsp; &nbsp; &nbsp; var AlertTokenName = character.get("name"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var AlertColor = getObj("player", character.get("controlledby").split(",")[0]).get("color"); &nbsp; &nbsp; &nbsp; &nbsp; var AlertTextColor = (getBrightness(AlertColor) &lt; (255 / 2)) ? "#FFF" : "#000"; &nbsp; &nbsp; &nbsp; &nbsp; var AlertShadowColor = (AlertTextColor == "#000") ? "#FFF" : "#000"; &nbsp; &nbsp; &nbsp; &nbsp; var AlertOuterStyle = "max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;"; &nbsp; &nbsp; &nbsp; &nbsp; var AlertInnerStyle = "max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: " + AlertTextColor + "; background-color: " + AlertColor + "; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 " + AlertShadowColor + ", 1px -1px 0 " + AlertShadowColor + ", -1px 1px 0 " + AlertShadowColor + ", 1px 1px 0 " + AlertShadowColor + ";"; &nbsp; &nbsp; &nbsp; &nbsp; var AlertImageStyle = "height: 40px; width: 40px; float: right; margin: -32px 5px 0px 0px;"; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "/desc &lt;div style='" + AlertOuterStyle + "'&gt;&lt;div style='" + AlertInnerStyle + "'&gt;" + AlertTokenName + " is Inspired! &lt;/div&gt;&lt;img src='<a href="https://s3.amazonaws.com/files.d20.io/images/39783029/-w45_4ICV9QnFzijBimwKA/max.png" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/39783029/-w45_4ICV9QnFzijBimwKA/max.png</a>' style='" + AlertImageStyle + "'&gt;&lt;/img&gt;&lt;/div&gt;"); &nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;DropInspiration = function (id) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //character_ID is passed from on change &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //sendChat("",id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( _.isEmpty(id)) return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var character = getObj("character", id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; log ('dropped'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const getCharacterTokens = (cid) =&gt; findObjs({type:'graphic'}).filter((t)=&gt;t.get('represents')===cid); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; /* ... */ &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',false)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; on("ready", function(){log('-=&gt; HazInspiration &lt;=- V0.0.1');&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;sendChat("", "/desc &lt;div style='max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;'&gt;&lt;div style='max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: fff; background-color: 20b2aa; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 000, 1px -1px 0 000, -1px 1px 0 000, 1px 1px 0 000'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); &nbsp;&nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; on("chat:message", function(msg) { &nbsp; &nbsp; &nbsp; if(msg.type == "api" && msg.content.indexOf("!inspiration") !== -1) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "/desc &lt;div style='max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;'&gt;&lt;div style='max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: fff; background-color: 20b2aa; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 000, 1px -1px 0 000, -1px 1px 0 000, 1px 1px 0 000'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); &nbsp;&nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // Has a character sheet been updated? &nbsp; &nbsp; &nbsp; on("change:attribute", function(obj, prev) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var isupdated = obj.get("name"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isupdated =="inspiration"){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Only work if 'inspiration' was changed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var val = obj.get("current"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var id = obj.get("_characterid");&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Inspired-&nbsp; Now, decide, is it turned on or off? &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isupdated =="inspiration" && val == "on"){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//&nbsp; It's On' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var charname = getAttrByName(id, "character_name"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Get the Character Name for Annoucing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(charname != ""){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //A Name was found, let's move on. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AnnounceInspiration(id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {sendChat("", "Failed getting Character Name") ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Couldn't find a name &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (isupdated =="inspiration" && val != "on"){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //It's Off &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DropInspiration(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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Silent if not inspired &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; &nbsp; &nbsp;&nbsp;
1506537670
The Aaron
Pro
API Scripter
Sky won't mind if you use his functions and he's unlikely to respond to messages, but I'll ask him for you. You'll need to pull over his getBrightness function. &nbsp;It's a good idea to wrap your things either explicitly in an object or implicitly by doing them all in an on('ready') function. &nbsp;That prevents polluting the global scope and prevents anything from slipping into your code unintentionally. &nbsp;It's also a good idea (for historic reasons) to start functions with a lowercase letter, though that's probably going away. &nbsp;Also, no need to redeclare getCharacterTokens(), you can move it out to a first class citizen of your script. =D Anyway, something like this: on('ready',()=&gt;{ const getCharacterTokens = (cid) =&gt; findObjs({type:'graphic'}).filter((t)=&gt;t.get('represents')===cid); /* copy this... from wherever... const getBrightness = ()=&gt;0; const announceInspiration = function (id) { //character_ID is passed from on change //sendChat("",id); if ( _.isEmpty(id)) return; var character = getObj("character", id); getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',true)); var AlertTokenName = character.get("name"); var AlertColor = getObj("player", character.get("controlledby").split(",")[0]).get("color"); var AlertTextColor = (getBrightness(AlertColor) &lt; (255 / 2)) ? "#FFF" : "#000"; var AlertShadowColor = (AlertTextColor == "#000") ? "#FFF" : "#000"; var AlertOuterStyle = "max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;"; var AlertInnerStyle = "max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: " + AlertTextColor + "; background-color: " + AlertColor + "; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 " + AlertShadowColor + ", 1px -1px 0 " + AlertShadowColor + ", -1px 1px 0 " + AlertShadowColor + ", 1px 1px 0 " + AlertShadowColor + ";"; var AlertImageStyle = "height: 40px; width: 40px; float: right; margin: -32px 5px 0px 0px;"; sendChat("", "/desc &lt;div style='" + AlertOuterStyle + "'&gt;&lt;div style='" + AlertInnerStyle + "'&gt;" + AlertTokenName + " is Inspired! &lt;/div&gt;&lt;img src='<a href="https://s3.amazonaws.com/files.d20.io/images/39783029/-w45_4ICV9QnFzijBimwKA/max.png" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/39783029/-w45_4ICV9QnFzijBimwKA/max.png</a>' style='" + AlertImageStyle + "'&gt;&lt;/img&gt;&lt;/div&gt;"); }; const dropInspiration = function (id) { //character_ID is passed from on change if ( _.isEmpty(id)) return; var character = getObj("character", id); getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',false)); }; on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!inspiration") !== -1) {&nbsp; sendChat("", "/desc &lt;div style='max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;'&gt;&lt;div style='max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: fff; background-color: 20b2aa; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 000, 1px -1px 0 000, -1px 1px 0 000, 1px 1px 0 000'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); } }); // Has a character sheet been updated? on("change:attribute", function(obj) { var isupdated = obj.get("name"); if (isupdated =="inspiration"){ // Only work if 'inspiration' was changed var val = obj.get("current"); var id = obj.get("_characterid"); &nbsp; //Inspired- &nbsp;Now, decide, is it turned on or off? if (isupdated =="inspiration" && val == "on"){ // &nbsp;It's On' var charname = getAttrByName(id, "character_name"); //Get the Character Name for annoucing if(charname != ""){ //A Name was found, let's move on. announceInspiration(id); } else {sendChat("", "Failed getting Character Name") ; //Couldn't find a name } } else if (isupdated =="inspiration" && val != "on"){ //It's Off dropInspiration(id); }&nbsp; // Silent if not inspired } }); log('-=&gt; HazInspiration &lt;=- V0.0.1'); &nbsp; sendChat("", "/desc &lt;div style='max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;'&gt;&lt;div style='max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: fff; background-color: 20b2aa; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 000, 1px -1px 0 000, -1px 1px 0 000, 1px 1px 0 000'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); });
1506558696

Edited 1506559272
Giger
API Scripter
Thanks again TheAaron, i was able to connect with him earlier this evening and, as you suspected, he was cool with it. I got the missing function added and everything seems to be working well.&nbsp; Can't really figure out github, so i'll just dump this here for anyone else that wants to use it Only little bug i can find is, if inspiration has never been toggled, the attribute won't yet exist and so the script won't fire the first time.&nbsp; Works fine afterwards though. //HazInspiration v. 0.2 created&nbsp; on the 9-27-2017 by Giger, my first script with massive help from TheAaron and code shamelessly stolen from Sky's Initiative System (it's pretty) /* &nbsp; &nbsp; This script reports to the chat window, and updates the players token with an icon, to indicate whether the player has Inspiration or not. &nbsp; &nbsp; Designed for the 5th Edition ( OGL by Roll20 ) Character Sheet. &nbsp; &nbsp;&nbsp; */ &nbsp; &nbsp; &nbsp; on('ready',()=&gt;{ &nbsp; &nbsp; &nbsp; const getCharacterTokens = (cid) =&gt; findObjs({type:'graphic'}).filter((t)=&gt;t.get('represents')===cid); &nbsp; &nbsp; &nbsp; //Brightness&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var getBrightness = getBrightness || {}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var getHex2Dec = getHex2Dec || {}; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function getBrightness(hex) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hex = hex.replace('#', ''); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var c_r = getHex2Dec(hex.substr(0, 2)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var c_g = getHex2Dec(hex.substr(2, 2)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var c_b = getHex2Dec(hex.substr(4, 2)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function getHex2Dec(hex_string) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, ''); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return parseInt(hex_string, 16); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; const announceInspiration = function (id) { &nbsp; &nbsp; &nbsp; //Handles Chat Annoucement &nbsp; &nbsp; &nbsp; if ( _.isEmpty(id)) return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var character = getObj("character", id); &nbsp; &nbsp; &nbsp; var AlertTokenName = character.get("name"); &nbsp; &nbsp; &nbsp; var AlertColor = getObj("player", character.get("controlledby").split(",")[0]).get("color"); &nbsp; &nbsp; &nbsp; var AlertTextColor = (getBrightness(AlertColor) &lt; (255 / 2)) ? "#FFF" : "#000"; &nbsp; &nbsp; &nbsp; var AlertShadowColor = (AlertTextColor == "#000") ? "#FFF" : "#000"; &nbsp; &nbsp; &nbsp; var AlertOuterStyle = "max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;"; &nbsp; &nbsp; &nbsp; var AlertInnerStyle = "max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: " + AlertTextColor + "; background-color: " + AlertColor + "; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 " + AlertShadowColor + ", 1px -1px 0 " + AlertShadowColor + ", -1px 1px 0 " + AlertShadowColor + ", 1px 1px 0 " + AlertShadowColor + ";"; &nbsp; &nbsp; &nbsp; var AlertImageStyle = "height: 40px; width: 40px; float: right; margin: -32px 5px 0px 0px;"; &nbsp; &nbsp; &nbsp; sendChat("", "/desc &lt;div style='" + AlertOuterStyle + "'&gt;&lt;div style='" + AlertInnerStyle + "'&gt;" + AlertTokenName + " is Inspired! &lt;/div&gt;&lt;img src='<a href="https://s3.amazonaws.com/files.d20.io/images/39783029/-w45_4ICV9QnFzijBimwKA/max.png" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/39783029/-w45_4ICV9QnFzijBimwKA/max.png</a>' style='" + AlertImageStyle + "'&gt;&lt;/img&gt;&lt;/div&gt;"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Set Status Icon on Token &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',true)); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; const dropInspiration = function (id) { &nbsp; &nbsp; &nbsp; //Remove Status Icon from Token &nbsp; &nbsp; &nbsp; if ( _.isEmpty(id)) return; &nbsp; &nbsp; &nbsp; var character = getObj("character", id); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',false)); &nbsp; &nbsp; &nbsp; }; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; on("chat:message", function(msg) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Is script running? &nbsp; &nbsp; &nbsp; if(msg.type == "api" && msg.content.indexOf("!inspiration") !== -1) {&nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "/desc &lt;div style='max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;'&gt;&lt;div style='max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: fff; background-color: 20b2aa; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 000, 1px -1px 0 000, -1px 1px 0 000, 1px 1px 0 000'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // Has a character sheet been updated? &nbsp; &nbsp; &nbsp; on("change:attribute", function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var isupdated = obj.get("name"); &nbsp; &nbsp; &nbsp; //Was it the Inspiration attribute? &nbsp; &nbsp; &nbsp; if (isupdated =="inspiration"){ &nbsp; &nbsp; &nbsp; var val = obj.get("current"); &nbsp; &nbsp; &nbsp; var id = obj.get("_characterid");&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //Gained Inspiration? &nbsp; &nbsp; &nbsp; if (isupdated =="inspiration" && val == "on"){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Announce Character Inspired &nbsp; &nbsp; &nbsp; announceInspiration(id); &nbsp; &nbsp; &nbsp; }else if (isupdated =="inspiration" && val != "on"){ &nbsp; &nbsp; &nbsp; //Remove Inspiration Icon from Token &nbsp; &nbsp; &nbsp; dropInspiration(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; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; log('-=&gt; HazInspiration &lt;=- V0.2');&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "/desc &lt;div style='max-height: 40px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;'&gt;&lt;div style='max-height: 20px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: hidden; font-family: Candal; font-weight: lighter; font-size: 13px; line-height: 20px; color: fff; background-color: 20b2aa; background-image: linear-gradient(rgba(255, 255, 255, .4), rgba(255, 255, 255, 0)); border: 1px solid #000; border-radius: 4px; text-shadow: -1px -1px 0 000, 1px -1px 0 000, -1px 1px 0 000, 1px 1px 0 000'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp;&nbsp;
1506563805
Loren the GM
Pro
Marketplace Creator
Thanks for this! I'll be giving it a shot in my game - I'm terrible at remembering to reward inspiration, so seeing a visual when players have it on their token might remind me to actually reward it!
Lady Victoria said: This isn't directly helpful to the API script in question, but on the subject of "how I handle inspiration in my game," I use this card I made in Photoshop as a 1-card, infinite-size deck in Roll20 and just drag cards onto players' portraits when they receive inspiration. That the card appears above their portrait is a nice visual cue to everyone. I do something similar.&nbsp; Though my deck has two cards in it.&nbsp; One for Inspiration, and one for Luck tokens.