Advertisement Create a free account

[Script] Highlight Token at Top of Initiative

1383757701

Edited 1394895821
Sky
Pro
The new an improved INITIATIVE TOOL! The script, in addition to highlighting the token at the top of the turn order, gives players a command to end their turn. It currently allows anyone to advance the turn order... but I will be adding a check soon, so that only players who are in control of the token at the top of the order can end the turn. I should be able to get that done late tonight or tomorrow afternoon. The command to end your turn is simply !eot in the chat window or as a macro. // VARIABLE & FUNCTION DECLARATION var TurnOrderAgent = TurnOrderAgent || {}; // AnnounceNewRound - Set to TRUE if you want the script to announce // the beginning of each new round. var AnnounceNewRound = true; on("chat:message", function(msg) { // Exit if not an api command if (msg.type != "api") return; // Get the API Chat Command msg.who = msg.who.replace(" (GM)", ""); msg.content = msg.content.replace("(GM) ", ""); var command = msg.content.split(" ", 1); if (command == "!eot") { if (!Campaign().get('turnorder')) return; // Exit if the turn order tracker is not open var turn_order = JSON.parse(Campaign().get('turnorder')); // Parse the turn order information into JSON if (!turn_order.length) return; // Exit if there are no tokens on the tracker var turn = turn_order.shift(); // Grab the info for the top of initiative turn_order.push({ // Add the info to the bottom of initiative id: turn.id, pr: turn.pr, custom: turn.custom }); Campaign().set("turnorder", JSON.stringify(turn_order)); // Send the turn order back to the tracker TurnOrderAgent(); } }); on("change:campaign:turnorder", function(obj) { TurnOrderAgent(); }); function TurnOrderAgent () { if (!Campaign().get("turnorder")) return; var turn_order = JSON.parse(Campaign().get("turnorder")); if (!turn_order.length) return; if (typeof turn_order[0].pr == "string") { if (turn_order[0].pr.substring(0, 5) == "Round") { var RoundTracker = turn_order[0].pr; var CurrentRound = parseInt(RoundTracker.substring(5)); turn_order[0].pr = "Round " + (CurrentRound + 1); Campaign().set({turnorder: JSON.stringify(turn_order)}); if(AnnounceNewRound == true) { sendChat("", "/desc "); sendChat("", "/direct &lt;div style='width: 100%; color: #C8DE84; border: 1px solid #91bd09; background-color: #749a02; box-shadow: 0 0 15px #91bd09; display: block; text-align: center; font-size: 20px; padding: 5px 0; margin-bottom: 0.25em; font-family: Garamond;'&gt;" + turn_order[0].pr + "&lt;/div&gt;"); } } } // Exit script if custom item on turn order tracker instead of a token... if (turn_order[0].id == -1) 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); }; Add this script to your API tabs, drop the linked token: <a href="http://the-adventure-game.wdfiles.com/local--files/introduction/Initiative%20Highlight.png" rel="nofollow">http://the-adventure-game.wdfiles.com/local--files/introduction/Initiative%20Highlight.png</a> into your map, and name it InitiativeHighlight exactly. This script will move the bright lime green highlighter token to the same location of the token at the top of the turn order and then use the API function toFront() to move that token to the front, so it is above the green token. This form of highlighting really only works with top down tokens or round portrait tokens. Square tokens that fill the entire grid will not be highlighted. In use:
1383759872
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Like it... It will move to tokens hidden on the GM layer if they are in the turn order.
1383760006

Edited 1383760085
Sky
Pro
Hrm, it prolly will. I didn't ever test that. Going to try now. edit - Hah yeah it does... I will have to decide if I want to move the token to a different layer or just hide it out of the way or leave it where it was.
1383760446
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
I like it a lot... don't get me wrong. I just noticed it as I was trying it (had a token on the GM layer and in the turn order just by chance.) Personally I would like it to do that.... it keeps in consistent or the GM.
1383760613

Edited 1383760780
Sky
Pro
Ok, I added a line and now, it will move the highlight token to the same layer as the token at the top of the turn order. Except now the token appears where the gm layer token was and then moves. Gah. Guess I need to make it a little more complex and text which layer it is and change it in a specific order.
1383761736
May I ask, why go with a highlight token when you could use the Tint or Aura setting for the token? With the new reroll coming, the party will be able to split across pages and you'd need to identify a highlight token on the correct page while simultaneously hiding any others.
1383761908
Sky
Pro
Welp, that didn't work either. I can't think of a solution that allows GM's to use this script without revealing that there are tokens in the gmlayer and in the turn order due to the way it all works.
1383761958

