Nevermind, I got it! It works great. To use it make a macro called !SaveTurnOrder and !LoadTurnOrder. Run !SaveTurnOrder, then on another map select whatever tokens you want to add and run !LoadTurnOrder. on("ready",function(){
on("chat:message",function(msg){
if(msg.type=="api" && msg.content.indexOf("!SaveTurnOrder")==0)
{
// Read in each init in the init order
var turnorder;
if(Campaign().get("turnorder") == "") turnorder = []; //NOTE: We check to make sure that the turnorder isn't just an empty string first. If it is treat it like an empty array.
else turnorder = JSON.parse(Campaign().get("turnorder"));
// Erase the stored turn order
state.StoredTurnOrder = [];
// Make a for loop and then turn each id into an array with the character name and init. If the character doesn't have an ID (-1) then skip it.
for (let i = 0; i < turnorder.length; i++) {
var ID = turnorder[i].id;
if (ID != -1) {
var tok = getObj("graphic",turnorder[i].id);
if (tok != undefined)
{
var character = getObj("character", tok.get("represents"));
if (character != undefined)
{
var CharName = character.get("name");
var Init = turnorder[i].pr;
const ThisChar = [CharName, Init];
state.StoredTurnOrder.push( [CharName, Init] ); // For each read in init, store it in the state
}
}
}
}
sendChat("","Turn order stored as "+String(state.StoredTurnOrder));
}
if(msg.type=="api" && msg.content.indexOf("!LoadTurnOrder")==0)
{
// for each selected token, see if they are in the stored info.
_.each(msg.selected,function(selectedItem) // for each selected item....
{
if (selectedItem._type == "graphic"){
var turnorder;
if(Campaign().get("turnorder") == "") turnorder = []; //NOTE: We check to make sure that the turnorder isn't just an empty string first. If it is treat it like an empty array.
else turnorder = JSON.parse(Campaign().get("turnorder"));
let FoundIt = 0;
var tok = getObj("graphic",selectedItem._id);
let character = getObj("character", tok.get("represents"));
if(character == undefined) // if its not a character, skip.
{
sendChat("","Not a character. Skipping....");
return;
}
let CharName = character.get("name");
for (let i = 0; i < state.StoredTurnOrder.length; i++)
{
if(state.StoredTurnOrder[i][0]==CharName) // we found a selected character in the stored turn order.
{
FoundIt = 1;
//Add them to the init using the character's stored init.
turnorder.push({
id: selectedItem._id,
pr: state.StoredTurnOrder[i][1],
custom: "",
_pageid: tok.get("pageid"),
});
var orderFinal = turnorder;
Campaign().set("turnorder", JSON.stringify(orderFinal));
}
}
if(FoundIt==0)
{
sendChat("","Could not find any info in the stored turn order for "+CharName+". Skipping adding to the turn order.");
}
}
})
}
});
});