Open tposney opened 3 years ago
There is a tokenId stored in the workflow. However that tokenId it keeps is either item.actor.token.id (which is correct for unlinked tokens) or ChatMessage.getSpeaker.token which is often the selected token.
In the next release I'll pass the tokenId as one field in args[0], but you might have to experiment
In GitLab by @Akaito1 on Dec 10, 2020, 04:19
Thanks! I'll check it out after updating. I'll be comparing it to this, below, which I started using instead of the 'ownedTokens' filter described previously:
function getChatCardToken(chatId) {
let chatCard = content.ui.chat.collection.get(chatId);
let speaker = chatCard.data.speaker;
if (speaker.token !== null) {
return canvas.tokens.get(speaker.token);
}
else {
let fauxToken = canvas.scene.data.tokens.find(t => {return t.actorId == speaker.actor});
return canvas.tokens.get(fauxToken._id);
}
}
let sourceToken = getChatCardToken(args[0].itemCardId);
In GitLab by @Akaito1 on Dec 10, 2020, 04:43
Ah, unfortunately args[0].tokenId isn't quite right. Just tried changing to let sourceToken = canvas.tokens.get(args[0].tokenId)
. It has the same problem as the existing speaker
that could be found somewhere in the args[0] objects. It's totally fine and valid iff you happen to have the speaker/attacker selected. It acts a bit like canvas.tokens.controlled
.
In GitLab by @Akaito1 on Dec 9, 2020, 07:08
Use case: I'm starting to use the "On Use Macro" to play some TokenMagic FX / JB2A effects. Such as arrows firing from the user of a bow to any hitTargets. But getting the origin of the shot to place/angle/scale the effect is a hassle, because
token
is just whatever token was most recently selected, andargs[0].actor
only knows its prototype token.So currently, to find the token that the attack actually originated from (because names can be ambiguous ("Goblin")), I'm doing this:
It'd be handy to instead go
let sourceToken = args[0].token
or similar to get the token the attack originated from.For completeness, here's the whole macro I'm using. Credit for 90% of it due to contributors to JB2A / TokenMagic FX. I just did the MidiQOL "glue" to find the attack source.