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] GroupInitiative -- Calculate the Initiative for all selected tokens [New Thread]

1430683376

Edited 1455065708
The Aaron
Pro
API Scripter
Update v0.9.16 &nbsp;-- Added --clear to remove all turns from the turn order. &nbsp;If Auto Open Init is enabled, it will also close the turn order window. (Thanks Lucian H. !) Update v0.9.15 -- Fixed bug with --reroll causing custom entries to be dropped off the Turn Order. (Thanks Three of Swords !) Update v0.9.14 &nbsp;-- Fixed bug with --reroll not working if Replace Roll was off. &nbsp;(Thanks Three of Swords !) Update v0.9.13 &nbsp;-- Fixed bug where having 10+ enemies could result in the wrong bonus being applied. (Thanks Jurph !) Update v0.9.12 -- Split the rolls for initiative across multiple sendChat() calls. &nbsp;This fixes a problem with complex rolls overloading the API dice roller. (Thanks Kevin!) Update v0.9.11 &nbsp;-- Fixed bug when the dice count attribute has been set with an API script (integer instead of string). &nbsp;(Thanks Dylan S.!) Update v0.9.10 &nbsp;-- Fixed some bugs with certain attribute values. (Thanks Kevin!) Update v0.9.9 &nbsp;-- Added --reroll to reroll all the tokens in the Turn Order as if they had all be selected. &nbsp;(Thanks Three of Swords!) Update v0.9.8 &nbsp;-- Fixed crash bug when a character doesn't have an attribute for a rule. (Thanks Ken L and Three of Swords) Update v0.9.7 &nbsp;-- Added Observable Pattern notifications (Taken advantage of by Bump v0.2.4 and higher). &nbsp;Other scripts can register to observe when GroupInitiative makes changes to the turn order. &nbsp;Sample code (from Bump): &nbsp; &nbsp; &nbsp; &nbsp; if('undefined' !== typeof GroupInitiative && GroupInitiative.ObserveTurnOrderChange){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GroupInitiative.ObserveTurnOrderChange(handleTurnOrderChange); &nbsp; &nbsp; &nbsp; &nbsp; } Registered functions currently don't receive any parameters (I'm working on a generalized solution but this is my test case.). Update v0.9.6 -- Fixed bug with default installed state for fresh script use (Thanks Joseph l.!) Update v0.9.5 -- Allow players to execute !group-init and also access the --bonus argument. Update v0.9.4 -- Fixed crash bug with Stat-DnD (Thanks Greg!) Update v0.9.3 -- Fixed crash bug with missing attributes. (Thanks Kevin!) Update v0.9.2 -- Fixed a crash bug with empty bonus groups. (Thanks Greg and Gozer!) Update v0.9.1 -- Fixed a crash bug that had to do with Dice Count Attributes. (Thanks Vince!) Update v0.9.0 -- This is a pretty massive change, so there may be some bugs (that Vince hasn't already found... =D ). First off, GroupInitiative is now using the dice engine to calculate rolls. This opens up the use of formula stats among other things. I had to remove the Bounded Stat adjustment, but I don't think anyone used that anyway. There are also a bunch of new configuration options in the help: For systems that use multiple dice for initiative, you can use the Initiative Dice Count to set the number of initiative dice to roll. For ShadowRun, you can now set an attribute to be used to determine the number of dice to roll. Look for Dice Count Attribute in the settings. This can be a simple formula, but it is a bit flakey so just be aware that it may crash your API. Once Nested Inline Rolls hit the API, it will be come more stable. Characters without that attribute (or where that attribute is a 0) will use the Initiative Die Count to determine the number of dice to roll. You can now use attributes that have formulas in them as part of your Bonus Stat Groups Update: v0.8.9 - Added --Tie-Breaker option which adds an attribute *0.01 as a tie breaker. !group-init --add-group --Tie-Breaker dexterity Update v0.8.8 - Fixed the 3+6.06 = 9.05999999999999999 problem. =D (Thanks Ziechael!) Update v0.8.7 - Added four Announcers to show the results of GroupInitiative None -- Doesn't announce anything Hidden -- Announces all rolls via whisper to the gm(s) Partial -- Announces rolls for PCs to all, but whispers NPCs to the gm(s) (PCs are any character with either All, or at least one non-gm as a controller) Visible -- Announces everything to everyone With the caveat that tokens on the GM layer are always whispered. PCs have a Greenish background, NPCs have a bluish background, GMLayer items have a darker grayish background. Standard Dice highlighting applies and hover shows you the die roll and the total bonus applied. Update v0.8.5 - Fixed parsing of bonuses to allow floating point numbers. Update v0.8.4 - Added Auto Sorting (Ascending,Descending, or None), Setting the Die Size to roll, and Popping up the TurnOrder on Group Init roll. Update v0.8.3 - Fixed the regular expression for detecting bonuses to support decimals. Update v0.8.2 - Support for decimal bonuses. Update v0.8.1 - Removed dependency on isGM, added --bonus to add a number to the rolls: !group-init --bonus 5 Inline rolls are fine too (but note that the same bonus is applied to all selected in that case): !group-init --bonus [[1d4]] Update v0.6 - Minor Bugfix to handling of second tier attributes. (Thanks Naz!) Update v0.41 - Minor fix. HTML Special characters were getting subsisted for their values and breaking the Javascript. I've changed how they are generated to get rid of the "Unexpected identifier" error. (Thanks al e!) Update v0.4 - Minor fix. A UTF-8 character had slipped into one of the strings. It shouldn't have caused any issues, but just in case, I've pulled it out in v0.4. Update v0.3 - This version is so different, it's practically a full rewrite.See Below! Overview: This script adds a command for rapidly adding large groups of tokens into the turn order. As of v0.3, there are quite a few configuration commands (see Commands below). The basic process followed by the script is this: Remove any tokens that already have a turn. For all selected tokens, find the character they represent. For each character, figure out the initiative bonus. Initiative bonuses are calculated using Bonus Stat Groups . Each Bonus Stat Group is a collection of Attribute Names and Stat Adjustment operations to apply to them. Bonus Stat Groups are evaluated in order. The first one that produces a bonus is used. If a character doesn't have one of the Attribute Names listed in the Bonus Stat Group (or that Attribute Name does not contain a valid number), that group does not produce a bonus. The selected Roller is used to generate the rolls for each token, with the bonus for its character applied (or 0 if it doesn't have a character). Add each token to the turn order. Commands: !group-init This is the root api command. If you have any tokens selected, it will add them to the initiative order. If you don't have anything selected, it will show the help. !group-init --help This shows the help, which includes state information about the currently selected Roller , available Stat Adjustment Options , and the ordered list of Bonus Stat Groups . !group-init --add-group --&lt;adjustment&gt; [--&lt;adjustment&gt;] &lt;attribute name[|&lt;max|current&gt;]&gt; ... This command adds another Bonus Stat Group to the end of the list. Examples and further explanation below. !group-init --del-group &lt;number&gt; Removes the Bonus Stat Group identified by number. !group-init --promote &lt;number&gt; Moves the Bonus Stat Group identified by number up one slot. !group-init --set-roller &lt;roller name&gt; Sets the Roller to use for figuring initiative. Rollers: There are currently 4 different Rollers: Least-All-Roll -- Roll 1d20+Bonus for every token, then take the lowest number as the initiative for all tokens. (Bryan K.) Mean-All-Roll -- Roll 1d20+Bonus for every token, then take the average (rounded down) roll as the initiative for all tokens. Individual-Roll -- Roll 1d20+Bonus for each token and set each token's initiative to whatever it rolled. (James the DM, GenKitty, etc) Constant-By-Stat -- Set the initiative to whatever the Bonus for that token is. (Michael H.) Add-Group Detailed Explanation: The --add-group command creates a new Bonus Stat Group . It takes one or more attribute specifications. An attribute specification is made up of one or more Stat Adjustment Options , followed by an Attribute Name (optionally with |max on the end). Stat Adjustment Options Bare -- Use this when you want just the attributes value. This will add a Bonus Stat Group with just the attribute dexterity in it. !group-init --add-group --Bare dexterity Floor -- Use this to compute the floor of the value. This is useful when you have attributes that are decimal values, but you want a whole integer. Ceiling -- The same as Floor, but returns the next highest whole integer. The Bonus Stat Group added by this command would turn the attribute skill bonus from 2.35 to 3: !group-init --add-group --Ceiling skill bonus Bounded:&lt;low&gt;:&lt;high&gt; -- Use this to restrict the value of an attribute to a particular range. This would specify a Bonus Stat Group where dexterity can only be between -2 and +2: !group-init --add-group --Bounded:-2:2 dexterity To leave a value unrestricted, you can leave the bound for that side empty. This would specify a Bonus Stat Group where dexterity has a maximum value of +4, but can be as low as it wants: !group-init --add-group --Bounded::4 dexterity Stat-DnD -- Use this to convert an attribute from a Dungeons and Dragons Stat into the Stat's associated bonus. 18 becomes 4, 7 becomes -2, etc. This would specify a Bonus Stat Group which finds the stat bonus for the dexterity stat: !group-init --add-group --Stat-DnD dexterity Advanced Examples You can chain multiple Stat Adjustment Options together. This would specify a Bonus Stat Group where dexterity is first converted to a Dungeons and Dragons stat bonus, and then is bounded to a maximum of +2: !group-init --add-group --Bounded::2 --Stat-DnD dexterity Stat Adjustment Options always operate on the value to the right. In the example above, Bounded would be applied to whatever is returned from Stat-DnD. You can also chain multiple attribute specifications together. The Bonus is calculated by adding the results of each together. This would create a Bonus Stat Group that is the sum of the dexterity and initiative stats: !group-init --add-group --Bare dexterity --Bare initiative A more complicated example. This would specify a Bonus Stat Group which consists of the sum of the Dungeons and Dragons stat bonus computed for the max field of dexterity , the Dungeons and Dragons stat bonus computed from the max field of wisdom limited to a maximum of +2, and the current value of initiative . !group-init --add-group --Stat-DnD dexterity|max --Bounded::2 --Stat-DnD wisdom|max --Bare initiative Computing the Bonus When the Bonus is computed for a character, the Bonus Stat Groups are considered in order. The first Bonus Stat Group to produce a number is used. When a Bonus Stat Group is evaluated, it will produce a number as long as every referenced attribute is present and numeric on the character. Example. Assume you have the following 3 stat groups: dexterity |current + initiative |current + rage |current dexterity |current + initiative |current dexterity |current If a character has attributes named both dexterity and initiative , but doesn't have one named rage , the first Bonus Stat Group would not produce a number. In that case, the second Bonus Stat Group would produce a number, which would then be used as the Bonus. Hopefully that will be enough documentation that people can use this! If you have any issues, just let me know! Git: <a href="https://github.com/shdwjk/Roll20API/blob/master/GroupInitiative/GroupInitiative.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/GroupInitiative/GroupInitiative.js</a> Support my work on If you use my scripts, want to contribute, and have the spare bucks to do so , go right ahead. However, please don't feel like you must contribute just to use them! I'd much rather have happy Roll20 users armed with my scripts than people not using them out of some sense of shame. Use them and be happy, completely guilt-free! Disclaimer: This Patreon campaign is not affiliated with Roll20; as such, contributions are voluntary and Roll20 cannot provide support or refunds for contributions.
1430684630

