Created
April 6, 2016 21:19
-
-
Save symposion/5da32baf5394f34d53d6ca4fd8f89a37 to your computer and use it in GitHub Desktop.
Simple attribute removal code
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
var monsterData = { name:'Lich', AC:'20', HP:'99', alignment:'lawful evil', type:'undead', size:'Medium', challenge: '20' }; | |
on('chat:message', function(msg) { | |
if(msg.content === '!api-test') { | |
var characterId = getObj('graphic', msg.selected[0]._id).get('represents'); | |
var character = getObj('character', characterId); | |
var oldAttrs = findObjs({type: 'attribute', characterid: characterId}); | |
_.invoke(oldAttrs, 'remove'); | |
character.set('name', monsterData.name); | |
setAttrByName(characterId, 'import_data', JSON.stringify(monsterData)); | |
setAttrByName(characterId, 'import_data_present', 'on'); | |
setAttrByName(characterId, 'sheetOutput', '@{output_to_all}'); | |
setAttrByName(characterId, 'deathSaveOutput', '@{output_to_all}'); | |
} | |
}); | |
function setAttrByName(characterId, attributeName, value) { | |
var attrs = findObjs({type:'attribute', name:attributeName, characterid:characterId}); | |
if(attrs[0]) { | |
attrs[0].set('current', value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment