Skip to content

Instantly share code, notes, and snippets.

@shdwjk
Created June 17, 2014 16:13
Show Gist options
  • Save shdwjk/7377de58100f4e813432 to your computer and use it in GitHub Desktop.
Save shdwjk/7377de58100f4e813432 to your computer and use it in GitHub Desktop.
Roll20 API: Set Monster hit dice on add
// GIST: https://gist.github.com/shdwjk/7377de58100f4e813432
on('ready', function(){
on('add:graphic',function(obj){
if(
'graphic' == obj.get('type')
&& 'token' == obj.get('subtype')
&& '' != obj.get('represents')
)
{
setTimeout(_.bind(function(id){
var obj=getObj('graphic',id)
if(
undefined != obj
&& '' == obj.get('bar2_link')
)
{
var attrib = findObjs({
_type: 'attribute',
_characterid:obj.get('represents'),
name: 'HitDice'
})
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({
bar2_value: hp,
bar2_max: hp
})
});
}
}
},this,obj.id), 100);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment