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

[Script] Auto Initiative

Ok, I have updated this a lot. It has become much simpler to use, and then adds a functionality for multiple stats. Please see the changes above. Log: I added a selection functionality. If you place this into a macro on your macro bar, select the tokens you wish to be in initiative, and press the button, it will roll for all of them, add modifiers that are relevant and available, and sort them in order. Quick, easy, and smooth!
Additionally, I added an option for roll results to show in the chat log, at Michael's suggestion (above).
Why does the send chat message say it is divided by 20? Is the roll actually being divided? It looks like it says that but not actually trying to divide...
actually, that just my little addition with no formatting just a simple output to show that the rolls the were being executed correctly and what math goes into the initiative roll - the X/ 20 just means that it rolled an X  on a 20 sided die. i you change the dice rolled to say a d10, it would say X / 10 instead. its not a mathematical formula, just an output in my own little style.  
Josh said: Ok, I have updated this a lot. It has become much simpler to use, and then adds a functionality for multiple stats. Please see the changes above. Log: I added a selection functionality. If you place this into a macro on your macro bar, select the tokens you wish to be in initiative, and press the button, it will roll for all of them, add modifiers that are relevant and available, and sort them in order. Quick, easy, and smooth! Ever since that update. I've had huge variances in results showing up for certain characters. I've seen it roll for numbers up to 40+.(Which should be impossible for the character which only had a +4 for his Initiative +1d20) Yet, it was working correctly for the Rogue in our group (Unfortunately BECAUSE it was working for his character, he often came in last.)  I quadruple examined and confirmed it was set to roll a 20. The modifiers were being applicated correctly. However, as I said it specifically was saying characters were rolling 26+ on a d20.... <INSERT ZOMG FACE> 
This is cool.
ok in regards to Game Masters bug, I believe it is adding EACH set of modifiers to each consecutive roll, which leads to rather large numbers by the last characters rolls.  example: Fairilanios rolled a 4 (4)  - no mods, no problems WolfArcher rolled a 17 (12 + 5 Dexterity + 0 Initmod) - +5 mod, but 12+5 = 17, so no problem. Caster rolled a 9 (1 + 3 Dexterity + 0 Initmod)       1+3 = 4 - problem. It means it added the ^5^ from above. Mate rolled a 26 (15 + 3 Dexterity + 0 Initmod)      15+3=18, which is 8 over, which is the total added mods from the first three (0 + 5 + 3). next is going                                                                                 to be an 11 difference, just wait and see (0+5+3+3).  necro rolled a 30 (18 + 1 Dexterity + 0 Initmod)     18+1=19, which matches the same pattern but.... 30 - 19 = 11, which also equals 0+5+3+3   told ya Bitt rolled a 32 (14 + 2 Dexterity + 4 Initmod)        14+2+4=20, then add the other modifiers from above: 20+0+5+3+3+1=32
1375798638

Edited 1375799200
Ok, I figured out the problem. My modlist wasnt properly clearing itself, so it kept adding the previous mods (as Michael H suggested). I am fixing it now and then updating. EDIT: Updated.
sweet. it was 5 in the morning when I saw that. Knew you'd fix it quick, but before I woke up is awesome lol  :P 
1375840357

Edited 1375842027
also, might I suggest adding this little bit of code to the bottom? if (msg.type == "api" && msg.content.indexOf("!CombatEnds") !== -1) {         Campaign().set("turnorder", false );         Campaign().set("initiativepage", false );         if (MovementTracker.MovementTracker = true) { ResetAllPins() };     };     if (msg.type == "api" && msg.content.indexOf("!CombatSuspend") !== -1) {         var initTracker = "";         if (Campaign().get("initiativepage", Campaign().get("playerpageid") ) ) { Campaign().set("initiativepage", false ) }              else { Campaign().set("initiativepage", Campaign().get("playerpageid") ) };     }; and another bit at the top to automatically bring the turnorder list up when you start the script (I put it right after the !CombatBegins input line) Campaign().set("initiativepage", true ); (and another handy bit is to put Combat_Begins.Combat_Begins = true in your options list at the top while you're at it - its handy for when other scripts need to interact with yours..... example above being MovementTracker.MovementTracker = true, because I've modified that one to only be active when the turnorder is showing and the little addition to your script above allows for that. ) Edit: Urgh. Seems to be glitchy. works sometimes, other times not. Was working fine for the last version of your script, will keep working on it
Yea, I noticed a bunch of bugs last night. If certain tokens are selected it works and if others are, it doesn't. I haven't been able to isolate the problem to figure out what is causing it, but it started with the most recent update.
1375887031

