Below is a sample of the code I am currently building, and I am currently stumped on how to return the dieResult# out of the send chat function so I am not nesting multiple commands together. I will if I have to, but hope I don't need to. What I have below is how I would like to use this, if possible. on('ready', function() {
on('chat:message', function(msg) {
var args = msg.content.split(' ')
if('!cncAttack' === args.shift() ) {
// Usage: !cncAttack <attacker token id> <BtH> <Damage Roll> <Advantage> <target token id>
// BtH - Character Base to Hit bonus #
// Damage Roll - Die formula for damage roll
// Advantage - S:Standard, A:Advantage, D:Disadvantage
// Example:
// !cncAttack @{selected|token_id} 3 1d8+3 S @{target|token_id}
var attackerTokenID = args[0]
var attackerTokenObj = getObj('graphic', attackerTokenID)
var attackerBtH = args[1]
var attackerDamageRoll = args[2]
var attackerAdvantage = args[3]
var targetTokenID = args[4]
var targetTokenObj = getObj('graphic', targetTokenID)
var targetHP = parseInt(targetTokenObj.get('bar1_value'))
var toHitRoll = 0
sendChat(msg.who, '/roll 1d20', function(ops1) {
var rollResult = JSON.parse(ops[0].content)
var dieResult1 = rollResult.total
})
sendChat(msg.who, '/roll 1d20', function(ops2) {
var rollResult = JSON.parse(ops[0].content)
var dieResult2 = rollResult.total
})
switch(attackerAdvantage) {
case 'S':
toHitRoll = dieResult1
break;
case 'A':
if (dieResult1 >= dieResult2) {
toHitRoll = dieResult1
} else {
toHitRoll = dieResult2
}
break;
case 'D':
if (dieResult1 <= dieResult2) {
toHitRoll = dieResult1
} else {
toHitRoll = dieResult2
}
break;
}
if (toHitRoll >= parseInt(targetTokenObj.get('bar2_value'))) {
sendChat(msg.who, '/roll ' + attackerDamageRoll, function(ops) {
var rollResult = JSON.parse(ops[0].content)
var damageResult = rollResult.total
targetTokenObj.set('bar1_value', targetHP - damageResult)
}
}
})
})