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 Update] GroupInitiative - Now with Dice Modifiers for the initial roll!

November 17 (5 years ago)

Edited May 12 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

GroupInitiative

Update v0.9.34 -- Added an option to preserve the first token turn when auto-sorting the turn order on token add. (Thanks andrea d.)

You can set it in the help menu or toggle it with:

!group-init-config --toggle-preserve-first

Update v0.9.33 -- Fixed token_bar, token_bar_max and token_aura options to work when tokens don't represent a character.  Additionally, I've updated GroupInitiative to create a Help: GroupInitiative handout the same way TokenMod and some of my other scripts are.  By default, it is only viewable by the GM.  To support that, I overhauled the help quite a bit.

I've finally removed Dexterity as the default Bonus Stat Group and replaced it with a system that prompts you if you don't have something configured yet:


If you have a standard configuration for a released character sheet, let me know what it is and I'll get it added into the list.


Update v0.9.32 -- Fixed token_bar, token_bar_max and token_aura options (Thanks Lockbox313)

Update v0.9.31 -- Added support for passing token_ids using the --ids argument (Thanks Victor B. )

You can now pass an ID (if you are the GM or the API) using the --ids argument:

!group-init --ids @{target|token_id}

Additionally, I've added an external interface for scripts to request that tokens get rolled based on an array of token_ids:

GroupInitiative.RollForTokenIDs( <Array of IDs> [, Options ] );

  • <Array of IDs> is an array containing Token IDs
  • Options is an optional object with various properties set.  Currently, the only supported property is:
    • manualBonus -- a floating point number which is applied as if supplied to the --bonus argument.

Here's a sample script using it:

/* global GroupInitiative */
on('ready', ()=>{
	const handleTurnOrderChange = (/* obj */ /*, prev */ ) => {
		sendChat('',`/w gm Turnorder Changed!`);
	};

	let giRoll = () => sendChat('',`/w gm <code>GroupInitiative.RollForTokenIDs()</code> is not supported.`);

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

	if('undefined' !== typeof GroupInitiative && GroupInitiative.RollForTokenIDs){
		giRoll = GroupInitiative.RollForTokenIDs;
	}

	on('chat:message', (msg) => {
		if('api' === msg.type && /!test-gir/i.test(msg.content)){
			let cmds = msg.content.split(/\s+/);
			
			giRoll(
				(msg.selected||[]).map(s=>s._id),
				{
					manualBonus: cmds[1]||0
				}
			);
		}
	});


});

Update v0.9.30 -- Added Dice Modifiers (Thanks The Scout)


You can use this setting to append any number of things to the dice roll for initiative.  Exploding, rerolls, minimums, etc.  Pretty much anything that can go directly after the number of sides on the die.  There isn't any error checking on what you put in here currently, so play nice!

Update v0.9.28 -- Added --toggle-turnorder command which just opens and closes the turnorder. (Thanks Cutter )

Update v0.9.27 -- Added logic to attempt to fix inline rolls that will crash the API. (Thanks Dougansf )
Update v0.9.26 -- Fixed bug where 0 was sorted strangely. (Thanks Maetco)
Update v0.9.25 -- Fixed bug causing '(stat || "").replace is not a function' error. (Thanks eastwood)
Update v0.9.24 -- Adjusted bonus calculation to deal with @{selected} and &{tracker} references (Thanks Thorsten B.)
Update v0.9.23 -- Add current and previous objects to the Notification. (Thanks Lucian)
Update v0.9.22 -- Added better handling for empty stats, hoping to fix empty character sheet attributes at creation time.  (Thanks Nibrodooh )
Update v0.9.21 -- Case Sensitivity, sorting improvements and the Initiative Stack System.

For full commands, see then previous threads or the in-game help.

