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

TokenMod with Concentration and health macro help

So, I'm using tokenmod with keithcurtis's concentration script to track concentration and remind players to roll concentration checks. I also found an easy macro he made for adding and subtracting hp, but i noticed that using the macro to subtract hp does not trigger the concentration check mod. Is there something I can change to make sure the macro triggers the reminder, or are these two just not going to work together? the macro !token-mod --set bar1_value|?{Enter damage or healing amount. Use positive or negative to modify values|-0} the mod on('ready', () => { const TOKEN_CONCENTRATING_STATUS_MARKER = "status_" + "While_Concentrating::3742111"; on("change:graphic:bar1_value", function(obj, prev) { if (obj.get(TOKEN_CONCENTRATING_STATUS_MARKER)) { log ("status marker is " + obj.get(TOKEN_CONCENTRATING_STATUS_MARKER)); //let playerPage = Campaign().get("playerpageid"); //let tokenPage = obj.get("_pageid"); if (prev["bar1_value"] > obj.get("bar1_value")) { let final_conc_DC = 10; let calc_conc_DC = (prev["bar1_value"] - obj.get("bar1_value")) / 2; if (calc_conc_DC > final_conc_DC) { final_conc_DC = Math.floor(calc_conc_DC); } let tokenName = obj.get("name"); let theMessage = "/w gm &{template:npcaction} {{rname=Concentration Check "+tokenName+"}} {{name="+tokenName+"}} {{description=[DC " +final_conc_DC + " Constitution](~selected|constitution_save)"+ "
" +"}}"; sendChat("Concentration",theMessage ); } } }); });
1728003159
timmaugh
Pro
API Scripter
Hi, Lee...  Sorry, I made a mental note to answer this when I saw it a day or so ago, then forgot by the time I got back to my laptop. The issue you're dealing with, basically, is that scripts don't emit events (other than chat events). This is done so that we don't ever get into infinite loops. The good news is that TokenMod exposes an observer registration so you can code other scripts to "listen" for TokenMod events the same way they listen for Roll20 events (even with the same function, normally). TokenMod emits the standard  change:graphic  event, while your script expects something more specific, so you're going to need to test for the actual change you're looking for. This is air-coded and untested, but I think this is what you're looking for: on('ready', () => {     const TOKEN_CONCENTRATING_STATUS_MARKER = "status_" + "While_Concentrating::3742111";     const handleBarChange = (obj, prev) => {         if (obj.get(TOKEN_CONCENTRATING_STATUS_MARKER)) {             log("status marker is " + obj.get(TOKEN_CONCENTRATING_STATUS_MARKER));             //let playerPage = Campaign().get("playerpageid");             //let tokenPage = obj.get("_pageid");             if (prev["bar1_value"] > obj.get("bar1_value")) {                 let final_conc_DC = 10;                 let calc_conc_DC = (prev["bar1_value"] - obj.get("bar1_value")) / 2;                 if (calc_conc_DC > final_conc_DC) {                     final_conc_DC = Math.floor(calc_conc_DC);                 }                 let tokenName = obj.get("name");                 let theMessage = "/w gm &{template:npcaction} {{rname=Concentration Check " + tokenName + "}} {{name=" + tokenName + "}} {{description=[DC " + final_conc_DC + " Constitution](~selected|constitution_save)" + "
" + "}}";                 sendChat("Concentration", theMessage);             }         }     };     const handleTokenModChange = (obj, prev) => {         if (obj.get('bar1_value') !== prev.bar1_value) {             handleBarChange(obj, prev);         }     };     on("change:graphic:bar1_value", handleBarChange);     let tm = TokenMod || {};     if (tm.hasOwnProperty("ObserveTokenChange")) {         TokenMod.ObserveTokenChange(handleTokenModChange);     } });
AH Holy cow YES. Thank you for explaining, I figured there had to be some reasoning behind it my brain has just been mashed potatoes lately. The modifications you made seem to be working perfectly. Thank you so much!