Edited 1375889924
Weird, one encounter I had selected last night which would not work now just worked. Maybe they were working on the Dev server last night? Figures it would be during my live game EDIT: Nevermind, just started not working again with the same exact group... This is odd and suggests the selected tokens feature is still very unstable. EDIT2: Also, I added the suggestion of bringing up the initiative pane, but when it comes up it is blank. If I close it and reopen it, it is then filled. Its very odd, but until this is fixed by the Devs, I can't have it in my script as it's easier to open it yourself rather than close and open it.
Hey there, we are total beginners with API and trying to get this to work.  We've created the script, but can't figure out where to execute it.  Sorry, Any chance you'd be willing to help? :)
yea, I noticed that myself - thing is it works perfectly with your old script - i'm staying with that one for now. also wondering if its possible to have the select champ thing withy our new script allow new people to be included without wiping the turn order clean? Useful for those reinforcements. I haven't figured out how myself, but it should be possible, right?
Absolutely. Instead of creating a new one, pull the existing turn order, split it to an array, and add new ones, then push it back to turn order. I wonder if doing that would solve the problem... I am going to play around with it.
Ok, I updated it so that it tests if they are present and alters their score with the new roll. If you select someone not in the list, it rolls for them and adds them. I am going to do a new post but I discovered an API problem. I added a log(msg) before my script began, and 4 or 5 times I would press !CombatBegins or my macro button, and it would not post anything to the log, meaning something was catching it and not passing it to the API, my script never ran. I would not get an error, so this is something in the system that caused this problem. I've updated my script. If they fix what ever issue is happening in the API, it works great.
One suggestion, if it is possible, when you select tokens on the GM Layer and type !CombatBegins remove the message that shows up in the chat area. The other thing that might work better is add a new chat command !CombatBeginsGM or something so that the chat only shows to the GM and not the players.
Someone break this down for a noob.  where exactely does this scrip get coppied to?
Someone break this down for a noob.  I coppied the whole script from the first post into macro and clicked test macro. it sounded like the cops were comming to my house
From your Campaign detail, page you need to click API scripts, then enter a name and paste the script into the black text area below the name field.
1378947079

Edited 1378947129
Is this script working for everyone?  Was working fine over the weekend then suddenly stopped. Thanks
Sometimes it works correctly, other times it does not. It seems like the initiative pane is very unstable. When I add people to it, they wont show up unless you close the pane and open it again. Other times, my script runs through but nothing happens without any errors given (and scripts keep working). It does not make sense, but the API needs to be cleaned up around the initiative pane stuff. We posted it in the bugs section, but to my knowledge it has not been fixed yet.
I just copy pasted this script into my editor and when I went in game I saw nothing to turn it on to get it working.
have to type !CombatBegins to make it work - its all texted based commands right now, the easiest way is to make a macro yourself with that command.
I got it working!!!! I got the dex mods added on each sheet and also noticed I had to have all the tokens highlighted. but its working now. thank you! David
Hi, I'm working with my DM to try and add this script and I'm just wondering if it's possible to use the value of bar2 instead of using an attribute, we just thought this way might be easier so that we don't have to get a journal entry for each NPC. Thanks, Justin
This is a great tool Justin!
Still can't get this script working on my game - it crashes with this error message whenever I start combat with all the tokens involved selected.... TypeError: Cannot call method 'get' of undefined at evalmachine. :1717:21 at Array.forEach (native) at Function._.each._.forEach (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:78:11) at evalmachine. :1711:11 at eval ( lets me do one or two tokens at a time, but never the entire roster
Michael, mine just did the same thing... The error also makes no sense to me haha
I am redoing this entirely. This script has never been very stable. The entire API around initiative is very inconsistant, and with the rugged reroll coming out soon, I imagine it will change it a lot as well. Will post an update later today.
1383681683
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Yea!!!! I have wanted this script... but a bit more straight forward if you just want a single attribute to assign and a straight party vs bad guy roll.
to be honest, I still use the older version of the script, it works perfectly fine - no errors, ever. though this version has more useablility, i just tag stuff on the GM layer as not to be included in the init tracker, and have it drop any character that is under 0 HP when it rolls, and it works fine, which is why i'm not stressed about this. just thought that I would put it out there that this wasn't working, though I could not tell you why on my setup.
Currently, I just made a macro : @{selected|token_name} rolls a [[ 1d20 + @{selected|Dex} &{tracker} ]] for initiative! I go through the encounter group, highlight one creature from each of the groups (monster type), and click the macro in my macro bar. Its quick enough that it does not hurt. The players prefer to roll their init than having me to do it too. I will be fixing this, but its still giving me the same errors as I am updating it. Hope I can get past all of them.
1383705641
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Josh said: Currently, I just made a macro : @{selected|token_name} rolls a [[ 1d20 + @{selected|Dex} &{tracker} ]] for initiative! Now that is handy
Josh said: Currently, I just made a macro : @{selected|token_name} rolls a [[ 1d20 + @{selected|Dex} &{tracker} ]] for initiative! I go through the encounter group, highlight one creature from each of the groups (monster type), and click the macro in my macro bar. Its quick enough that it does not hurt. The players prefer to roll their init than having me to do it too. I will be fixing this, but its still giving me the same errors as I am updating it. Hope I can get past all of them. I do the same thing, I think this script was much more handy before the @{selected} and &{tracker} functions were added to macros. I use a /w gm though so my players don't see the roll (that way I can roll for hidden or otherwise out of sight monsters without them being revealed). Same type of thing.
this script is still an absolute time saver, adding all the relevant characters at the same time, which saves me minutes of setup time each fight. it adds up.
1384285642