New & Updated Commands

  • --add-group --<adjustment> ... -- All adjustments are now case-insensitive. You can use --bare, --Bare -- BaRe, etc.  Added an adjustment type of --negative which applies the inverse of the value of an attribute.
  • --sort -- Applies the configured sort method to the current list.
  • --clear -- Removes all entries from the turn order.
  • --adjust-current <value> [minimum] -- Adjusts the current turn by somevalue, with an optional minimum value.
  • --stack [stack command] -- This is a big addition to GroupInitiative.  The stack commands let you store the state of the initiative and restore it at a later point.  Here's a list of the possible stack commands:
    • list -- List all of the stored turn orders. This is the default command if you don't supply one.
    • clear -- Clear all the stored turn orders.
    • copy [label] -- Copy the current turn order to the stack.  Anything after the command will be used for naming it in the stack.  You can also use the dup instead of copy.
    • push [label] -- Puts a copy of the current turn order on the stack and clears the turn order.   Anything after the command will be used for naming it in the stack.
    • pop -- Replaces the current turn order with the last entry in the stack, removing it from the stack.
    • apply -- Replaces the current turn order with the last entry in the stack, but leaving a copy in the stack.
    • swap [label] -- Swaps the current turn order with the last entry in the stack.  Anything after the command will be used for naming it in the stack.
    • tail-swap [label] -- Swaps the current turn order with the first entry in the stack.   Anything after the command will be used for naming it in the stack.  You can also use tswap instead of tail-swap.
    • merge -- Removes the last entry in the stack and adds it to the current turn order, then sorts the new turn order with the configured sort method.
    • apply-merge -- Just like merge, but leaves the stack unchanged.
    • rotate [label] -- Pushes the current turn order onto the end of the stack, then removes the first entry in the stack and replaces the turn order with it.   Anything after the command will be used for naming it in the stack.  You can also use rot instead of rotate.
    • reverse-rotate [label] -- Just like rotate, but puts the current turn order on the front of the stack and pulls off the end of the stack.   Anything after the command will be used for naming it in the stack.  You can also use rrot instead of reverse-rotate.


Examples

The stack stuff is very powerful, but not as polished as I would like (I actually released it tonight by accident, but there ya go!).

Save a copy of the Turn Order:

!group-init --stack dup Backup Turn Order at round 5



List the saved turn orders:

!group-init --stack



Restore the saved copy:

!group-init --stack pop



Saving again, but this time clearing the turn order by pushing:

!group-init --stack push Saving again



Now with sort descending set (was sort ascending when I pushed), 

I'll use apply-merge to build a new turn order with what's stored, but leaving the copy on the stack:

!group-init --stack apply-merge



Now, swapping the current turn order for the saved one:

!group-init --stack swap


(I didn't name that one, so it got a generic title of {8 records} )

Will store custom turns and their auto change parameters as well (I named this one "A custom Turn").



Well, that's about all the examples I've got in me.  Try it out a bit and let me know what you come up with!



Github: https://github.com/shdwjk/Roll20API/blob/master/Gr...
Previous Forum Post: https://app.roll20.net/forum/permalink/3975602/



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.
January 07 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Update v0.9.31 -- Added support for passing token_ids using the --ids argument (Thanks Victor B. )

You can now pass an ID (if you are the GM or the API) using the --ids argument:

!group-init --ids @{target|token_id}

Additionally, I've added an external interface for scripts to request that tokens get rolled based on an array of token_ids:

GroupInitiative.RollForTokenIDs( <Array of IDs> [, Options ] );

  • <Array of IDs> is an array containing Token IDs
  • Options is an optional object with various properties set.  Currently, the only supported property is:
    • manualBonus -- a floating point number which is applied as if supplied to the --bonus argument.

Here's a sample script using it:

/* global GroupInitiative */
on('ready', ()=>{
	const handleTurnOrderChange = (/* obj */ /*, prev */ ) => {
		sendChat('',`/w gm Turnorder Changed!`);
	};

	let giRoll = () => sendChat('',`/w gm <code>GroupInitiative.RollForTokenIDs()</code> is not supported.`);

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

	if('undefined' !== typeof GroupInitiative && GroupInitiative.RollForTokenIDs){
		giRoll = GroupInitiative.RollForTokenIDs;
	}

	on('chat:message', (msg) => {
		if('api' === msg.type && /!test-gir/i.test(msg.content)){
			let cmds = msg.content.split(/\s+/);
			
			giRoll(
				(msg.selected||[]).map(s=>s._id),
				{
					manualBonus: cmds[1]||0
				}
			);
		}
	});


});

Been looking through the old threads in case this has already been asked. I couldn't find it but sorry if this is a duplicate question:

Is it possible to set up Group-Init to not reset the turn while adding new tokens? I run a game that regularly involves players swapping out characters/tokens and every time we do this we end up clicking next turn until we get to where we already were in the turn order.

March 12 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Not currently, but it's on my list of things to do.  sorry for the late reply.

Submitting a formal request (for the next version of GroupInit) to add the ability to roll one initiative per monster type. So in a combat featuring one vampire and five zombies, all five zombies have the same initiative count, but the vampire has its own initiative count. Thank you for this wonderful script!

March 16 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

That's definitely something I'd love to add!

the biggest problem with that is going to be how to represent it in the TurnOrder. The options are:

  1. pick one monster from the group, use it as the place holder. Problem if it goes away but there are others still on the board
  2. add them all with the same initiative (useful for several reasons, and the easiest option)
  3. add a custom turn entry that refers to the group (some issues with this one, but it's pretty straight forward)

what do you think is the right choice?

March 17 (5 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

1 or 2 would cause less synergy problems with other workflows that rely on the TurnOrder referring to actual tokens (ex. CombatTracker, CombatMaster).

Can the API react to a token deletion to replace one Goblin with the next Goblin, if such exists?

March 17 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

If it knows which goblins to chose from to replace it with. 

March 17 (5 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

I just figured it would filter the tokens on the page for the sheet the recently removed token was linked to, and choose one at random or by a predetermined criterion to place on the turn tracker in its place.

Token removed from Init 15 linked to goblin sheet.

Look at all tokens on map.

Any linked to goblin sheet?

If yes, add one to Turn Tracker at Init 15.

else, um... don't do that.

Personally though, if I have a battle with 10 goblins, four hobgoblins and, say, a couple of Xvarts, I place one of each in the border of the map I conceal with Fog of War. I use those tokens for initiative, and move and delete the rest of them as I will. I just found the question intriguing.

March 17 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

I suppose there wouldn't be any harm in doing it that way.  You'd have to use group-init to clear the turn order, otherwise it would just keep adding goblins back in.  It might also pick a goblin that's way far away on a big map (Dungeon of the Mad Mage, for example).  Better might be for you to select all of the critters, and roll, and let that determine the subset of creatures to chose from, then store them as a group in the state and keep one from each group in the turn order until they're all gone.

March 17 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Update v0.9.32 -- Fixed token_bar, token_bar_max and token_aura options (Thanks Lockbox313)


The Aaron said:

If it knows which goblins to chose from to replace it with. 


Could that be done using TokenNameNumber? It starts on Goblin 1, and if that dies it moves to the next Goblin in numerical order (skipping to 3 if 2 is already dead)

March 17 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

It could, but it's probably easier to do it in other ways that would not introduce a dependency on that script.  The main thing is to do it in a way that doesn't make assumptions (or as few as possible) about how the end user uses it.


The Aaron said:

That's definitely something I'd love to add!

the biggest problem with that is going to be how to represent it in the TurnOrder. The options are:

  1. pick one monster from the group, use it as the place holder. Problem if it goes away but there are others still on the board
  2. add them all with the same initiative (useful for several reasons, and the easiest option)
  3. add a custom turn entry that refers to the group (some issues with this one, but it's pretty straight forward)

what do you think is the right choice?

My vote would be option 2. 


Sorry for the dumb question - how can I roll initiative for a token which sums 2 of its parameters? I have perception|current and initiative_modifier|current in stat ordering, but they don't sum when I roll initiative... How can I do that?

March 18 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

You just need to add them to the same group. Sorry, the syntax is a bit arcane and dated...

!group-init --add-group --bare perception --bare initiative_modifier

Then you'll need to delete those other two groups (do this twice):

!group-init --del-group 1

Then you should be all set.

Got it, thanks!

The Aaron said:

You just need to add them to the same group. Sorry, the syntax is a bit arcane and dated...

!group-init --add-group --bare perception --bare initiative_modifier

Then you'll need to delete those other two groups (do this twice):

!group-init --del-group 1

Then you should be all set.




Just started trying this script today, and new to using the api. When I try using this script, it's adding a bonus of 10 to all the rolls and I'm not sure why.

April 17 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

You need to configure it.  It predates character sheets and defaults to adding an ability named "dexterity".

The Aaron said:

You just need to add them to the same group. Sorry, the syntax is a bit arcane and dated...

!group-init --add-group --bare perception --bare initiative_modifier

Then you'll need to delete those other two groups (do this twice):

!group-init --del-group 1

Then you should be all set.




The Aaron said:

That's definitely something I'd love to add!

the biggest problem with that is going to be how to represent it in the TurnOrder. The options are:

  1. pick one monster from the group, use it as the place holder. Problem if it goes away but there are others still on the board
  2. add them all with the same initiative (useful for several reasons, and the easiest option)
  3. add a custom turn entry that refers to the group (some issues with this one, but it's pretty straight forward)

what do you think is the right choice?


One  thought would be to use something like your init group but allow it to store specific token names and group init bonus checks for that sheet/token. That way the only thing you really have to do is just rename the token, not unlink it or just use a non linked token. 

April 20 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

So, a process like:

  • Select a group of tokens
  • Run !group-init
  • For each token GroupInitiative:
    • If a monster of that type does NOT exist, roll it's initiative and add it to a list of monsters of that type
    • If a monster of that type does exist, report the current initiative and add it to the list of monsters of that type
  • When a monster token is removed:
    • Remove that monster from the monsters of that type list
    • If there are other monsters of that type, re-add the first remaining one at the existing initiative point
    • If there are no other monsters of that type, remove the list.



The Aaron said:

So, a process like:

  • Select a group of tokens
  • Run !group-init
  • For each token GroupInitiative:
    • If a monster of that type does NOT exist, roll it's initiative and add it to a list of monsters of that type
    • If a monster of that type does exist, report the current initiative and add it to the list of monsters of that type
  • When a monster token is removed:
    • Remove that monster from the monsters of that type list
    • If there are other monsters of that type, re-add the first remaining one at the existing initiative point
    • If there are no other monsters of that type, remove the list.


That can work I was thinking it would be like !group-init --add-group --bare perception --bare initiative_modifier only you create a list something like !group-init --add-token-group --bare init --bare initiative_modifier .but your logic may have better application. Good stuff.




May 03 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Update v0.9.33 -- Fixed token_bar, token_bar_max and token_aura options to work when tokens don't represent a character.  Additionally, I've updated GroupInitiative to create a Help: GroupInitiative handout the same way TokenMod and some of my other scripts are.  By default, it is only viewable by the GM.  To support that, I overhauled the help quite a bit.

I've finally removed Dexterity as the default Bonus Stat Group and replaced it with a system that prompts you if you don't have something configured yet:


If you have a standard configuration for a released character sheet, let me know what it is and I'll get it added into the list.


May 03 (5 years ago)

Edited May 03 (5 years ago)

Fyi,

Reporting some feedback on  the new features for group init. I tried pre-rolling inits and getting my monsters into the tracker and used the !group-init --stack dup some name here to save it. This worked well. I even cleared the tracker and then confirmed the list was stored  using !group-init --stack. All seems fined, then tested with !group-init --stack pop,works no issue. Then cleared the tracker and put in some test party members and used !group-init --stack apply-merge and worked perfectly. So I cleared the tracker and did some other clean up. Logged out of the game and logged back in repeated my test which all worked fine. However when I started today game (this was about 8 hours since last log out) we get to the actual event only group init did not keep that list in its session state.  I had no errors nor was anything changed in that time. So how long is Group init supposed to save that list? Would clearing the chat archive have any affect on it.? Any way might be one off but thought you should know.

May 03 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Thanks for the detailed report!  It should store it indefinitely, I'll have to try and duplicate that. 

Do we have to reinstall it to get the upgrade or does it happen when we start up API?


May 04 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

It should show up automatically on Tuesday. 

@The Aaron, how do you get the nice end-of-turn markers that you have:  

May 05 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

That's TurnMarker1:   https://github.com/shdwjk/Roll20API/blob/master/TurnMarker1/TurnMarker1.js

I need to revamp it and get it back in the 1-click.


The Aaron said:

That's TurnMarker1:   https://github.com/shdwjk/Roll20API/blob/master/TurnMarker1/TurnMarker1.js

I need to revamp it and get it back in the 1-click.


Cool, thanks.  I'll try it out, and keep an eye open for your updates.  You do outstanding work!

May 05 (5 years ago)
The Aaron
Roll20 Production Team
API Scripter

Thanks!

May 12 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Update v0.9.34 -- Added an option to preserve the first token turn when auto-sorting the turn order on token add. (Thanks andrea d.)

You can set it in the help menu or toggle it with:

!group-init-config --toggle-preserve-first


The Aaron said:

Update v0.9.33 -- Fixed token_bar, token_bar_max and token_aura options to work when tokens don't represent a character.  Additionally, I've updated GroupInitiative to create a Help: GroupInitiative handout the same way TokenMod and some of my other scripts are.  By default, it is only viewable by the GM.  To support that, I overhauled the help quite a bit.

I've finally removed Dexterity as the default Bonus Stat Group and replaced it with a system that prompts you if you don't have something configured yet:


If you have a standard configuration for a released character sheet, let me know what it is and I'll get it added into the list.



Hello The Aaron, I am running a d&d 3.5 game and created some mooks by filling out the NPC character sheets and linking them to the tokens (which work perfectly for all macros that I have created so far). I wanted to use GroupInitiative for my mooks, so I manually entered the initiative bonus(es) into token bar 2 and was trying to use: !group-init --token_bar 2 to get it to add that bonus into the initiative rolls. However, I keep getting an error:

(From GroupInitiative):

Not a valid command: token_bar


Given that I am extremely new, it is possible that I am not typing the command with the correct syntax...but otherwise I have no clue as to how to fix/address this issue.

May 20 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

The syntax for adding groups is a bit arcane. You'd do:

!group-init --add-group --token_bar 2

Thanks The Aaron! That was my issue...follow up newb question: Do I just need to configure that 1 time per session? (I am assuming that the API script configuration is not a persistent setting of the game).

May 20 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Just once.  It is persisted.

May 23 (4 years ago)

0.9.34 is now in the One-click menu, but when I select it (and save), the new option for

!group-init-config --toggle-preserve-first

doesn't work.  All I get back is:

Unsupported Option:
toggle-preserve-first

And the option doesn't appear in the config menu that I can see. In fact, the config menu still shows the version as 0.9.33 (which may explain why the new option doesn't work).

May 23 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Hmm. That's bizarre. I'll take a look in the morning. 

May 23 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Ok, I've verified this is an issue on the Roll20 side.  The 1-click is still installing 0.9.33 for "Latest", despite 0.9.34 being there.  Importing it will get you 0.9.34.  I've passed this on to the Devs to sort out.

Not sure if I should start a new thread for this but was just wondering if it's possible to roll initiative for multiple layers at the same time? I'm guessing not since there doesn't seem to be a way to select tokens across multiple layers.


If that is the case, then is the process for adding tokens from both the token layer and GM layer:
1) Select tokens on token layer
2) Run the initiative command
3) Change layers to GM layer
4) Select tokens on GM layer
5) Run the initiative command again to add new tokens