Edited 1430686853
vÍnce
Pro
Sheet Author
Sweet! I beat GenKitty to the thread... Thanks Aaron now let's see if I can make a query for the bonus... Nice !group-init --bonus ?{Modifier?|0}
1430687671

Edited 1430687886
vÍnce
Pro
Sheet Author
[Request] Is it possible to allow decimals within the -- bonus &lt;foo&gt; Use case. I like adding (+ (0.01 * @{selected|init})) to my PF initiative macro rolls as a tie-breaker. [[((1d20 + @{selected|init}) + ?{Modifier?|0} + (0.01 * @{selected|init})) &{tracker}]] So I wanted to do the same with groupinitiative (using Individual-Roll, Bare and the attribute init) !group-init --bonus [[ ?{Modifier?|0} + (0.01 * @{selected|init}) ]] but I get the error message "Not a valid bonus: 0.01"
Yay, group-init any chance of adding the sorting to it as well? similar to the init-assist script you wrote for me?
1430697488
The Aaron
Pro
API Scripter
Good idea! Done! =D
1430697519
The Aaron
Pro
API Scripter
possibly.. =D
:) just a thought, thought others may find it useful as well.
1430698170
The Aaron
Pro
API Scripter
Yeah. I think I'm going to make a complete rewrite of GroupInitiative. I'd like to support some things that are not easy with the way it works now.
1430700116
Gen Kitty
Forum Champion
Yay. I'll point my GM at this! (And of course Vince beat me to the thread, I was out seeing Age of Ultron!)
1430700148
vÍnce
Pro
Sheet Author
Hey Aaron, you should consider a political party and run for president. You're adimantine!
1430700333
vÍnce
Pro
Sheet Author
GenKitty said: Yay. I'll point my GM at this! (And of course Vince beat me to the thread, I was out seeing Age of Ultron!) I guess you had a proper excuse. :-)
1430702907
The Aaron
Pro
API Scripter
Vince said: Hey Aaron, you should consider a political party and run for president. You're adimantine! Ha! You know politics has nothing to do with "fixing" things, right? =D
1430703599
vÍnce
Pro
Sheet Author
Thanks for adding decimal support. Works great!
1430703879
The Aaron
Pro
API Scripter
Great! =D And you're welcome!
1430956631
Gen Kitty
Forum Champion
I'm really really sick tonight and can't computer very well. I need step by step instructions to give to my GM to set this up. It'll be Individual rolls, with no stat, using a macro such as: !group-init --bonus ?{Modifier?|0} Aaron, help?
1430957802
The Aaron
Pro
API Scripter
So, you mean 1d20+bonus? 1) get rid of the default entry: !group-init --del-group 1 2) [OPTIONAL] enable replacing the initiative of selected tokens. Leave this off if you don't want to update any selected token that already has a turn: !group-init --toggle-replace 3) Playing the game. Here's a command to run the init prompting for the bonus: !group-init --bonus ?{Bonus?|0} Or if you know the bonus or it's just fixed always: !group-init --bonus 42 Hope you get to feeling better!!!!
1430960419
Gen Kitty
Forum Champion
Thanks. Passed to GM. (viral gastroenteritis isn't much fun)
1430969630
vÍnce
Pro
Sheet Author
GenKitty said: Thanks. Passed to GM. (viral gastroenteritis isn't much fun) Get well soon.
1430970553
The Aaron
Pro
API Scripter
oh noes!!! that is soooo adorable...
Can this script be adjusted to use a different die (such as a d6)?
1431003991
The Aaron
Pro
API Scripter
Yes. It's not built in currently, but it could be. Do you need that?
Yes, and I'm thinking of incorporating your Turn Marker script as well - PMd you on that one, because I didn't see an active thread for it.
The Aaron said: oh noes!!! that is soooo adorable... Right, its like scary cute. Feel better GenKitty.
1431180667
vÍnce
Pro
Sheet Author
Aaron, would you consider adding code that would open the tracker window when groupinitiative is fired? Not sure if it's possible, but I can't imagine anyone that uses initiative and doesn't need to see the tracker window. Or a separate script if it's a pain to modify groupinitiative. Thanks
+1 to that.
1431187006
The Aaron
Pro
API Scripter
Should be easy enough.
If I wanted to have this script roll a d6 instead of a d20, would I just replace this: return randomInteger(20)+d; with this: return randomInteger(6)+d; wherever it occurs? Or am I oversimplifying? :)
1431191135
The Aaron
Pro
API Scripter
That should work. I'll add a config for that...
Could it also be done with an exploding d10? (Initiative for Cyberpunk 2020) That seems like it would be at least a little bit more complicated.
1431193794
The Aaron
Pro
API Scripter
That would take some rewriting. It would need to use a dice expression at that point, which would require an asynchronous handling of initiative... doable, but a sizable chagne.
Yeah, that's not that important, but I'd really like the d6. Can we access repeatable fields as a bonus? On the 1e character sheet, the weapons are on there as repeatable tables, and weapon speed factor is an attribute.
1431195406
The Aaron
Pro
API Scripter
Good question. =D You should be able to, but repeating fields have been known to be problematic in the past.
1431202413
vÍnce
Pro
Sheet Author
I think the repeatable attribute should work, unless it's an auto-calculated field/attribute.
1431206095
The Aaron
Pro
API Scripter
Update v0.8.4 - Added Auto Sorting (Ascending,Descending, or None), Setting the Die Size to roll, and Popping up the TurnOrder on Group Init roll.
The Aaron said: Update v0.8.4 - Added Auto Sorting (Ascending,Descending, or None), Setting the Die Size to roll, and Popping up the TurnOrder on Group Init roll. You sir are a god among men :)
1431221731
vÍnce
Pro
Sheet Author
Aaron, you will have something in your stocking come X-mas. :-)
1431222334

