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

SimpleInitiative 1.0 - A lightweight turn order tracker...

March 10 (8 years ago)

Edited July 15 (7 years ago)
To Do:
  • Add logic to check for control of a token instead of character sheet when using !eot. If a token is not representing a character sheet but is controlled by a player, they will not be allowed to end that tokens turn.
  • Add user configuration options for what status icon to use to mark initiative. It is currently hard coded to the green dot.
July 15th, 2017 ~ 7:20 am eastern
June 22nd, 2017 ~ 8:30 pm eastern
  • Version: 1.2.1
  • Update: Tokens on the GM Layer will no longer have their names announced in chat when their turn comes up.
  • Update: Added an option to hide all npc names and replace them with NPC in chat.
June 18th, 2017 ~ 12:10 am eastern
  • Version: 1.2.0
  • Update: Added a new command !roll-init which uses the D&D 5e OGL character sheet attributes (dexterity, initmod, and jack_of_all_trades). Using this command will roll initiative for all selected tokens and add them to the turn order tracker or update initiative for a token already on the turn order tracker. If the token does not represent a character sheet, it will roll an unmodified 1d20 instead.
April 26th, 2017 ~ 7:30 am eastern
  • Version: 1.1.0
  • Bugfix: Players can no longer end the turn of someone else. A player can only use !eot if they have control of the character at the top of the turn order tracker.
  • Bugfix: The script would crash if multiple players had control over the same character. This is because the script was trying to find a player color for the chat announcement and couldn't find what it was looking for. The script will now default to the player color of the first player that is in the controlled by field of the character sheet.
  • Un-Fix: Removed listener for GroupInitiative script. It wasn't working anyway. Will work on getting it fixed at some point.
March 12th, 2017 ~ 4:00 pm eastern
  • Version: 1.0.4
  • Bugfix: Added listener for GroupInitiative script per TheAaron. Fixes a persistent green dot issue until the turn order has cycled past the first token added to the turn order tracker and auto sort is turned on in GroupInit.
March 12th, 2017 ~ 8:15 am eastern
  • Version: 1.0.3
  • Bugfix: Fixed logic to determine if a character sheet represents a PC or NPC.
March 10th, 2017 ~ 12:45 am eastern
  • Version: 1.0.2
  • Update: Added additional logic to show NPC in the chat announcement if the player's would not be able to see the token's name. Best used with the green dot turned on so you can see which npc whose turn it is.
March 10th, 2017 ~ 12:30 am eastern
  • Version: 1.0.1
  • Bugfix: Added logic to show NPC if the token does not have a name set. Without a name, the chat announcement box was messed up. Upon reading this, I will be looking at adding a way to not show NPC names in chat if players can't see the name normally.
March 9th, 2017 ~ 10:00 pm eastern
  • Version: 1.0.0
  • Initial Release: Please report any bugs you come across. Thanks!
Simple Initiative
This script is a lightweight turn order tracker that adds a green dot to the token at the top of the turn order, announces their turn in chat, and provides an option for players to end their turn and advance the turn order tracker to the next token. The GM also has a command to clear the initiative and close the tracker automatically.

To Do
  • Do the math for turn order calculations when the !eot command is used. This feature of Roll20 currently does not work when using the command instead of clicking the arrow on the tracker.
  • Add option to hide NPC token names in chat announcements if players cannot see the token name.
  • Add option to desginate which icon to use instead of the green dot.
Commands
  • !eot - Available to players and GM's alike, this command will advance the turn order one please. Players can only use this command if a token they control is at the top of the turn order.
  • !clear-init - A GM only command, this clears the turn order tracker, removes the green dot, and closes the tracker.
  • !sort-init - A GM only command to sort the tracker in descending order.
  • !roll-init - A GM only command to roll initiative for all selected tokens using the D&D 5e OGL Character Sheet attributes (dexterity, initmod, jack_of_all_trades). If a token does not represent a character sheet, it will roll an unmodified 1d20 for initiative instead.
