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 with hp script

I am trying to modify a script that tracks hp, but not being familiar enough with everything, I am lost. (a script The Aaron posted  here  originally) Why I am trying to modify the script? I am running Pathfinder 1e, in which a character is disabled at 0 hp, dying in negative hp, and dead at a number of negative hit points equal to the character's Constitution score. Trying to do the following specifically with the script. (using roll20 character sheet for pathfinder 1e) dead at hp = negative constitution (with dead condition) (or at 0 hp if creature has no constitution score) dying at negative hp (with dying condition) disabled at 0 hp (with disabled condition) /* global TokenMod, ChatSetAttr */ on('ready', () => { // Configuration parameters const HPBarNum = 3; const TempHPMarker = 'red'; const DeadMarker = 'dead'; const TempHPAttributeName = 'hp_temp'; // new constants const DisableMarker = 'half-heart'; const DyingMarker = 'skull'; const ConScore = 'constitution'; //end new constants ///////////////////////////////////////////// const bar = `bar${HPBarNum}_value`; const lnk = `bar${HPBarNum}_link`; const max = `bar${HPBarNum}_max`; const mrk = `status_${TempHPMarker}`; const ded = `status_${DeadMarker}`; const die = `status_${DyingMarker}`;    //new const const dis = `status_${DisableMarker}`;  //new const const checkTempHP = (obj) => { let v = parseFloat(obj.get('current')); findObjs({ type: 'graphic', represents: obj.get('characterid') }) .filter( (t) => t.get(lnk) !== '') .forEach((g)=>{ g.set(mrk,(v>0 ? (v>9 ? true : v) : false) ); }); }; const assureTempHPMarkers = () => { let queue = findObjs({ type: 'attribute', name: TempHPAttributeName }); const burndownQueue = ()=>{ if(queue.length){ let attr = queue.shift(); checkTempHP(attr); setTimeout(burndownQueue,0); } }; burndownQueue(); }; const temporalTempHPCache = {}; const accountForHPBarChange = (obj,prev) => { // 1. did hp change and is it a scale const hpMax = parseInt(obj.get(max),10); // new code - set death point of negative Constitution score let DeadPoint = parseInt(0 - obj.get(ConScore),10); // back to original code. let hp = parseInt(obj.get(bar),10); const diff = hp-parseFloat(prev[bar]); if( !isNaN(hpMax) && diff !== 0 ) { let changes = {}; // 2. does it represent a character // 3. does the hp bar represent an attribute const character = getObj('character',obj.get('represents')); if( diff < 0 && character && obj.get(lnk)!=='' ){ // 4. is there temp hp const temp_hp = findObjs({ type: 'attribute', characterid: character.id, name: TempHPAttributeName })[0]; if( temp_hp ) { const now = Date.now(); // 5. have we accounted for it. if( !temporalTempHPCache.hasOwnProperty(character.id) || (now-temporalTempHPCache[character.id].when)>300 ) { // calculate necessary change const tempHP = parseFloat(temp_hp.get('current'))||0; const newTmpHP = Math.max((tempHP+diff),0); const toHeal = tempHP - newTmpHP; temporalTempHPCache[character.id]={ when: now, toHeal: toHeal }; temp_hp.set('current', newTmpHP); checkTempHP(temp_hp); } hp += temporalTempHPCache[character.id].toHeal; changes[bar] = hp; } } if(hp > hpMax) { hp = hpMax; changes[bar] = hp; changes[dis] = false; //new line for new conditions changes[die] = false; //new line for new conditions changes[ded] = false; // original code /* } else if(hp <= 0) { changes[bar] = hp; changes[ded] = true; } */ // start new code for neg hp in pathfinder } else if(hp=0) { changes[bar] = hp; changes[dis] = true; changes[die] = false; changes[ded] = false; } else if( (hp <= 0) && (hp > DeadPoint) ) { changes[bar] = hp; changes[dis] = false; changes[die] = true; changes[ded] = false; } else if(hp <= DeadPoint) { hp = DeadPoint; changes[bar] = hp; changes[dis] = false; changes[die] = false; changes[ded] = true; // end new code } else { changes[dis] = false; // new line for new conditions changes[die] = false; // new line for new conditions changes[ded] = false; } obj.set(changes); } }; const onAttributeChange = (obj) => { if(obj.get('name') === TempHPAttributeName){ checkTempHP(obj); } }; on("change:attribute", onAttributeChange); on("change:token", accountForHPBarChange); if('undefined' !== typeof TokenMod && TokenMod.ObserveTokenChange){ TokenMod.ObserveTokenChange(accountForHPBarChange); } if('undefined' !== typeof ChatSetAttr && ChatSetAttr.registerObserver){ ChatSetAttr.registerObserver('change',onAttributeChange); } assureTempHPMarkers(); }); A second minor issue I have encountered with this script is the updating of the temp hit points with the condition on the token. Everything reports correctly on the character sheet, but the condition number (on the token) does not report correctly.  Thanks for any help in advance.
1585325358
The Aaron
Roll20 Production Team
API Scripter
I can probably help with that later tonight.  With the temp HP not displaying right, is it when the amount of temp HP is greater than 9?  That's a limitation of the Token Markers. It could be extended higher by adding more TokenMarkers, but that starts to get cluttered...
I was specifically keeping temp hp at 9 or lower after seeing in your original post that temp hp or 10 or more did not report correctly. To add more information to the temp hp and condition marker. When I add the temp hp to the character, it displays correctly. If the character heals any amount, temp hp stay correct and reflect correct on the token. It is when the character takes damage that the issues come up. The character sheet shows correct (from memory) at each instance, but the token shows incorrect. Just a thought on this (and I cant tell which way you set it up in the script), could it be because the condition is being modified instead of taken off and reapplied whenever damage is taken?
1585328170
The Aaron
Roll20 Production Team
API Scripter
It's more likely that the method by which the temp hp is updated when damage is taken does not provide an event that the API can use to adjust the TempHP. What makes the change, a Character Sheet Sheet Worker?
I am updating hit points through the token bubble associated with hp (bar 3) directly. I don't know if this matters or helps, but here is a list of scripts I am running (some affect conditions): torch, bump, simple door controls, map lock, marching order, TNN, world map discovery, combat master, token mod, carry tokens, map change, chatsetattr, gm-aura
I just experimented trying to capture an image.  What I did - gave 7 temp hp to alexei through a macro (chatsetattr). worked fine. condition showed up correctly on the alexei token. - did 7 points of damage to alexei in the token bar3 bubble.  the image below is the results.
1585336201
The Aaron
Roll20 Production Team
API Scripter
Can you show the token's settings for bars?  Does @{selected|hp_temp} in chat come back as 0 or 7?
@{selected|hp_temp} returns as 0 attached is a ss of the token setup (basic). Nothing has changed among the tokens/character sheet since the last ss.
To put everything into 1 post (3 screenshots), the first is the setup on giving alexei 7 temp hit points. I do have a macro setup to give temp hp. The second is actual screen shot of how I'm applying damage to alexei. The third screenshot is the result, and the chat window is the last command I entered in the text box to yield the 0  as the last chat message.
1585339128
The Aaron
Roll20 Production Team
API Scripter
That's really bizarre.  It definitely noticed the change since it changed to 9 (which itself is weird).  I'll have to try and duplicate that.  or you can PM me an invite and GM me and I can see about figuring it out in situ.
1585339827

Edited 1585339963
I can do so, but I'm running a game tonight starting at 8pm est. If its not fixed before then, we will deal with it (really a laid back group so won't cause any issues at all).  If you want to take a look before then, thats fine. Otherwise whenever you have time. Invite sent
Thank you for all your help, The Aaron.