So, as usual, just as I posted this I tried something else and it worked for some reason. I'm still interested why it didn't work though. Here's not working version: on("chat:message", function(msg) {
if(msg.type == "api" && msg.content.indexOf("!shoot") !== -1) {
log(msg.content);
let rollTemplate = "&{template:default} ";
let args = msg.content.split('!!');
log(args[0]);
log(args[1]);
log(args[2]);
log(args[3]);
args = args.slice(1, args.length);
log(args);
let id = args[0];
let weaponName = args[1];
let shotType = args[2];
log(shotType);
switch (shotType) {
case "single":
rollTemplate = rollTemplate.concat(
`{{name=Single shot from ${weaponName}} `,
"{{attack=[[1d10 + @{ref_modified} + @{marksmanship} + @{weapon_accuracy}]]}} ",
"{{damage=[[@{weapon_damage}]]}} ",
"{{location=[[1t[Hit-Location]]]}} "
);
break;
case "burst":
rollTemplate = rollTemplate.concat(
`{{name=Burst from ${weaponName}} `,
"{{attack=[[1d10 + @{ref_modified} + @{marksmanship} + @{weapon_accuracy}]]}} ",
"{{damage=[[@{weapon_damage}]], [[@{weapon_damage}]], [[@{weapon_damage}]]}} ",
"{{location=[[3t[Hit-Location]]]}}"
);
break;
case "auto":
let targets = args[3]*1;
let range = args[4];
let rof = args[5]*1;
let toHitNumber = args[6]*1;
let blankSpots = targets - 1;
let attackMod = (range === "close" ? +1 : -1) * Math.floor(rof / 10);
let bulletsPerTarget = Math.floor(rof / (targets + blankSpots));
rollTemplate = rollTemplate.concat(`{{name=Auto fire from ${weaponName}}} `);
for (let i = 1; i <= targets; i++) {
rollTemplate = rollTemplate.concat(
`{{Target ${i}}} `,
`{{Bullets hit=[[(1d10 + @{ref_modified} + @{marksmanship} + @{weapon_accuracy} + ${attackMod}) - ${toHitNumber}]] (${bulletsPerTarget} max}} `,
`{{Roll damage and location for each bullet hit}} `
)
}
break;
default: log("default");
}
log(rollTemplate);
sendChat(msg.who, rollTemplate);
}
});
And here's one that works: on("chat:message", function(msg) {
if(msg.type == "api" && msg.content.indexOf("!shoot") !== -1) {
log(msg.content);
let rollTemplate = "&{template:default} ";
let args = msg.content.split('!!');
log(args[0]);
log(args[1]);
log(args[2]);
log(args[3]);
args = args.slice(1, args.length);
log(args);
let id = args[0];
let weaponName = args[1];
let shotType = args[2];
log(shotType);
switch (shotType) {
case "single":
rollTemplate = rollTemplate.concat(
`{{name=Single shot from ${weaponName}}} `,
`{{attack=[[1d10 + @{${msg.who}|ref_modified} + @{${msg.who}|marksmanship} + @{${msg.who}|repeating_weapons_${id}_weapon_accuracy}]]}} `,
`{{damage=[[@{${msg.who}|repeating_weapons_${id}_weapon_damage}]]}} `,
"{{location=[[1t[Hit-Location]]]}} "
);
break;
case "burst":
rollTemplate = rollTemplate.concat(
`{{name=Burst from ${weaponName}}}`,
`{{attack=[[1d10 + @{${msg.who}|ref_modified} + @{${msg.who}|marksmanship} + @{${msg.who}|repeating_weapons_${id}_weapon_accuracy}]]}} `,
"{{damage=[[@{weapon_damage}]], [[@{weapon_damage}]], [[@{weapon_damage}]]}} ",
"{{location=[[3t[Hit-Location]]]}}"
);
break;
case "auto":
let targets = args[3]*1;
let range = args[4];
let rof = args[5]*1;
let toHitNumber = args[6]*1;
let blankSpots = targets - 1;
let attackMod = (range === "close" ? +1 : -1) * Math.floor(rof / 10);
let bulletsPerTarget = Math.floor(rof / (targets + blankSpots));
rollTemplate = rollTemplate.concat(`{{name=Auto fire from ${weaponName}}} `);
for (let i = 1; i <= targets; i++) {
rollTemplate = rollTemplate.concat(
`{{Target ${i}}} `,
`{{Bullets hit=[[(1d10 + @{${msg.who}|ref_modified} + @{${msg.who}|marksmanship} + @{${msg.who}|repeating_weapons_${id}_weapon_accuracy} + ${attackMod}) - ${toHitNumber}]] (${bulletsPerTarget} max}} `,
`{{Roll damage and location for each bullet hit}} `
)
}
break;
}
log(rollTemplate);
sendChat(msg.who, rollTemplate);
}
}); I guess that previous behaviour was somehow caused by missing } on this line `{{name=Single shot from ${weaponName}} `, but how it affected logging and execution flow is beyond me. Perhaps it somehow corrupted output to the console?