Last active
August 29, 2015 14:08
-
-
Save shdwjk/941cee5942ac4275d9ea to your computer and use it in GitHub Desktop.
Roll20API: MonsterHitDice5e -- Monster Hit Dice script setup to work with Actoba's 5th Edition character sheet for NPCs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GIST: https://gist.github.com/shdwjk/941cee5942ac4275d9ea | |
on('ready', function() { | |
on('add:graphic',function(obj) { | |
if( | |
'graphic' === obj.get('type') | |
&& 'token' === obj.get('subtype') | |
) { | |
setTimeout(_.bind(function(id){ | |
var obj=getObj('graphic',id) | |
if( undefined !== obj | |
&& '' !== obj.get('represents') | |
&& '' === obj.get('bar3_link') ) { | |
var attrib = findObjs({ | |
_type: 'attribute', | |
_characterid:obj.get('represents'), | |
name: 'npc_HP_hit_dice' | |
}) | |
if( attrib.length ) { | |
sendChat('','/r '+attrib[0].get('current'),function(r){ | |
var hp=0; | |
_.each(r,function(subr){ | |
var val=JSON.parse(subr.content); | |
if(_.has(val,'total')) { | |
hp+=val.total; | |
} | |
}); | |
obj.set({ | |
bar3_value: hp, | |
bar3_max: hp | |
}) | |
}); | |
} | |
} | |
},this,obj.id), 500); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment