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

[Script Update] Small fixes to Inspiration Tracking

1527254543

Edited 1527254799
Thorsten
KS Backer
The inspiration tracking script found here:&nbsp; <a href="https://app.roll20.net/forum/post/5579750/help-5e-" rel="nofollow">https://app.roll20.net/forum/post/5579750/help-5e-</a>... by Giger had a few small issues. The original thread is locked. I sincerely hope sharing my changes is okay. If you object, Giger, I'll remove this post. 1) It would crash if a character was controlled by "All Players" 2) The "Inspiration Tracking Online" announcement did not render well because of the way the shadow was applied. I removed the shadow entirely. Alternatively, getting this to work more like the "is inspired" announcement is an option, where the shadow works well. 3) Long character names now announce correctly, and the graphic is no longer clipped - it will render partially outside the announcement which I think looks fine On 2): This did not show in Chrome and Firefox because color was 000 instead of #000. Set it it #000 and the issue shows. It always showed in Edge. //HazInspiration v. 0.21 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 ( Shaped by Kryx ) Character Sheet. &nbsp; &nbsp;&nbsp; */ on('ready',()=&gt;{ const getCharacterTokens = (cid) =&gt; findObjs({type:'graphic'}).filter((t)=&gt;t.get('represents')===cid); //Brightness&nbsp; &nbsp; &nbsp; var getBrightness = getBrightness || {}; &nbsp; &nbsp; var getHex2Dec = getHex2Dec || {}; &nbsp; &nbsp; function getBrightness(hex) { &nbsp; &nbsp; &nbsp; &nbsp; hex = hex.replace('#', ''); &nbsp; &nbsp; &nbsp; &nbsp; var c_r = getHex2Dec(hex.substr(0, 2)); &nbsp; &nbsp; &nbsp; &nbsp; var c_g = getHex2Dec(hex.substr(2, 2)); &nbsp; &nbsp; &nbsp; &nbsp; var c_b = getHex2Dec(hex.substr(4, 2)); &nbsp; &nbsp; &nbsp; &nbsp; return ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000; &nbsp; &nbsp; }; &nbsp; &nbsp; function getHex2Dec(hex_string) { &nbsp; &nbsp; &nbsp; &nbsp; hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, ''); &nbsp; &nbsp; &nbsp; &nbsp; return parseInt(hex_string, 16); &nbsp; &nbsp; }; &nbsp; const announceInspiration = function (id) { &nbsp; &nbsp; //Handles Chat Annoucement &nbsp; &nbsp; if ( _.isEmpty(id)) return; &nbsp; &nbsp; var character = getObj("character", id); &nbsp; &nbsp; AlertTokenName = character.get("name"); &nbsp; &nbsp; var AlertColor = (character.get("controlledby").split(",")[0] === "all") ? "#FFF" : getObj("player", character.get("controlledby").split(",")[0]).get("color"); &nbsp; &nbsp; var AlertTextColor = (getBrightness(AlertColor) &lt; (255 / 2)) ? "#FFF" : "#000"; &nbsp; &nbsp; var AlertShadowColor = (AlertTextColor == "#000") ? "#FFF" : "#000"; &nbsp; &nbsp; var AlertOuterStyle = "max-height: 60px; width: 100%; margin: 10px 0px 5px -7px; line-height: 40px;"; &nbsp; &nbsp; var AlertInnerStyle = "max-height: 40px; width: 100%; margin: 0px; padding: 0px 0px 2px 0px; clear: both; overflow: visible; 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; var AlertImageStyle = "height: 40px; width: 40px; float: right; margin: -32px 5px 0px 0px;"; &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; //Set Status Icon on Token &nbsp; &nbsp; &nbsp; &nbsp; getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',true)); &nbsp; }; &nbsp; const dropInspiration = function (id) { &nbsp; &nbsp; //Remove Status Icon from Token &nbsp; &nbsp; if ( _.isEmpty(id)) return; &nbsp; &nbsp; var character = getObj("character", id); &nbsp; &nbsp; getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',false)); &nbsp; }; &nbsp; on("chat:message", function(msg) { &nbsp; &nbsp; &nbsp; //Is script running? &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'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); &nbsp; &nbsp; } &nbsp; }); &nbsp; // Has a character sheet been updated? &nbsp; on("change:attribute", function(obj) { &nbsp; &nbsp; &nbsp; var isupdated = obj.get("name"); &nbsp; &nbsp; //Was it the Inspiration attribute? &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 == "1"){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Announce Character Inspired &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; announceInspiration(id); &nbsp; &nbsp; &nbsp; }else if (isupdated =="inspiration" && val != "1"){ &nbsp; &nbsp; &nbsp; &nbsp; //Remove Inspiration Icon from Token &nbsp; &nbsp; &nbsp; &nbsp; dropInspiration(id); &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; } &nbsp; }); &nbsp; log('-=&gt; HazInspiration &lt;=- V0.21');&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'&gt;Inspiration Tracking Online!&lt;/div&gt;&lt;/div&gt;"); });
1527473426
Giger
API Scripter
Neat!!&nbsp; I definitely do not object :) The only thing i think that is incorrect is the "1" on isupdated. if (isupdated =="inspiration" && val == "1"){ // Announce Character Inspired announceInspiration(id); } else if (isupdated =="inspiration" && val != "1"){ //Remove Inspiration Icon from Token dropInspiration(id); } Inspiration is either "on" or "0"; at least on my end. if (isupdated =="inspiration" && val == "on"){ // Announce Character Inspired announceInspiration(id); } else if (isupdated =="inspiration" && val != "on"){ //Remove Inspiration Icon from Token dropInspiration(id); I'm still trying to figure out how to get "announceInspiration" to fire the very first time the player gets inspired, as the script doesn't see to execute when the attribute is first created.
Hmm. I didn't change that part of the code, and it appears to work. I wonder whether that's because you used '==', which would do type conversion for the comparison. It's your code, change it to "on" if that works more reliably :).