I'm fine if that's the case, just want to make sure I'm not doing extra unnecessary work. Love this script btw.


Kyle said:

Not sure if I should start a new thread for this but was just wondering if it's possible to roll initiative for multiple layers at the same time? I'm guessing not since there doesn't seem to be a way to select tokens across multiple layers.


If that is the case, then is the process for adding tokens from both the token layer and GM layer:
1) Select tokens on token layer
2) Run the initiative command
3) Change layers to GM layer
4) Select tokens on GM layer
5) Run the initiative command again to add new tokens


I'm fine if that's the case, just want to make sure I'm not doing extra unnecessary work. Love this script btw.

No not with Group Init. However you should check out the BUMP script also buy  The Aaron. It provides a way to invisibly manipulate tokens on the GM Layer from the Objects Layer, and vice versa. Even those transparent invisible tokens can be selected and rolled for init. ;)


Thank you so much for that reply. Not only does that script fix the initiative issue but makes managing hidden/shown tokens so much easier to deal with.

May 26 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Woot! Glad you got a solution!  Go community!!! Thanks Mark!

May 26 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Anthony said:

0.9.34 is now in the One-click menu, but when I select it (and save), the new option for

!group-init-config --toggle-preserve-first

doesn't work.  All I get back is:

Unsupported Option:
toggle-preserve-first

