You can get the character object, from the selected, but only if the token has its represents set. These three commands will do that: const selected = msg.selected[0]; const token = getObj('graphic', selected._id); const char = getObj('character', token.get('represents')); You might need to have some error checking in there, to make sure a token is selected, and that token represents a character. Its a bit simpler to require the character id is supplied in the command that launches the script. Here's a quick-and-dirty script to apply healing to a character to represent that: You must call it with this format: !healingpotion @{selected|character_id} [[2d4+2]] This method allows you to change the way a character is selected, like !healingpotion @{Bob|character_id} [[?{Enter healing amount|2d4+2}]] Here's the script, with some error checking (might not be complete). on('ready', function () { on('chat:message', function (msg) { if ('api' === msg.type && msg.content.toLowerCase().startsWith('!healingpotion ')) { const args = msg.content.split(/\s/); const cid = args.length > 1 ? args[1] : 'error';
if (cid === 'error') { sendChat('Healing Potion', '/w GM no character selected.'); return; }
const roll = msg.inlinerolls && msg.inlinerolls.length > 0 ? msg.inlinerolls[0].results.total : 'error'; if (roll === 'error') { sendChat('Healing Potion', '/w GM no inline roll detected.'); return; }
const hp = findObjs({ type: 'attribute', characterid: cid, name: 'hp' })[0] || 'error'; if (hp === 'error') { sendChat('Healing Potion', '/w GM no HP attribute for Healing Potion'); return; } const current = parseInt(hp.get('current')) || 0; const max = parseInt(hp.get('max')) || 0; if(current === 0 || max ===0 ) { sendChat('Healing Potion', "/w GM the character's HP values are not valid."); return; } if (current >= max) { sendChat('character|' + cid, '/em tries to use a Healing potion, but as already at full health.'); return; } hp.set('current', Math.min(current + roll, max)); sendChat('character|' + cid, '/em uses a Healing potion to Recover ' + roll + ' Hit Points.'); } }); });