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

Temp HP Script for Bar 1

1523569712

Edited 1523569750
Having trouble getting this script to work with bar 1 instead of 3, any suggestions? // Github: <a href="https://github.com/shdwjk/Roll20API/blob/master/TempHPAndStatus/TempHPAndStatus.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/TempHPAndStatus/TempHPAndStatus.js</a> // By: The Aaron, Arcane Scriptomancer // Contact: <a href="https://app.roll20.net/users/104025/the-aaron" rel="nofollow">https://app.roll20.net/users/104025/the-aaron</a> var TempHPAndStatus = TempHPAndStatus || (function() { 'use strict'; var version = '0.4.1', lastUpdate = 1427604271, HitPointBarNum = 1, TempHitPointsIn = 'temp_HP', BloodiedMarker = 'half-heart', DyingMarker = 'dead', DeadMarker = 'broken-skull', ASSUME_HEALS = true, CurrentHPLocation = 'bar' + HitPointBarNum + '_value', MaxHPLocation = 'bar' + HitPointBarNum + '_max', TokenChange = function(obj, prev) { if (obj.get("isdrawing")) { return; } var HP = { now: parseInt(obj.get(CurrentHPLocation),10) || 0, old: parseInt(prev[CurrentHPLocation],10) || 0, max: parseInt(obj.get(MaxHPLocation),10) || 0, tmp: 0 }, tmpHPInAttr = false, tmpHPAttr, target = {}; if (0 === HP.max) { return; } if(obj.get(TempHitPointsIn)) { HP.tmp = parseInt(obj.get(TempHitPointsIn),10) || 0; } else if(obj.get('represents')) { tmpHPInAttr = true; tmpHPAttr = findObjs({_type: 'attribute', _characterid: obj.get('represents'), name: TempHitPointsIn})[0]; if(tmpHPAttr) { HP.tmp = parseInt(tmpHPAttr.get('current'),10) || 0; } } HP.bloodied = Math.floor(HP.max/2) || 0; HP.dead = -HP.bloodied; HP.delta = HP.now-HP.old; HP.healed = (HP.delta &gt; 0); HP.hurt = (HP.delta &lt;0); if ( 0 !== HP.delta ) { if (HP.tmp && (HP.delta &lt; 0 )) { target[TempHitPointsIn] = Math.max( HP.tmp + HP.delta, 0 ); HP.delta = Math.min( HP.delta + HP.tmp, 0 ); target[CurrentHPLocation] = Math.min( HP.old + HP.delta, HP.max ); HP.now = target[CurrentHPLocation]; HP.tmp = target[TempHitPointsIn]; } else if (HP.now &gt; HP.max) { HP.now=HP.max; target[CurrentHPLocation]=HP.max; } else if( ASSUME_HEALS && HP.old &lt; 0 && (HP.delta &gt; 0)) { HP.now=Math.min( HP.delta, HP.max ); target[CurrentHPLocation]=HP.now; } if ( HP.now &lt;= HP.dead ) { HP.now=HP.dead; target[CurrentHPLocation]=HP.dead; target['status_'+DeadMarker]=true; } else { target['status_'+DeadMarker]=false; } if ( HP.now &lt;= 0 && HP.now &gt; HP.dead ) { target['status_'+DyingMarker]=true; } else { target['status_'+DyingMarker]=false; } if ( HP.now &lt;= HP.bloodied && HP.now &gt; HP.dead ) { target['status_'+BloodiedMarker]=true; } else { target['status_'+BloodiedMarker]=false; } if(tmpHPInAttr) { if(tmpHPAttr && undefined !== target[TempHitPointsIn] ) { tmpHPAttr.set({current: (target[TempHitPointsIn] || 0)}); } delete target[TempHitPointsIn]; } obj.set(target); } }, checkInstall = function() { log('-=&gt; TempHPAndStatus v'+version+' &lt;=- ['+(new Date(lastUpdate*1000))+']'); }, RegisterEventHandlers = function() { on('change:token', TokenChange); }; return { CheckInstall: checkInstall, RegisterEventHandlers: RegisterEventHandlers }; }()); on('ready',function(){ 'use strict'; TempHPAndStatus.CheckInstall(); TempHPAndStatus.RegisterEventHandlers(); });
1523586375
Kirsty
Pro
Sheet Author
Try changing line 8: HitPointBarNum =1, to HitPointBarNum =3,
Kirsty said: Try changing line 8: HitPointBarNum =1, to HitPointBarNum =3, Unfortunatley nope still doesnt work for changes on bar 1
1523587435

Edited 1523587737
Kirsty
Pro
Sheet Author
Sorry, it's late and my brain is a little slow. Is what you posted the original script or does that include your modifications? HitPointBarNum = 1,&nbsp; looks like it should make changes based on bar 1. That's not happening now? Does it change on any other bar or not at all? Are you getting an error message? Edit: Nevermind I had a look at the original. Try changing the version number. I think that will solve your problems.
Kirsty said: Sorry, it's late and my brain is a little slow. Is what you posted the original script or does that include your modifications? HitPointBarNum = 1,&nbsp; looks like it should make changes based on bar 1. That's not happening now? Does it change on any other bar or not at all? Are you getting an error message? Edit: Nevermind I had a look at the original. Try changing the version number. I think that will solve your problems. Change the version number to what? It does not seem to working with any bars actually.
1523590056
Kirsty
Pro
Sheet Author
It's not working at all? Hmm. I'm on my phone atm. If The Aaron doesn't appear in the meantime, I'll have a look when I'm on my computer tomorrow&nbsp;
1523628038
Kirsty
Pro
Sheet Author
I put the script into a test game, and it worked perfectly for me. Changing line 8 (HitPointBarNum = 1,) worked to switch over the bar number to bar 1. I'd suggest disabling your other API scripts to make sure that there's no interference. If that doesn't work, you're welcome to PM me with a link to the game and I can try and take a look for you (full disclosure, I'm no Scriptomancer!)
1523894133
The Aaron
Pro
API Scripter
Hi, sorry, I've been on vacation all week and I'm just getting caught up again. Changing the version number isn't going to help here (You're remembering the schemaVersion change hack for TurnMarker1).&nbsp; There is probably something else going on. 1)&nbsp; Is the token you're using a "drawing", meaning if you right click it and go to advanced, is that on? This script skips drawing graphics, so it would not make any changes to them if that was the case. 2) Do they have a bar max value other than 0?&nbsp; If they have a 0, it skips them. If you get here, then there is probably some other error.&nbsp; I wrote this script over 3 years ago, and some things have changed.&nbsp; If the above doesn't fix it, feel free to PM me an invite and GM me and I'll come take a look.