
Hi all, I'm having trouble updating my groups turn order API to the new Turn Order API changes. We've used it for years and really hope we can get it working again. It was originally a slimmed down abomination version of Fabio M. 's Hero system Turn Order API . Does anyone have an updated Hero System initiative or know how to update the below code to work with new turn order API? var iii = 1; //var iTurn = iTurn || {}; //var whisper = "/w "; var whisper = ""; var iTurn; var combatBegun = combatBegun || {}; var aChars = new Array(); var aSPDchart = new Array(); var aBleedingTable = new Array(); var tempTurnOrder = new Array(); var needle; var Pins; var pinExists; var MasterID = "-J5R2trPC6jWXlClBuAL"; aSPDchart = ['','12','6,12','4,8,12','3,6,9,12','3,5,8,10,12','2,4,6,8,10,12','2,4,6,7,9,11,12','2,3,5,6,8,9,11,12','2,3,4,6,7,8,10,11,12','2,3,4,5,6,8,9,10,11,12','2,3,4,5,6,7,8,9,10,11,12','1,2,3,4,5,6,7,8,9,10,11,12']; function addTokens() { if(Campaign().get("turnorder") == "") { turnorder = []; } else turnorder = JSON.parse(Campaign().get("turnorder")); var phase = iii; var delayedChars = new Array(); tempTurnOrder = turnorder; turnorder.length = 0; needle = ""; var currSPD = 0; for(var a=0;a<tempTurnOrder.length;a++) // Check for any delayed phase characters { if(tempTurnOrder[a].pr == "d" || tempTurnOrder[a].pr == "D") { delayedChars[delayedChars.length] = tempTurnOrder[a].id; } } Campaign().set("turnorder", JSON.stringify(turnorder)); if(phase<3) {needle = phase+",";} else {needle = phase;} turnorder.push({ id: "-1", pr: " ", custom: "TURN " + iTurn + " - Phase " + phase }); for(var a = 0;a < delayedChars.length;a++) { turnorder.push({ id: delayedChars[a], pr: "D", custom: "" }); } for (var a = 0; a < aChars.length; a++) { // cycles through the characters to see if they act during this phase currSPD = aChars[a][1]; var phases = aSPDchart[currSPD]; var pos = phases.indexOf(needle); if(pos>-1) { turnorder.push({ id: aChars[a][0], pr: aChars[a][2], custom: "" }); } } Campaign().set("turnorder", JSON.stringify(turnorder)); delayedChars.length = 0; } function removeToken(IDsString, tokensArray) { var newChars = new Array(); for (var a = 0; a < aChars.length; a++) { if(IDsString.indexOf(aChars[a][0])==-1) newChars.push(aChars[a]); } aChars.length = 0; aChars = newChars; } on('chat:message', function(msg) { var command = msg.content.toLowerCase(); if (msg.type == "api" && (command == "!combatstart" || command == "!nextphase" || command == "!combatadd")) { if(command == "!combatstart" || command == "!combatadd") { Campaign().set('turnorder','[]'); var selected = msg.selected; var addCount = 0; if(command == "!combatstart") { cambatBegun = true; iii = 12; iTurn = 0; phase = 12; var nCount = 0; } if(command == "!combatadd") { if(!combatBegun) { sendChat("Script", "/w GM Start a combat first (with the '!combatstart' command)."); return; } var nCount = aChars.length; } _.each(selected, function(obj) { if(obj._type != 'graphic') return; //if(token.get('_id')==undefined) //{ //sendChat("script", "/w gm Tokens not set up."); //return; //} var token = getObj("graphic", obj._id); var oCharacter = getObj("character", token.get("represents")); if (oCharacter != "" ) { // gets SPD, DEX from character's sheet and put them into the array together with tokenen's ID var currTop = token.get("top"); var currLeft = token.get("left"); aChars[nCount] = new Array(4); aChars[nCount][0] = token.get('_id'); var oSPD = findObjs({name: "SPD",_type: "attribute", _characterid: oCharacter.id}, {caseInsensitive: true})[0]; if (oSPD != "" ){aChars[nCount][1] = parseInt(oSPD.get('current'));} else{sendChat("GM", "No SPD attribute for character " + token.get('name')); return;} var oDEX = findObjs({name: "DEX",_type: "attribute", _characterid: oCharacter.id}, {caseInsensitive: true})[0]; if (oDEX != "" ) aChars[nCount][2] = parseInt(oDEX.get('current')); aChars[nCount][3] = currLeft + "," + currTop; aChars[nCount][4] = new Array(); nCount++; addCount++; } }); if(nCount==0) { sendChat("script", "/w gm Select some tokens first!"); return; } if(command == "!combatadd") sendChat("Script", "/w GM added " + addCount + " token(s)."); aChars = aChars.sort(function(a,b) { // sorts characters by SPD and then DEX if (a[2] < b[2]) return 1; if (a[2] > b[2]) return -1; if (a[1] < b[1]) return 1; if (a[1] > b[1]) return -1; return 0; }); if(aChars.length>0 && command == "!combatstart") {sendChat("GM", "/desc Combat begins!");} else if(aChars.length==0) {sendChat("Script", "/w GM No tokens selected!");} } var currSPD = 0; var needle = ""; if(Campaign().get("turnorder") == "") { turnorder = []; } else turnorder = JSON.parse(Campaign().get("turnorder")); if (msg.type == "api" && command == "!nextphase" && combatBegun) { turnorder.length = 0; Campaign().set("turnorder", JSON.stringify(turnorder)); iii++; if(iii>12) {iii=1;} if(iii==1) {iTurn++; sendChat("GM", "New Turn!");} } nextPhase(iii); function nextPhase(phase){ if(aChars.length>0){ var header = true; do{ if(phase<3) {needle = phase+",";} else {needle = phase;} for (var a = 0; a < aChars.length; a++) { // cycles through the characters to see if they act during this phase currSPD = aChars[a][1]; var phases = aSPDchart[currSPD]; var pos = phases.indexOf(needle); if(pos>-1){ if(header){ sendChat("GM", "Phase " + phase + " begins!"); turnorder.push({ id: "-1", pr: " ", custom: "TURN " + iTurn + " - Phase " + phase }); header = false; } turnorder.push({ id: aChars[a][0], pr: aChars[a][2], custom: "" }); } } if(header){ phase++; if(phase>12) {phase=1;} if(phase==1) {iTurn++; sendChat("GM", "New Turn!");} iii = phase; } } while (header) } Campaign().set("turnorder", JSON.stringify(turnorder)); } } else if (msg.type == "api" && command == "!combatend"){ if(aChars.length>0) { turnorder.length = 0; Campaign().set("turnorder", JSON.stringify(turnorder)); sendChat("GM", "/desc Combat ends."); aChars.length = 0; } } else if (msg.type == "api" && command == "!combatremove"){ var idlist = ""; var removeList = new Array; var counter = 0; var selected = msg.selected; _.each(selected, function(obj) { if(obj._type != 'graphic') return; idlist += obj._id + ","; removeList[counter] = new Array(1); removeList[counter][0] = obj._id; counter++; }); removeToken(idlist, removeList); addTokens(); sendChat("Script", "/w GM removed " + counter + " token(s)."); } });