Variables
  • SHOW_GREEN_DOT
    • Set to true to add a green dot to the token at the top of the turn order.
  • ANNOUNCE_NEW_TURN
    • Set to true to send an announcement to chat.
  • PC_COLOR
    • Use a six digit hex color code and this will show in chat when a token controlled by a player is announced.
  • NPC_COLOR
    • This is the default color all chat announcements will use if no other color is specified.
  • PLAYER_COLOR
    • Set to true to use the player color next to their name, beneath their avatar. This requires the token to be controlled by or represent a character controlled by that player.
  • HIDE_NPC_NAMES
    • Set to true to hide all npc token names in chat.
March 10 (8 years ago)
March 10th, 2017 ~ 12:45 am eastern
March 10th, 2017 ~ 12:30 am eastern
  • Version: 1.0.1
  • Bugfix: Added logic to show NPC if the token does not have a name set. Without a name, the chat announcement box was messed up. Upon reading this, I will be looking at adding a way to not show NPC names in chat if players can't see the name normally.
My monsters are showing "PC" instead of "NPC".  In the chat.  I'm also getting this error, maybe the two are connected:

  "Error: No attribute or sheet field found for character_id -Kd_uK7_ny1etxVkrnmr named npc"
"Error: No attribute or sheet field found for character_id -Kd_uK7_ny1etxVkrnmr named npc"
"Error: No attribute or sheet field found for character_id -Kcq2etd7rbX_S7Evl9e named npc"
"Error: No attribute or sheet field found for character_id -Kcq6KYWwjHFUTglcd8n named npc"
"Error: No attribute or sheet field found for character_id -Kd_uK7_ny1etxVkrnmr named npc"
"Error: No attribute or sheet field found for character_id -Kcq2etd7rbX_S7Evl9e named npc"
"Error: No attribute or sheet field found for character_id -Kcq6KYWwjHFUTglcd8n named npc"

I'm using the 5e Shaped Sheet with it's companion script as well, if that has any bearing on anything.
March 12 (8 years ago)

Edited March 12 (8 years ago)
The script is written for the OGL 5e Sheet. I have no desire nor care to support the shaped sheet. However, if it can't find that attribute, it should pop up as NPC. I will look into that bug.
March 12 (8 years ago)