And the option doesn't appear in the config menu that I can see. In fact, the config menu still shows the version as 0.9.33 (which may explain why the new option doesn't work).

This is fixed now!

May 28 (4 years ago)


The Aaron said:

Anthony said:

0.9.34 is now in the One-click menu, but when I select it (and save), the new option for

!group-init-config --toggle-preserve-first

doesn't work.  All I get back is:

Unsupported Option:
toggle-preserve-first

And the option doesn't appear in the config menu that I can see. In fact, the config menu still shows the version as 0.9.33 (which may explain why the new option doesn't work).

This is fixed now!

Great; thanks!


May 29 (4 years ago)

Is there an option to turn off the ".Dexterity" value that is coming up?  I have the tiebreaker checkbox turned off, but it still adds it.  Pretty sure it didn't use to, but this is a new game that I just started.

May 29 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Can you show me what your current configuration is?  !group-init --help

June 14 (4 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Is there a way to respect characters using the D&D 5th Edition by Roll20 Sheet who roll for initiative using advantage (it's a setting on the PC sheet). I'd prefer to use one macro for all.

June 14 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Sadly, not easily. It's something I intend to add, but requires a rewrite of the bonus stat groups to add conditional branching.

June 14 (4 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Eh, I only have one player with this ability. He can roll twice and edit. :)

Oh, I had no idea group-init didn't allow for that advantage toggle. I have a player who has that ability. Hmm. Maybe I'll use group-init for monsters exclusively.