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

Doubt about script and macro to give and use inspiration

I just started trying to learn to build scripts and macros and need some help. So I will say what I intend to achieve first and how far i have gonne copying other sollutions and changing them. What I want is to have a macro and/or script that gives inspiration and use inspiration, announcing in the chat that the inspiration has been giving or used by selected token/character, toggling the character sheet inspiration button and setting an Icon for inspiration in the character token. So I am using a Script from&nbsp; Nehrim &nbsp;(HazInspiration) to set the inspiration icon and a Macro from&nbsp; keithcurtis &nbsp;that uses a deck of card to distribute Inspiration. In the end those are not quite what I am intending to control the Inspiration system. I fiddled with keith Macro to use charsetattrb to togle Inspiration On and Off and it works (basically i justed added the setattr line, the rest is keith works). For awarding !roll20AM --audio,play,nomenu| name_of_inspiration_award_track !setattr --sel --silent --replace --inspiration|'on' --rtype|'\at{inspiration}' &amp;{template:npcaction} {{rname=Congratulations!}} {{description=**@{selected|character_name} has just been granted Inspiration!** [x]( URL_of_inspiration_card_image )}} For spending: !roll20AM --audio,play,nomenu| name_of_inspiration_spending_track !setattr --sel --silent --replace --inspiration|'off' --rtype|'\at{inspiration}' &amp;{template:npcaction} {{rname=Inspiration!}} {{description=**@{selected|character_name} has just spent their Inspiration!** [x]( URL_of_inspiration_card_image )}} When I do this,&nbsp; Nehrim &nbsp;script bellow dosen't reconize that the chacter sheet inspiration has been toggle On or Off, and dosen't set an Icon for inspiration in the character token. When i toggle inspiration by hand in the character sheet it recognizes and set the token icon. As i am already using keith macro to send in the chat that the character has received or is using inspiration, the only part I really intend to use in Nehrim script bellow is the part that checks if the character sheet has been updated and set a icon (black-flag) in the character token. I could use the Token Mod Script directly and put a line in the macros above to set the icon (black-flag) to true or false depending if I am giving Inspiration or using inspiration, but it is not the final solution I am looking for, because if I put a new token in a map it will not set the icon automatically in the token in accordance to if the character sheet has inspiration or not. The question is: Is there a way to check if the attribute inspiration is on or off in the character sheet and set the icon black-flag in all the tokens in the map accordingly to its character sheet status? //HazInspiration v. 0.2 created 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) /* This script reports to the chat window, and updates the players token with an icon, to indicate whether the player has Inspiration or not. Designed for the 5th Edition ( OGL by Roll20 ) Character Sheet. */ on('ready',()=&gt;{ const getCharacterTokens = (cid) =&gt; findObjs({type:'graphic'}).filter((t)=&gt;t.get('represents')===cid); //Brightness var getBrightness = getBrightness || {}; var getHex2Dec = getHex2Dec || {}; function getBrightness(hex) { hex = hex.replace('#', ''); var c_r = getHex2Dec(hex.substr(0, 2)); var c_g = getHex2Dec(hex.substr(2, 2)); var c_b = getHex2Dec(hex.substr(4, 2)); return ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000; }; function getHex2Dec(hex_string) { hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, ''); return parseInt(hex_string, 16); }; const announceInspiration = function (id) { //Handles Chat Annoucement if ( _.isEmpty(id)) return; var character = getObj("character", id); 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;"); //Set Status Icon on Token getCharacterTokens(character.id).forEach((t)=&gt;t.set('status_black-flag',true)); }; const dropInspiration = function (id) { //Remove Status Icon from Token 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) { //Is script running? if(msg.type == "api" &amp;&amp; msg.content.indexOf("!inspiration") !== -1) { 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"); //Was it the Inspiration attribute? if (isupdated =="inspiration"){ var val = obj.get("current"); var id = obj.get("_characterid"); //Gained Inspiration? if (isupdated =="inspiration" &amp;&amp; val == "on"){ // Announce Character Inspired announceInspiration(id); }else if (isupdated =="inspiration" &amp;&amp; val != "on"){ //Remove Inspiration Icon from Token dropInspiration(id); } } }); log('-=&gt; HazInspiration &lt;=- V0.2'); 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;"); });
I could be wrong but as far as i know there is no way to have the token automatically check for a character sheet attribute and apply a status marker automatically when dragged to the table. The reason you can toggle inspo from the character sheet and the flag updates, but doesn't when you toggle via api, is likely because of the way the Nehrim script is checking for status updates...I think there are two methods to do that, and one isn't triggered by the api. (I also think the one that is triggered by the API is bugged? I think I read that somewhere). I'd wait for one of the more experienced scripters to comment but I think this is what's going on.
Thanks for the reply. Well, i can always use Copy and Paste when changing maps so that the token already comes with the Inspiration and drop HazInspiration script. Gonna use only the macro with TokenMod. Thanks very much