Edited March 12 (8 years ago)
Ah, I thought getAttrByName returned -1 if it couldn't find an attribute on a character sheet and instead returns undefined. Will have a bugfix up for it shortly.
Another thing - I'm using the Group Initiative script (one-click install), PCs roll from their sheets, and I roll monsters with the script.  For now, I'm just testing with 1 PC and two monsters.  So, I roll the PC from the sheet, and he gets a dot (because he's the only one in the turn order).  Then, I roll the other two monsters using Group Initiative, and sort.  Then, if a monster has a higher number, it goes to the top (and gets a green dot), but then the green dot also stays on the first PC who rolled.  After one time through the turn order, it all gets sorted, but it would be nice to not have to do that.

Anyway, just testing my own usage case, and that's the results I'm getting.
March 12 (8 years ago)
March 12th, 2017 ~ 8:15 am eastern

SkyCaptainXIII said:

The script is written for the OGL 5e Sheet. I have no desire nor care to support the shaped sheet. However, if it can't find that attribute, it should pop up as NPC. I will look into that bug.

Fair enough.

March 12 (8 years ago)

Edited March 12 (8 years ago)

Gozer the Gozerian said:

Another thing - I'm using the Group Initiative script (one-click install), PCs roll from their sheets, and I roll monsters with the script.  For now, I'm just testing with 1 PC and two monsters.  So, I roll the PC from the sheet, and he gets a dot (because he's the only one in the turn order).  Then, I roll the other two monsters using Group Initiative, and sort.  Then, if a monster has a higher number, it goes to the top (and gets a green dot), but then the green dot also stays on the first PC who rolled.  After one time through the turn order, it all gets sorted, but it would be nice to not have to do that.

Anyway, just testing my own usage case, and that's the results I'm getting.

Shouldn't doing that. As soon as the initiative is sorted, it should remove the green dot from whichever token had it previously and then adding the green token to the new token at the top of the turn order, but then again, you are using a script I haven't used... so I dunno. How are you sorting the turn order? If it's through a script, that does not trigger a turn order change I believe.
No, I'm sorting by using the turn order window, and sorting manually.  Sorry I can't be of more help. 

March 12 (8 years ago)

Gozer the Gozerian said:

No, I'm sorting by using the turn order window, and sorting manually.  Sorry I can't be of more help. 

Has to be a conflict with the way GroupInitiative is adding the other tokens to the turn order. Without using GroupInitiative, my script will properly hide and show the green dot on the correct tokens.
Got it.  Thanks for looking into in, anyway.
March 12 (8 years ago)

Gozer the Gozerian said:

Got it.  Thanks for looking into in, anyway.
Turn off auto-sort in group-initiative and it appears to fix the persistent green dot issue on my end.

March 12 (8 years ago)
The Aaron
Pro
API Scripter
It's because there is no event when the API changes the TurnOrder.  If you want to support it, GroupInitiative sends an event when it changes the turn order for any reason.  Here's what your code change would be:

var HandleTurnOrderChange = function(obj, prev) {
    var current = JSON.parse(obj.get("turnorder"));
    var previous = JSON.parse(prev["turnorder"]);
    if (obj.get("turnorder") && !obj.get("initiativepage")) Campaign().set("initiativepage", true);
    if (current.length == 0 && previous[0].id != -1 && SHOW_GREEN_DOT) getObj("graphic", previous[0].id).set("status_green", false);
    if (previous.length > 0 && previous[0].id != -1 && SHOW_GREEN_DOT) getObj("graphic", previous[0].id).set("status_green", false);
    if (current.length > 0 && current[0].id != -1 && SHOW_GREEN_DOT) getObj("graphic", current[0].id).set("status_green", true);
    if (ANNOUNCE_NEW_TURN) AnnounceNewTurn(current, previous);
}

on("change:campaign:turnorder", HandleTurnOrderChange );

if('undefined' !== typeof GroupInitiative && GroupInitiative.ObserveTurnOrderChange){
	GroupInitiative.ObserveTurnOrderChange(HandleTurnOrderChange);
}

March 12 (8 years ago)

Edited March 12 (8 years ago)
Implemented this change and will be posting it to the gist soon. It just feels weird sticking an if statement outside of on("change or chat... 
March 12 (8 years ago)

Edited March 12 (8 years ago)
March 12th, 2017 ~ 4:00 pm eastern
March 13 (8 years ago)
Actually that didn't fix anything. I thought I had turned sorting back on when I tested it, but apparently I did not. Just tried out GroupInitiative again and the green dot issue persists even with TheAaron's changes.
March 13 (8 years ago)
The Aaron
Pro
API Scripter
hmm... 

Oh, I see the issue.  I'm sending out the current and previous turnorder, not campaign.
var HandleTurnOrderChange = function(obj, prev) {
    var current = JSON.parse(obj.get("turnorder"));
    var previous = JSON.parse(prev["turnorder"]);
    if (obj.get("turnorder") && !obj.get("initiativepage")) Campaign().set("initiativepage", true);
    if (current.length == 0 && previous[0].id != -1 && SHOW_GREEN_DOT) getObj("graphic", previous[0].id).set("status_green", false);
    if (previous.length > 0 && previous[0].id != -1 && SHOW_GREEN_DOT) getObj("graphic", previous[0].id).set("status_green", false);
    if (current.length > 0 && current[0].id != -1 && SHOW_GREEN_DOT) getObj("graphic", current[0].id).set("status_green", true);
    if (ANNOUNCE_NEW_TURN) AnnounceNewTurn(current, previous);
}

on("change:campaign:turnorder", HandleTurnOrderChange );

if('undefined' !== typeof GroupInitiative && GroupInitiative.ObserveTurnOrderChange){
	GroupInitiative.ObserveTurnOrderChange(function(obj,prev){
		HandleTurnOrderChange(Campaign(),{turnorder:prev});
	});
}
This should adapt to what you need.
March 13 (8 years ago)
Didn't fix it... getting errors now, seemed to happen when I cleared the turn order.

TypeError: subs[x].apply is not a function
March 13 (8 years ago)
The Aaron
Pro
API Scripter
Any more callstack than that?
March 13 (8 years ago)
The Aaron
Pro
API Scripter
Try using:
    var current = JSON.parse(obj.get("turnorder"))||[];
    var previous = JSON.parse(prev["turnorder"])||[];
March 13 (8 years ago)
That works! I'm sure there's some other edge cases where it crashes. Thanks. :)
March 13 (8 years ago)

Edited March 13 (8 years ago)
Found that edge case... this happens when I clear the turn order manually instead of using a script to do so. I don't use subs or .apply in anything in my script. And the only .apply in your script is for finding initiative modifiers. So I'm not sure what I'm doing wrong.

TypeError: subs[x].apply is not a function
    at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:146:34), <anonymous>:65:16)
    at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:146:34), <anonymous>:70:8)
    at TrackedObj.set (/home/node/d20-api-server/api.js:901:14)
    at updateLocalCache (/home/node/d20-api-server/api.js:1194:18)
    at /home/node/d20-api-server/api.js:1484:7
    at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560
    at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147)
    at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
    at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489)
    at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425)
