Ok - finally got back to my computer - Here's the tracker I've been using (thought it was HB's). /*
Scripts to help manage the iniative, round tracker and effects over time
!clearInit : justy clears the Initiative Tracker
!startInit : sorts the Iniative Tracker and adds the round tracker ebtry
!addInit EffectName : adds a new effect to the Iniative Tracker below the current node
NOTE do not use : in any character names or effect names. This will confuse the tracker
which uses : as a separator between names and rounds
*/
on("chat:message", function(msg)
{
if(msg.type == "api" && msg.content.indexOf("!clearInit") != -1)
{
var turnorder = [];
Campaign().set("turnorder", JSON.stringify(turnorder));
}
}
);
function sortJSON(data, key, way) {
return data.sort(function(a, b) {
var x = a[key]; var y = b[key];
if (way === '123' ) { return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
if (way === '321') { return ((x > y) ? -1 : ((x < y) ? 1 : 0)); }
});
}
on("chat:message", function(msg)
{
if(msg.type == "api" && msg.content.indexOf("!startInit") != -1)
{
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"));
//log (turnorder);
var turnOrderSorted = [];
turnOrderSorted = sortJSON(turnorder,'pr', '321');
//Add a new custom entry to the end of the turn order.
turnOrderSorted.push( {
id : "-1",
pr : "--",
custom : "Round : 1"
});
var orderFinal = turnOrderSorted;
Campaign().set("turnorder", JSON.stringify(orderFinal));
}
}
);
on("chat:message", function(msg)
{
if(msg.type == "api" && msg.content.indexOf("!addInit") != -1)
{
var effect = msg.content;
effect = effect.replace("!addInit ","");
effect = "____"+effect+" : ";
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"));
var effectName = effect +" 0"
var firstElem = [];
firstElem = turnOrder.shift();
turnOrder.unshift( {
id : "-1",
pr : "--",
custom : effectName
});
turnOrder.unshift(firstElem);
var orderFinal = turnOrder;
Campaign().set("turnorder", JSON.stringify(orderFinal));
}
}
);
on("change:campaign:turnorder", function(obj, prev) {
if (!Campaign().get("turnorder")) return;
var turn_order = JSON.parse(Campaign().get("turnorder"));
if (!turn_order.length) return;
if (!turn_order[0].id == -1) return;
if (typeof turn_order[0].custom == "string") {
if ( (turn_order[0].custom.substring(0, 5) == "Round") || (turn_order[0].custom.substring(0, 4) == "____") ){
var l = turn_order[0].custom.length;
var p = turn_order[0].custom.indexOf(":");
var name = turn_order[0].custom.substring(0,p);
var round = turn_order[0].custom.substring(p+1,l);
round = (parseInt(round) + 1);
turn_order[0].custom = name + ": " + round;
Campaign().set({turnorder: JSON.stringify(turn_order)});
sendChat("", "/desc ---- ROUND " + round + " FIGHT! ----");
return;
}
}
var current_token = getObj("graphic", turn_order[0].id);
var initiative_highlighter = findObjs({name: "InitiativeHighlight", pageid: current_token.get("pageid")}, {caseInsensitive: true})[0];
if (initiative_highlighter == undefined) {
sendChat("ERROR", "/w gm Cannot find an initiative highlight token on this page.");
return;
}
if (initiative_highlighter.get("layer") == "gmlayer" && current_token.get("layer") != "gmlayer") {
initiative_highlighter.set({
"top": current_token.get("top"),
"left": current_token.get("left"),
"height": current_token.get("height"),
"width": current_token.get("width")
});
setTimeout(function() {
initiative_highlighter.set({
"layer": current_token.get("layer")
});
}, 500);
} else {
initiative_highlighter.set({
"layer": current_token.get("layer"),
"top": current_token.get("top"),
"left": current_token.get("left"),
"height": current_token.get("height"),
"width": current_token.get("width")
});
}
toFront(current_token);
}
);