Here's an improved version of the script. To use it, you just need to get the character id's for the characters you want to toggle control of. The easiest way to do that is to select tokens that represent those characters and enter @{selected|character_id} in chat. Then copy/paste the character id's into the script like this ... var CharacterIDs = ["id", "id", "id"] ... replacing id with the actual id shown in chat. It should look like this: var CharacterIDs = ["-KHWScTHo_oHinvteAqm", "-KGucJWiVEW9vZhF7_eM", "-KHWSkIxLWXyGIO5A4dJ"]; Due to the way lighting doesn't update until a token change has been triggered, this version includes adding a green dot to the token at the top of the turn order. You could use whatever status icon you want, but I haven't been able to find an easy way to trigger the change. Maybe TheAaron can figure something out. on("change:campaign:turnorder", function(current, previous) {
var CharacterIDs = ["-KHWScTHo_oHinvteAqm", "-KGucJWiVEW9vZhF7_eM", "-KHWSkIxLWXyGIO5A4dJ"];
var CurrentTO = JSON.parse(current.get("turnorder"));
var PreviousTO = JSON.parse(previous["turnorder"]);
var Token;
var Character;
// Save F2F data...
if (!state.f2f) state.f2f = {};
if (_.isEmpty(state.f2f)) {
_.each(CharacterIDs, function(charid) {
Character = getObj("character", charid);
state.f2f[charid] = {
CharacterID: charid,
ControlledBy: Character.get("controlledby")
}
});
}
// Process the turn order...
if (CurrentTO.length > 0) {
_.each(state.f2f, function(a) {
getObj("character", a["CharacterID"]).set("controlledby", "");
});
if (CurrentTO[0].id != -1) Token = getObj("graphic", CurrentTO[0].id);
if (CurrentTO[0].id != -1 && Token.get("represents") !== "") Character = getObj("character", Token.get("represents"));
if (CurrentTO[0].id != -1 && Token.get("represents") !== "" && Character.id in state.f2f) {
Character.set("controlledby", state.f2f[Character.id]["ControlledBy"]);
} else {
// Return control to all players during npc and custom item turns...
_.each(state.f2f, function(b) {
getObj("character", b["CharacterID"]).set("controlledby", b["ControlledBy"]);
});
}
} else {
// Turn order tracker is empty. Return control to all players...
_.each(state.f2f, function(z) {
getObj("character", z["CharacterID"]).set("controlledby", z["ControlledBy"]);
});
state.f2f = {};
}
// Simple Initiative Tracker (Green Dot)...
if (CurrentTO.length === 0 && PreviousTO[0].id != -1) getObj("graphic", PreviousTO[0].id).set("status_green", false);
if (CurrentTO.length > 0 && CurrentTO[0].id != -1) getObj("graphic", CurrentTO[0].id).set("status_green", true);
if (PreviousTO.length > 0 && PreviousTO[0].id != -1) getObj("graphic", PreviousTO[0].id).set("status_green", false);
});