Jay, you can try this. Requires hp to be in bar1 of npc token (the hp attribute doesn't seem to always be populated for dragged out creatures). Also requires selected PC token to represent a "PC" style character sheet, and the target token to represent a "NPC" style character sheet. Put together quickly, so haven't tested much, but you get the idea. syntax !know @{selected|token_id} @{target|Enemy|token_id} script const knowYourEnemy = (() => {
const version = '0.1.0';
const scriptName = 'KnowYourEnemy';
const checkInstall = () => {
log('-=> ' + scriptName + ' v' + version);
};
function processInlinerolls(msg) {
if(_.has(msg,'inlinerolls')){
return _.chain(msg.inlinerolls)
.reduce(function(m,v,k){
var ti=_.reduce(v.results.rolls,function(m2,v2){
if(_.has(v2,'table')){
m2.push(_.reduce(v2.results,function(m3,v3){
m3.push(v3.tableItem.name);
return m3;
},[]).join(', '));
}
return m2;
},[]).join(', ');
m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0;
return m;
},{})
.reduce(function(m,v,k){
return m.replace(k,v);
},msg.content)
.value();
} else {
return msg.content;
}
}
const compare = (pcVal, npcVal) => {
pcVal = Number(pcVal);
npcVal = Number(npcVal);
if (pcVal > npcVal) {
return 'Superior';
} else if (pcVal < npcVal) {
return 'Inferior';
} else {
return 'Equal';
}
}
const handleInput = (msg) => {
let pcTok, npcTok;
let pcChar, npcChar;
if (msg.type=="api" && msg.content.indexOf("!know") === 0 ) {
try {
who = getObj('player',msg.playerid).get('_displayname');
//Check for inline rolls in script input
let inlineContent = processInlinerolls(msg);
let args = inlineContent.split(/\s+/);
args.shift();
//Get Tokens
pcTok = getObj("graphic", args[0]);
npcTok = getObj("graphic", args[1]);
//Get Characters
pcChar = getObj("character", pcTok.get("represents"));
npcChar = getObj("character", npcTok.get("represents"));
//PC values
let pcName = pcTok.get("name");
let pcSTR = getAttrByName(pcChar.id,'strength');
let pcDEX = getAttrByName(pcChar.id,'dexterity');
let pcCON = getAttrByName(pcChar.id,'constitution');
let pcAC = getAttrByName(pcChar.id,'ac');
let pcHP = getAttrByName(pcChar.id,'hp');
//NPC values
let npcName = npcTok.get("name");
let npcSTR = getAttrByName(npcChar.id,'strength');
let npcDEX = getAttrByName(npcChar.id,'dexterity');
let npcCON = getAttrByName(npcChar.id,'constitution');
let npcAC = getAttrByName(npcChar.id,'npc_ac');
let npcHP = npcTok.get("bar1_value");
//Let's compare values
let strResult = compare(pcSTR, npcSTR);
let dexResult = compare(pcDEX, npcDEX);
let conResult = compare(pcCON, npcCON);
let acResult = compare(pcAC, npcAC);
let hpResult = compare(pcHP, npcHP);
//output
let output = `&{template:npcaction} {{rname=Know Your Enemy}} {{name= ${pcName} vs ${npcName}}} {{description=**STR: ${strResult}**
**DEX: ${dexResult}**
**CON: ${conResult}**
**AC: ${acResult}**
**HP: ${hpResult}**
}}`;
sendChat('', `/w GM ` + output);
}
catch(err) {
sendChat('',`/w "${who}" `+ 'Error: ' + err.message);
}
};
};
const registerEventHandlers = () => {
on('chat:message', handleInput);
};
on('ready', () => {
checkInstall();
registerEventHandlers();
});
})();
output