Edited 1383762730
Sky
Pro
Because people use auras for other things and the token itself is much more visible. And the turn order only works on the page it was created on.
1383764523

Edited 1383765000
Sky
Pro
Oh wow.... just tested this and on two different pages with one highlight token on each page... it does work. I didn't have to change anything in the script. It will automatically move the right highlight token on the right page, but all the turn order tracker is global, meaning it is across all pages. So while you can split the party, you can't split the turn order tracker. I also still cannot figure out how to make it so that GM Layer tokens are ignored and not revealed....
1383801127
Brian
Sheet Author
API Scripter
if(currect_token.get('layer') == 'gmlayer') initiative_highlighter.set({ top: -35, left: -35, width: 70, height: 70 }); else ...
1383828771

Edited 1383829189
Sky
Pro
That doesn't work either. I tried a great number of ways... but without a reliable delay command, I can't make any of them work.
1383872538

Edited 1383872606
Brian
Sheet Author
API Scripter
Well, I realize I misspelled "current_token," but what to you mean it doesn't work? I'm simply suggesting you remove the highlighter token from the visible map. If you just want a delay, JavaScript can do that: setTimeout(function() { initiative_highlighter.set(...); }, 50); // set values on i_h in 50 milliseconds Set the initiative_highlighter's layer outside the setTimeout function, and its position inside.
1383917197
Sky
Pro
Oh, I thought that timeout function didn't work
1383917298
Sky
Pro
And I don't want to remove the highlight token from the map. I want it to shift smoothly between layers to highlight to token at the top of initiative without revealing where GM tokens are. The problem was that everything I tried... would reveal a GM token when the token animation for the token moving from one spot to another played. Nothing I tried prevented that animation from playing right away and revealing the spot where the GM token was at the start of their turn.
1383917567
Sky
Pro
Woot! setTimeout does work!! Now I just need to figure out a formula to determine how fast the token animation plays so that it only reappears beneath the target token after it has reached that token if they happen to be really far apart.
1383917682

Edited 1383917704
Sky
Pro
After testing, it appears that the token animation is set to play at a little under 1 second. Meaning I can safely set my timeout to 1200 ms.
1383918254

Edited 1383918281
Sky
Pro
Script is done! I see nothing else I can do to improve it. It is as perfect as it can be for what I want it to do I think. :)
1383918265
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
knee toe
1385672888

Edited 1385673136
Samuel T.
Sheet Author
HoneyBadger said: Here's a video of this script in action: <a href="https://plus.google.com/109659591453191902524/posts/9hxNC7SDXAt" rel="nofollow">https://plus.google.com/109659591453191902524/posts/9hxNC7SDXAt</a> Your link returns an error for me. HoneyBadger , why do you do this to me? Your script makes me want to become a Mentor, my wallet will hate me. Are you sure you want to be the cause of the gulf between my wallet and I? :)
1385675651
Sky
Pro
Sorry about that. I deleted the earlier post and reposted the correct link. <a href="https://plus.google.com/109659591453191902524/posts/WvJYCE52n57" rel="nofollow">https://plus.google.com/109659591453191902524/posts/WvJYCE52n57</a>
1387733271

Edited 1388858170
Sky
Pro
Here's a combined script that highlights the token at the top of the initiative and looks for a token with an initiative value of "Round X" and then increments that X value by one. on("change:campaign:turnorder", function(obj, prev) { // AnnounceNewRound - Set to TRUE if you want the script to announce // the beginning of each new round. var AnnounceNewRound = false; 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].pr == "string") { if (turn_order[0].pr.substring(0, 5) == "Round") { var RoundTracker = turn_order[0].pr; var CurrentRound = parseInt(RoundTracker.substring(5)); turn_order[0].pr = "Round " + (CurrentRound + 1); Campaign().set({turnorder: JSON.stringify(turn_order)}); if(AnnounceNewRound == true) { sendChat("", "/desc ---- " + turn_order[0].pr + " ----"); } } } 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); });
1388155806