Edited 1384285738
Hey all, I did an update here, changing a lot to make is more stable. There still exists a problem with the turn order pane, it does not update visually until you close it and open it (I tried to work this into my script but it does not work). Any tokens selected that are not controlled by players will now whisper their initiative to the GM instead of broadcasting to the players. In addition, you can opt out to ignore the players that are selected (my players like to roll for themselves). I attempted to use the new script I created, but for some reason when I send chat, it is ignoring the attributes of the characters. I can't figure out why it is doing this, however it prevents me from using the attribute (@(character|attribute}) with the API send chat command. In addition, the &{tracker} does not work when it comes from a sendChat function.
I recommend working the 'fix' into the macro for the updating problem. put in another command that simply shuts the init tracker down when typed in if its open, or opens it again once its closed. in my game its !CombatSuspend, so that you have a 'pause' button that closes the tracker (actually so I can use the movement tracker which is locked to th init tracker - if the tracker is visible, then only the person at the top of the init tracker can move their icon) Thing is, if you use it in your combat begins macro it will close and open the tracker every time you press the start button for combat. ie: !CombatBegins !CombatSuspend !CombatSuspend that rolls init, closes the init tracker, and then opens it back up. this is the code you need to add to the auto init here(thats what works in my game - even I don't know why it has 'var initTracker' anymore, I put this in 4 months ago: if (msg.type == "api" && msg.content.indexOf("!CombatSuspend") !== -1) { var initTracker = ""; if (Campaign().get("initiativepage", Campaign().get("playerpageid") ) ) { Campaign().set("initiativepage", false ) } else { Campaign().set("initiativepage", Campaign().get("playerpageid") ) }; };
I have that. At the beginning it closes the pane, and at the end it opens it. It doesnt solve the problem.
works on mine, all I'm saying. by putting it into the macro twice in my game, it closes the panel and then opens it back up. admittedly I still use your older version where it pulls all the tokens on the player layer, not this one, so maybe that's it.
Hi Josh, I can not understand why, but this macro does not work for me. I selected all the tokens on the map and then I type "!CombatBegins" but nothing happens. The initiative pop-up tells me that there are no tokens on the page! I have tried several times to re-install the macro, but it does not work ... you have any suggestions? Thank you.
Once the initiative opens up, close it and reopen it. There is an error in the API that the initiative pane does not refresh after a script runs and updates the list. IF you close it and open it, you force a refresh, and your tokens should appear. If that does not work let me know.
Thanks for the quick answer Josh, but I was already aware of this "trick" and everything worked until the last session, about a week ago. Instead yesterday I was preparing the new session and I accidentally did a test with "auto initiative" and no longer worked! :( As I said I already tried to reinstall the macro 3 times but does not go...
Hi Josh finally I have found a solution, but now I have a new problem ... when I launch the macro it makes all double rolls for the chosen tokens. In this way in the Turn Order I have all the names twice! What can I do?
Hey all, this is my first foray in the scripting world. Having one issue. A. I copy and pasted the Script into my API and the only think i changed was: Combat_Begins.statName = "Initiative"; //Stat to be added to roll B. I added an "Initiative" attribute to each character sheet, double checking spelling and capitalization. C. I created a simple global macro for that just inputs "!CombatBegins" into the chat log. D. It pulls all the characters, posts their roll into chat, and (besides having to close/re-open) looks solid, however i have not been able to get a roll over 20. no matter when i bump up their "Initiative" to 25 or another ridiculous number. What am i doing wrong? -Thanks!
Kenny, the number is not being added to the roll. It rolls 1d20 and adds initiative. If you have a 25 initiative then it should roll 26 to 45. Are you putting the value in the left or right box of character sheet?
Beppe63, are you clearing them out after each use of !CombatBegins? It should be over writing them if they are in the initiative order. Try clearing the initiative pane and then run the script as it describes. Does it add double then? If you have duplicate copies of tokens selected, then you will get two in the initiative pane.
1387219621

Edited 1389306993
Beppe63 said: Hi Josh finally I have found a solution, but now I have a new problem ... when I launch the macro it makes all double rolls for the chosen tokens. In this way in the Turn Order I have all the names twice! What can I do? I am having the same issue as Beppe. Did we ever find a solution to this? For an example I: 1) created a new page 2) added a single goblin token to the page 3) created the goblin character page, and linked it to the token 4) added a stat called "Dex" with value 2 to the goblin char page 5) select the token 6) Ensure that the initiative tracker has no current entries (by clearing it, even if empty). 7) enter !CombatBegins into the chat dialogue. 8) Two "Combat Begins!" dialogue prompts show up in the chat pane, and two goblin entries, each with separately rolled initiative values are added to the initiative pane. Clearly the script is running twice, but for what reason I can not say. Did you find an solution to this Beppe63 ? EDIT: FIXED! Thanks.
This is awesome. Does it support re-rolling initiative each round?