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] Send Current HP after HP Change to Chat (GM Whisper)

Hi, I'm looking looking for a script that, whenever a token's HP (bar 1) change, sends the new value to chat via a GM Whisper. For any token, and I guess it should refer to the token's name. Why? So that when mistakes happen, even after a couple of rounds, it's easier to construct what happened and figure out where things should be now. I want it to show up in the Chat Log so that even if it scrolls up off the top of the current chat window, it can be viewed with "View all chat entries for this game". I think this is probably fairly simple to do; wondering if anyone has a script that does this already? Thanks.
1611508233

Edited 1611512340
The Aaron
Roll20 Production Team
API Scripter
Give this a try: /* global TokenMod ChatSetAttr */ on('ready',()=>{ const bar = 'bar1'; const upColor = '#0d0'; const downColor = '#f66'; const getActivePages = () => [...new Set([ Campaign().get('playerpageid'), ...Object.values(Campaign().get('playerspecificpages')), ...findObjs({ type: 'player', online: true }) .filter((p)=>playerIsGM(p.id)) .map((p)=>p.get('lastpage')) ]) ]; const sign = (n) => (n>0 ? '+' : (n<0 ? '-' : ' ')); const colored = (c,p,s) => ((c>p) ? `<span style="color:${upColor}">${s?sign(c):''}${c}</span>` : ((c<p) ? `<span style="color:${downColor}">${c}</span>` : c )); const handleTokenChange = (obj,prev)=>{ let pages = getActivePages(); if(pages.includes(prev._pageid) ){ let hp = obj.get(`${bar}_value`); let hpMax = obj.get(`${bar}_max`); let pHp = prev[`${bar}_value`]; let pHpMax = prev[`${bar}_max`]; let hpDiff = (hp-pHp); let hpMaxDiff = (hpMax-pHpMax); if(hp !== pHp || hpMax !== pHpMax){ sendChat('',`/w gm <div style="padding: 2px .5em; font-size: .8em;background: #333;color:#ccc;border-radius:.5em;"><code>${prev.name}</code> ${pHp}/${pHpMax} => ${colored(hp,pHp)}/${colored(hpMax,pHpMax)} (${colored(hpDiff,0,true)}/${colored(hpMaxDiff,0,true)})</div>`); } } }; on('change:graphic', handleTokenChange); if('undefined' !== typeof TokenMod && TokenMod.ObserveTokenChange){ TokenMod.ObserveTokenChange(handleTokenChange); } if('undefined' !== typeof ChatSetAttr && ChatSetAttr.registerObserver){ ChatSetAttr.registerObserver('change',handleTokenChange); } }); Here's what it looks like: Also supports TokenMod and ChatSetAttr changes.
Seems to work well enough; thanks!  It only has an oddity where if there are multiple maps that have a token with the same name, it sends a chat message for every instance of that token name. I tend to leave multiple PC tokens on multiple maps as players are wandering around the dungeon--especially a large one like The Dead in Thay--saves me the trouble of switching tokens around every time they move to a new map. I just have to move them. It's nothing I can't live with though.  Thanks The Aaron!
1611512428
The Aaron
Roll20 Production Team
API Scripter
Easily handled, adjusted the script above to only issue notices for tokens on active pages.  You'll still get multiple notices if you have split the party and have the same character on multiple pages, or if you have multiple copies of the same token on the same page.  I could actually fix that, if that's an issue.
Thanks for this scriplet! I've started using it in my own game, and added a button for undoing the most recent change using TokenMod. Changed this line sendChat('',`/w gm <div style="padding: 2px .5em; font-size: .8em;background: #333;color:#ccc;border-radius:.5em;"><code>${prev.name}</code> ${pHp}/${pHpMax} => ${colored(hp,pHp)}/${colored(hpMax,pHpMax)} (${colored(hpDiff,0,true)}/${colored(hpMaxDiff,0,true)})</div>`); to this sendChat('',`/w gm <div style="padding: 2px .5em; font-size: .8em;background: #333;color:#ccc;border-radius:.5em;"><code>${prev.name}</code> ${pHp}/${pHpMax} => ${colored(hp,pHp)}/${colored(hpMax,pHpMax)} (${colored(hpDiff,0,true)}/${colored(hpMaxDiff,0,true)}) [<code>UNDO CHANGE</code>](`!token-mod --ids ${prev._id} --ignore-selected --set bar1_value|-[[${hpDiff}]])</div>`);