Edited 1388156757
nm got it workin
I love the script! I runs well for me but my problem is with my tokens. About 90% of them are filled in like this: I cannot see the highlight under the token. Without modifying my library, do you have any quick suggestions? I am a graphics noob. I currently work with &lt;cough&gt; MS Paint &lt;cough&gt; to modify maps, etc. What would be the easiest way to eliminate the background?
1389459347
Sky
Pro
John G. said: I love the script! I runs well for me but my problem is with my tokens. About 90% of them are filled in like this: I cannot see the highlight under the token. Without modifying my library, do you have any quick suggestions? I am a graphics noob. I currently work with &lt;cough&gt; MS Paint &lt;cough&gt; to modify maps, etc. What would be the easiest way to eliminate the background? <a href="http://www.sumopaint.com/app" rel="nofollow">www.sumopaint.com/app</a>
1389459471
Sky
Pro
The other option would be to utilize the green dot status marker as a highlight. At least until we get some kind of solid border option. I've requested to be able to set a border around tokens, but it hasn't seen any traction yet. :(
Hi HoneyBadger , I'm so stupid that I dont understand the command line to put in chat to run your API...
1389621677
Sky
Pro
You don't... you just add the script, add the token, name the token InitiativeHighlighter and it should work.
Thanks HoneyBadger as I said I'm stupid!! ;)
hey honey badger im trying to use your duel script and Ive done all you guys have talked about and i cant seem to get the round counter part of it to work help and thank u for all the help in the past and any that might come in the future your the shit
1393401822
Konrad J.
Pro
API Scripter
John G. said: I love the script! I runs well for me but my problem is with my tokens. About 90% of them are filled in like this: I cannot see the highlight under the token. Without modifying my library, do you have any quick suggestions? I am a graphics noob. I currently work with &lt;cough&gt; MS Paint &lt;cough&gt; to modify maps, etc. What would be the easiest way to eliminate the background? Are you saving these as jpgs? You need to save as png if you want to have a transparent background. If its the black background you are trying to get rid of easily then a graphics program other than paint should be able to select just the black for you and then cut it out. Then save as a png. But with that black background and the white halo around the image it leads me to believe you have already cutout the figure and then saved it as a jpg so you are getting a black background? Point me in the direction of the original figure you got this from and I'll show you whats possible
1393411585
Sky
Pro
Shaun Bradley (Elmo) said: hey honey badger im trying to use your duel script and Ive done all you guys have talked about and i cant seem to get the round counter part of it to work help and thank u for all the help in the past and any that might come in the future your the shit Post a screenshot of your setup or invite me to the campaign and promote me to GM. That way I can see what you're doing.
1393641608

Edited 1393642143
Great Script and thanks for sharing, been having a play about with it and got it working
1393668767

Edited 1394790554
Sky
Pro
Cool. Glad you like it. :) @Celestian - There is a bug I recently found. I will post a fix later today.
I'm trying to use your 2nd listed script. Added the script to the API (enabled the round announcement). Included the "InitiativeHighlighter" token. Added 3 tokens to the turn order box, rolled init, used the advancement arrow on the turn order box, green token slides around, no round counter increment or announcement ;(. Script log doesn't show any errors. Any thoughts? I see you asked for a SS above for someone else with the same problem, what do you want a SS of?
1394780182
Isembard
Pro
Sheet Author
Have you got a round counter token set up? Script is working ok for me. I have a token of a D6, add it to turn tracker and manually add it's initiative as Round 0. I then get the round count and announcement. HoneyBadger said: Here's a combined script that highlights the token at the top of the initiative and looks for a token with an initiative value of "Round X" and then increments that X value by one
1394820434
Sky
Pro
@Celestian - You have to add a token and give it the initiative value of Round 0 to get the round tracker/announcement. I'll post an updated version of the script with some CSS styling on the round announcement later this weekend.
1394895897
Sky
Pro
The initiative highlighter script has been improved slightly... ... you can now end your turn simply by typing !eot into the chat window or creating a macro with that command. ... the script also has an option to announce each new round in chat with a green box. Look for a future update that will let you change the color!
1397589394
Isembard
Pro
Sheet Author
Hi. I can get the round highlighter to work perfectly with the green identifier moving as required and the round counter as well. I can not get the !eot command to work though. I had a player log on and nothing happened, no error or message. Could someone confirm I am doing this right? Thank You