Edited 1431222416
vÍnce
Pro
Sheet Author
Just did a quick test. I'm getting an error with the same macro that was working with v8.0.3 Not a valid bonus: 0.01 macro !group-init --bonus [[ (0.01 * @{selected|init}) ]] !startInit !power {{ --name|Initiative has been sorted...^^"Let's Get it On!" }} If I remove the --bonus portion of the macro it works fine.
1431223254
The Aaron
Pro
API Scripter
This falls into the category of "things that couldn't possibly have worked before." It's fixed now. =D
1431223309
The Aaron
Pro
API Scripter
Update v0.8.5 - Fixed parsing of bonuses to allow floating point numbers.
1431223635
vÍnce
Pro
Sheet Author
=-P
1431223668
vÍnce
Pro
Sheet Author
Thank You! Now go play some music or hug ytour kids and wife.
1431224446
The Aaron
Pro
API Scripter
hahahaha. Yup, gonna go watch an Anime on Netflix with the wife. =D
The Aaron said: Good question. =D You should be able to, but repeating fields have been known to be problematic in the past. Yes, it seems that I'm not able to use the repeating field for weapons from the AD&D 1e character sheet. I've tried to do an "add-group" to add bonuses, and I was successful in getting the attribute "SurpriseBonus" on there, but not "selected|repeating_weapon_0_WeaponSpeed." One thing to note - "SurpriseBonus" actually shows up as an attribute on the Attributes and Abilities tab, while "selected|repeating_weapon_0_WeaponSpeed" does not. Perhaps this is the cause of the problem?
1431281653
The Aaron
Pro
API Scripter
yeah, that's the problem for sure. I'll see if I can come up with a solution... =/
1431287928

