Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Round Tracker (Honey Badgers)

I've added the round tracker which works pretty well. Something I can't figure out is why the Round number increments if I just add another token into the table during play. For instance if other combatants joined later. Anyone got experience with this? The thread is shut down now.
1411576001
The Aaron
Roll20 Production Team
API Scripter
I believe that will happen when the round marker is at the top of the initiative order and you add a turn. That script looks at the turn order whenever it changes. If it is the turn of the round marker, it increments the round number. This is a logical way to handle it, as it would normally change only when the turn has changed. However, when you add someone, you are changing the turn order data, without changing the actual order and the logic for the round marker having a turn takes effect. The practical upshot being, if you add turns when it isn't the round marker's turn, you should be fine.
1411580934

Edited 1411581404
Paul S.
Sheet Author
API Scripter
I've been working on improving this script (or trying). The improvement I'm trying to make - but can't figure out - is changing it so that the Announce Round doesn't trigger for the addInit entries in the turn tracker. I can do it by turning off the counter on the addInit entries. But then they don't get tracked... a 1/2 step backwards. I TRIED to do it by having the initiative number (.pr) increment (or decrement in this case) instead of having an incrementing variable on the effectName (.custom). This DOES add the entry and STARTS to work - but it freezes (stops incrementing) both the .pr of the addInit item and the .custom of the Round Tracker. So - I'm not done beating my head against the wall on this - but anyone that actually knows Java ... I'd appreciate the assist. My idea is having the command be "!addEffect EffectName [# of Rounds]" and then decrement the .pr on each (change:campaign:turnorder).... Thoughts? Here's the script I've got so far that I have been trying to plug into the Honey Badger init tracker script in place of the addInit portion: on("chat:message", function(msg) { var args, text=''; if(msg.type != "api") { return; } args = msg.content.split(" "); switch(args[0]) { case '!addEffect': if(args.length > 1) { var effect effect="__"+args[1]; var turn_order; if(Campaign().get("turnorder") == "") turn_order = []; //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 turn_order = JSON.parse(Campaign().get("turnorder")); //log (turn_order); var effectName = effect args[2] = (parseInt(args[2])-1); var firstElem = []; firstElem = turn_order.shift(); turnOrder.unshift( { id : "-1", pr : args[2], custom : effectName }); turn_order.unshift(firstElem); var orderFinal = turn_order; Campaign().set("turnorder", JSON.stringify(orderFinal)); return; } } } );
1411583209
The Aaron
Roll20 Production Team
API Scripter
@Paul -- are you sure you're talking about the same script? I don't see addInit in the linked script.
1411586260
Paul S.
Sheet Author
API Scripter
Hmmm. Actually different. Let me link the code since I can't find it in the forum.
1411612348
Paul S.
Sheet Author
API Scripter
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); } );
Yeah... that is not mine, lol... and the round tracker incrementing whenever a token is added is something I kept meaning to work on, but I get bored with scripting and it takes a few months or more before something gets me back into it.
1411655334
Paul S.
Sheet Author
API Scripter
Yeah - I don't know why I thought it was yours HB. I am just learning scripting (teaching myself) but among other things going on it is low on the priority list. I've almost got this sorted ... I'm probably just missing something really obvious.