Hey everyone, me again. Is it possible to chain API calls via using sendChat(charName, "!call")? What I'm trying to achieve, is it provide my players with opportunity to target arbitrary number of enemies. So the logic is, a player presses a button in his character sheet, which triggers !shoot function, which requires him to input a number of targets he's trying to shoot. Then, based on input number, !shoot function constructs a call to !autofire function with variable number of @{target|...} calls, which it then sends to chat via sendChat(charName, autoFireCall). At first I was getting ERROR: Unable to find character target in chat command., but googling led me to this post (thanks once again, Aaron, for all the good work you do here) and utilized escaping the command I send to chat, alas to no avail - the error is no more, but nothing happens. Should I really use chat buttons for such task? I would really like to minimize number of clicks before result is produced. The !autofire call then should chain into another one, so it would take a while to sort things out by pressing buttons. Here are some snippets, the whole script is somewhat long: let autoFireCall = `!autofire!!${charName}!!${weaponId}!!${weaponName}!!${damageDice}!!${bulletsPerTarget}!!${toHitNumber}!!${targets}`;
for (let i = 1; i <= targets; i++) {
autoFireCall = autoFireCall.concat(`!!@{target|Target ${i}|character_name}`);
/*rollTemplate = rollTemplate.concat(
`{{Target ${i}}} `,
`{{Bullets hit ${i}=[[(1d10 + @{${charName}|ref_modified} + @{${charName}|marksmanship} + @{${charName}|repeating_weapons_${weaponId}_weapon_accuracy} + ${attackMod})]] - [[${toHitNumber}]] (${bulletsPerTarget} max)}} `
)*/
}
log("escaping autoFireCall");
log(HE(autoFireCall));
sendChat(charName, HE(autoFireCall));
return;
//!autofire!!${charName}!!${weaponId}!!${weaponName}!!${damageDice}!!${bulletsPerTarget}!!${toHitNumber}!!${targets}
on("chat:message", function(msg) {
if (msg.type == "api" && msg.content.indexOf("!autofire") !== -1) {
let args = msg.content.split('!!');
args = args.slice(1, args.length);
let i = 0;
let charName = args[i++];
let weaponId = args[i++];
let weaponName = args[i++];
let damageDice = args[i++];
let bulletsPerTarget = args[i++];
let toHitNumber = args[i++];
let targetsNumber = args[i++];
let targets = [];
for (let t = 0; i++, t++; t < targetsNumber) {
targets.push(args[i]);
}
let character = findObjs({ type: 'character', name: charName })[0];
_.each(targets, function (targetName) {
let target = findObjs({type: 'character', name: targetName})[0];
//`{{attack=[[1d10 + @{${charName}|ref_modified} + @{${charName}|marksmanship} + @{${charName}|repeating_weapons_${weaponId}_weapon_accuracy}]]}} `
let refMod = get(findObjs({type: "attribute", _characterid: character.id, name: `ref_modified`}, {caseInsensitive: true})[0]);
let marksmanship = get(findObjs({type: "attribute", _characterid: character.id, name: `marksmanship`}, {caseInsensitive: true})[0]);
let weaponAccuracy = get(findObjs({type: "attribute", _characterid: character.id, name: `repeating_weapons_${weaponId}_weapon_accuracy`}, {caseInsensitive: true})[0]);
let hitRoll = randomInteger(10) + refMod + marksmanship + weaponAccuracy;
let hits = hitRoll - toHitNumber;
if(hits > 0) {
spawnShootingFx(character, target);
let hitCall = `!hit!!${charName}!!${targetName}!!${hits}!!${damageDice}`;
sendChat(charName, hitCall);
} else {
let missTemplate = `&{template:default}{{name=Miss on ${targetName}}}`;
sendChat(charName, missTemplate);
}
})
}
});