Edited 1431288181
vÍnce
Pro
Sheet Author
Hey Gozer. This macro seems to work for me on the 1e sheet !group-init --bonus [[ @{selected|SurpriseBonus} + @{selected|repeating_weapon_0_WeaponSpeed} ]]
1431288152
vÍnce
Pro
Sheet Author
Any way to get an output to chat Aaron? 3d dice no longer work with API rolls, but an inline rolls output to chat would still be nice as a way to see what was rolled and the bonuses that were applied. Too bad tipsy didn't work over the tracker items.
Oh cool - I didn't realize we could use macros like that for bonuses, I'll have to try that. EDIT: I pasted that in the chat window, and got: "You attempted to use a roll command looking for the value of a selected token, but no tokens are selected."
Vince said: Any way to get an output to chat Aaron? 3d dice no longer work with API rolls, but an inline rolls output to chat would still be nice as a way to see what was rolled and the bonuses that were applied. Too bad tipsy didn't work over the tracker items. +1 on this, nice way to confirm the bonuses are appliances correctlly. I could see a gm whisper being wanted for gm layer tokens.
1431292916
The Aaron
Pro
API Scripter
Gozer the Gozerian said: Oh cool - I didn't realize we could use macros like that for bonuses, I'll have to try that. EDIT: I pasted that in the chat window, and got: "You attempted to use a roll command looking for the value of a selected token, but no tokens are selected." That's because the @{selected|...} needs something to be selected. It would be the same if you just typed @{selected|bar1} or similar instead of an api command.
1431292934
The Aaron
Pro
API Scripter
Vince said: Any way to get an output to chat Aaron? 3d dice no longer work with API rolls, but an inline rolls output to chat would still be nice as a way to see what was rolled and the bonuses that were applied. Too bad tipsy didn't work over the tracker items. So, what information would you want to see in that output?