EDIT - cross-posted! Tim's solution is prettier :) - Hey, at least I got some experience messing with attributes Well, I had 40min to kill at work while waiting for some test results (and I wanted to eventually play with some attribute-related stuff for another script I'm working on since I hadn't worked with them in the API before), so I went ahead and put this script together. Syntax !injuries --CharName Looks for all attributes starting with "inj" (case insensitive) and displays the attribute name with the "inj" prefix removed. Has conditional output for current and max values, if exists. The script const InjuryReport = (() => {
const version = '0.1.0';
const checkInstall = () => {
log('-=> InjuryReport v'+version);
};
const handleInput = (msg) => {
if(msg.type=="api" && msg.content.indexOf("!injuries") === 0 ) {
try {
who = getObj('player',msg.playerid).get('_displayname');
let charName = msg.content.split(/--/)[1].trim();
let char = findObjs({
_type: "character",
name: charName
});
if (char[0] !== undefined) {
var attrs = findObjs({
_type: "attribute",
_characterid: char[0].get('_id')
}, {caseInsensitive: true});
attrs = attrs.filter(att => att.get('name').toLowerCase().indexOf("inj") === 0);
} else {
sendChat('API', `/w "${who}"" Unable to find character named ${charName}`);
return;
}
let output = `/w "${who}" &{template:default} {{name=${charName} Injury Report}} `;
if (attrs.length === 0) {
output = output + '{{N/A=}}';
} else {
attrs.forEach(att => {
let name = att.get('name').replace(/inj/i, "");
let current = att.get('current');
let max = att.get('max');
if (max !== "") {
output = output + `{{${name}=${current} / ${max}}}`;
} else {
output = output + `{{${name}=${current}}}`;
}
});
}
sendChat('API', output);
}
catch(err) {
sendChat('API',`/w "${who}" Error: ${err.message}`);
}
};
};
const registerEventHandlers = () => {
on('chat:message', handleInput);
};
on('ready', () => {
checkInstall();
registerEventHandlers();
});
})(); Example output (BigToe has current and max, Head only has current, and Tuchus contains a text string). The next character is uninjured.