March 13 (8 years ago)
Weird... changing it to this got rid of that crash:

on("change:campaign:turnorder", function (obj, prev) {
    HandleTurnOrderChange(obj, prev);
});
March 13 (8 years ago)

Edited March 14 (8 years ago)
And that green dot problem is still there, argh. I'm done messing with that problem for a little bit. Trying to take all my scripts and re-write them to be cleaner and less spread out. Consolidating a lot of the commands into a DM Toolkit for D&D 5e script so I don't have to bounce all over the place looking for something.
March 14 (8 years ago)
The Aaron
Pro
API Scripter
I know the feeling...  =D
March 24 (8 years ago)
Anyone using this and having issues? I haven't really had a chance to test it out yet other than on my own and would like to get some feedback from anyone that is using it. Thanks!
April 20 (7 years ago)
Found a bug... fixed it. Will post the update soon. The script was letting anyone end anyone's turn instead of just if it was actually their turn.
April 26 (7 years ago)
Oh, I never posted the fix... which incidentally, also included a bug that I need to fix before I post the update. The "fixed" script crashes if more than one player controls a character. 
April 26 (7 years ago)

Edited April 26 (7 years ago)
April 26th, 2017 ~ 7:30 am eastern
  • Version: 1.1.0
  • Link: https://gist.github.com/Sky-Captain-13/d6acd51388507c8b10b2931950100992
  • Bugfix: Players can no longer end the turn of someone else. A player can only use !eot if they have control of the character at the top of the turn order tracker.
  • Bugfix: The script would crash if multiple players had control over the same character. This is because the script was trying to find a player color for the chat announcement and couldn't find what it was looking for. The script will now default to the player color of the first player that is in the controlled by field of the character sheet.
  • Un-Fix: Removed listener for GroupInitiative script. It wasn't working anyway. Will work on getting it fixed at some point.
  • To Do 1: Add logic to check for control of a token instead of character sheet when using !eot. If a token is not representing a character sheet but is controlled by a player, they will currently not be allowed to end that tokens turn. Realized this while putting in the fix for the above !eot issue.
  • To Do 2: Add user configuration options for what status icon to use to mark initiative. It is currently hard coded to the green dot.
June 13 (7 years ago)

Edited June 13 (7 years ago)

Gozer the Gozerian said:

SkyCaptainXIII said:

The script is written for the OGL 5e Sheet. I have no desire nor care to support the shaped sheet. However, if it can't find that attribute, it should pop up as NPC. I will look into that bug.

Fair enough.


Hey Gozer!, if you want to use this script with the 5e Shaped Character sheet, you can change the attribute "npc" for "is_npc". "is_npc" is used in 5e Shaped sheet to distinguish between Characters and NPC/Monsters.
if (Character != "" && getAttrByName(Character.id, "is_npc") != undefined && getAttrByName(Character.id, "is_npc") != 1) {
I hope this help you using this amazing, and simple script :)
June 18 (7 years ago)

Edited June 23 (7 years ago)
June 18th, 2017 ~ 12:10 am eastern
  • Version: 1.2.0
  • Link: https://gist.github.com/Sky-Captain-13/d6acd51388507c8b10b2931950100992
  • Update: Added a new command !roll-init which uses the D&D 5e OGL character sheet attributes (dexterity, initmod, and jack_of_all_trades). Using this command will roll initiative for all selected tokens and add them to the turn order tracker or update initiative for a token already on the turn order tracker. If the token does not represent a character sheet, it will roll an unmodified 1d20 instead.
June 23 (7 years ago)

Edited June 23 (7 years ago)
June 22nd, 2017 ~ 8:30 pm eastern
  • Version: 1.2.1
  • Link: https://gist.github.com/Sky-Captain-13/d6acd51388507c8b10b2931950100992
  • Update: Tokens on the GM Layer will no longer have their names announced in chat when their turn comes up.
  • Update: Added an option to hide all npc names and replace them with NPC in chat.
  • To Do:
    • Add logic to check for control of a token instead of character sheet when using !eot. If a token is not representing a character sheet but is controlled by a player, they will not be allowed to end that tokens turn.
    • Add user configuration options for what status icon to use to mark initiative. It is currently hard coded to the green dot.
June 23 (7 years ago)
Also, fyi, this script will crash if you delete a token off the map while it is on the turn order. I have put in a bug report because the token is removed from the turn order tracker but not the campaign object that stores the turn order information.
Does anyone happen to have gotten the player names to display properly with the shaped sheets? I can get them to display when also showing NPC names, but when show npc names is set to false, it automatically displays 'PC' for all PC's.
July 05 (7 years ago)
That's because the shaped sheet doesn't use the same npc variable that the OGL sheet uses for some stupid ass reason. 
July 06 (7 years ago)

Edited July 06 (7 years ago)
Kryx
Pro
Sheet Author
API Scripter

Sky said:

That's because the shaped sheet doesn't use the same npc variable that the OGL sheet uses for some stupid ass reason. 
The Shaped sheet tried to keep variables named consistently with the community sheet as that was the popular sheet at the time. "is_npc" is the name the name that the community sheet used so the Shaped sheet kept it for consistency. OGL, which was created after, did not make any effort for consistent variable names.

========

@Arne you can probably search through the script and replace "npc" with "is_npc"
July 06 (7 years ago)
Not my problem you didn't adapt to the OGL Sheet. Now shoo.
July 15 (7 years ago)
July 15th, 2017 ~ 7:20 am eastern
Loving the spirit of collaboration here ;-)
I understand you're not supporting the shaped sheet yourself Sky, which is why I didn't ask you directly.

@Kryx Yep, I figured that one out, but that wasn't the cause of the issue. It was either showing names for both players and NPC's, or for neither, I wanted it to show player names regardless of whether showing NPC names was enabled or disabled.

I did manage to change it, so if anyone wants the same thing I did, let me know.
July 15 (7 years ago)
The most recent update should fix that.