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]

September 23 (9 years ago)
Just an FYI, this is still a problem with the latest update (not that there was any reason to exactly believe this would be specifically fixed, but tested it anyway).
September 23 (9 years ago)
The Aaron
Pro
API Scripter
Ok. I'll try to take a look very soon.  Busy week...
September 23 (9 years ago)
The Aaron
Pro
API Scripter
Update v0.9.10 -- Fixed some bugs with certain attribute values. (Thanks Kevin!)

I'm pretty sure this will take care of your issues.  If not, perhaps you can invite me to your game and I can take a closer look.  =D
September 24 (9 years ago)
It seems to no longer give the strange failure with the player/monsters that have a negative modifier.

However with that said it still fails when I add the tiebreaker option.
September 24 (9 years ago)
The Aaron
Pro
API Scripter
Hmm.. It seems to be working for me with the following rules:
initiative_overall|current + Tie-Breaker( initiative_overall|current ) + pcinit|current
npc_initiative_overall|current + Tie-Breaker( npc_initiative_overall|current )
What rules are you using?  Are you using the 5e character sheet or the 5e shaped one?

September 24 (9 years ago)

The Aaron said:

Hmm.. It seems to be working for me with the following rules:
initiative_overall|current + Tie-Breaker( initiative_overall|current ) + pcinit|current
npc_initiative_overall|current + Tie-Breaker( npc_initiative_overall|current )
What rules are you using?  Are you using the 5e character sheet or the 5e shaped one?


I am currently using the shaped sheet with the following setting in group-init:
!group-init --add-group --Bare initiative_overall --Tie-Breaker initiative_overall

September 24 (9 years ago)
The Aaron
Pro
API Scripter
I'll have to try that.  Do NPCs and PCs use the same field for initiative?
September 24 (9 years ago)
On the shaped sheet they indeed do share the same field for initiative.
September 24 (9 years ago)
The Aaron
Pro
API Scripter
Can you go into detail about how it fails for the Tie-Breaker?  I looked back over the discussion and I think I may be missing something.
September 24 (9 years ago)
Sure, it is 100% reproducible for me, simply setup group-init with one evaluation group:
!group-init --add-group --Bare initiative_overall --Tie-Breaker initiative_overall

Select more than one creature on the objects layer and it crashes with the following error:
For reference, the error message generated was: 
evalmachine.<anonymous>:16173
                                        total: (ird.results.total%1===0
                                                   ^
TypeError: Cannot read property 'results' of undefined
    at evalmachine.<anonymous>:16173:52
    at Array.map (native)
    at Function._.map._.collect (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:97:56)
    at _.(anonymous function) [as map] (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:1073:39)
    at evalmachine.<anonymous>:16170:34
    at checkFinishedOps (
Selecting an individual token does not generate the error and !group-init completes without error (and of course has the tie-breaker as part of the roll).

September 26 (9 years ago)
The Aaron
Pro
API Scripter
Ok, I've setup the shaped character sheet and have 3 tokens (one with a negative adjustment, one with a positive adjustment, one with no adjustment) and I can't get it to crash like this.  Options?
September 29 (9 years ago)
The Aaron
Pro
API Scripter
I've figured out the issue and opened a bug for it:  https://app.roll20.net/forum/post/2466383/bug-api-...

I'll see if I can get a multi-sendChat() version to work as an alternative until the above gets fixed.

September 29 (9 years ago)
The Aaron
Pro
API Scripter

Dylan S. said:

The Aaron said:

Interesting.  Can you post your Tracker macros?  What is happening is they are adjusting (apparently) whatever attribute is your diceCountAttribute.  Through normal setting, the attribute ends up being a string.  In this function, the string is pulled up for the character, then anything that looks like @{foo} is replaced with @{charname|foo} so that it can be calculated correctly.  However, your tracker macros seem to be setting a number into them (which I frankly though would come back as a string anyway), which means there is no .replace() method, which is what the crash is from.  The solution to this is to verify that it is a string and convert it to one if it isn't.  I can work on that pretty fast, but to be sure I've got it fixed, I need the macros you're running so I can duplicate the crash.

I'll need to know a bit about your Group Initiative configuration as well.  The output of !group-init --help should be sufficient.

Did this ever get resolved?

I'm pretty certain this is fixed now, can you verify you aren't having this problem now?

September 30 (9 years ago)

Edited September 30 (9 years ago)
Yes and no. Changing a bonus attribute with a script is fine but changing the die count attribute value is still a no no.

/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1
orts, require, module, __filename, __dirname)
{ function g(a){throw a;}var j=v ^
TypeError: Object 4 has no method 'replace'
at buildInitDiceExpression (evalmachine.<anonymous>:1596:29)
at rollers.Individual-Roll.func (evalmachine.<anonymous>:1637:28)
at evalmachine.<anonymous>:2321:46 at Array.map (native)
at Function._.map._.collect (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:97:56)
at _.(anonymous function) [as map] (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:1073:39)
at handleInput (evalmachine.<anonymous>:2313:30) at eval (

September 30 (9 years ago)
The Aaron
Pro
API Scripter
Update v0.9.11 -- Fixed bug when the dice count attribute has been set with an API script (integer instead of string). (Thanks Dylan S.!)

Give that a try.  =D
September 30 (9 years ago)
Hell yes. Thank you!
September 30 (9 years ago)
The Aaron
Pro
API Scripter
Great!  Let me know if you find any more!
October 03 (9 years ago)
Ravenknight
KS Backer
Hi! I love the idea of the script. But sadly I'm too much of a java-idiot to understand how to set it up properly. I would like the outcome to depend on a d20 + stat named Initiative. How would I tell the program to do this? :)
October 03 (9 years ago)

Edited October 03 (9 years ago)
The Aaron
Pro
API Scripter
No problem!  It defaults to a d20 roll, so all you need to do is get rid of the default group (Dexterity) and add a new one with the initiative stat:
!group-init --del-group 1
!group-init --add-group --Bare initiative
Note, you only need to do this once, from then on, you just select the tokens and run:
!group-init

For in-game help and configuration, run this command:
!group-init --help
October 03 (9 years ago)
Ravenknight
KS Backer
Worked like a charm. Thanks Aaron. You're the best! :)
October 03 (9 years ago)
The Aaron
Pro
API Scripter
Great!  Let me know if you need anything else!
October 04 (9 years ago)

Edited October 04 (9 years ago)
Ravenknight
KS Backer
Thanks! I do seem to have messed up somewhere. When I first tried the script it worked but now it halts my API whenever I write: !group-init and gives the following message: 

/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ SyntaxError: Expected [0-9] but "f" found.

[[1d20 + @{selected|Initiative} &{tracker}]] still works for me though.
October 04 (9 years ago)
The Aaron
Pro
API Scripter
Hmm. Can you PM me a join link and GM me, I can pop in and debug it. 
October 04 (9 years ago)
Ravenknight
KS Backer
Thank you. Pm sent.

The Aaron said:

It's not perfect (If you've got tokens you DON'T want to reroll, there's no way to exclude them, TurnMarker being one of them.. I'll fix that at a later point...), but it's pretty good.  =D


So, does that mean that TurnMarker won't work with the reroll command?  It will reroll the turn marker as well?  Has this been fixed yet, or still on the list?
October 13 (9 years ago)
The Aaron
Pro
API Scripter
Update v0.9.12 -- Split the rolls for initiative across multiple sendChat() calls. This fixes a problem with complex rolls overloading the API dice roller. (Thanks Kevin!)

In addition, I updated TurnMarker1 so that it will correct it's marker when GroupInitiative rerolls it:
TurnMarker1 Update v1.3.1 -- Observe changes by GroupInitiative and place PlaceTurnMarker back at the top with an order of -1
October 13 (9 years ago)
Ziechael
Forum Champion
Sheet Author
API Scripter

The Aaron said:

TurnMarker1 Update v1.3.1 -- Observe changes by GroupInitiative and place PlaceTurnMarker back at the top with an order of -1

Just a heads up that i couldn't find the above, it is either still v1.3.0 OR it is v1.3.1 but with the wrong version number on line 12?
October 13 (9 years ago)

Edited October 13 (9 years ago)
The Aaron
Pro
API Scripter
GroupInitiative: https://github.com/shdwjk/Roll20API/blob/master/Gr...
TurnMarker1: https://github.com/shdwjk/Roll20API/blob/master/Tu...

You can always find the latest versions of my scripts in my repo: https://github.com/shdwjk
I've created pull requests for the Roll20 repo, but it may be a few days before they make it there.  Additionally, each script has the URL to itself in the repo as the first line of the file, so if you have one version, you can find the latest version. =D
October 13 (9 years ago)

The Aaron said:

Update v0.9.12 -- Split the rolls for initiative across multiple sendChat() calls. This fixes a problem with complex rolls overloading the API dice roller. (Thanks Kevin!)

Just finished testing this, works great!  Thanks very much for the update.
October 13 (9 years ago)
The Aaron
Pro
API Scripter
Sweet!  Glad to provide it. =D
October 13 (9 years ago)
Ziechael
Forum Champion
Sheet Author
API Scripter

The Aaron said:

GroupInitiative: https://github.com/shdwjk/Roll20API/blob/master/Gr...
TurnMarker1: https://github.com/shdwjk/Roll20API/blob/master/Tu...

You can always find the latest versions of my scripts in my repo: https://github.com/shdwjk
I've created pull requests for the Roll20 repo, but it may be a few days before they make it there.  Additionally, each script has the URL to itself in the repo as the first line of the file, so if you have one version, you can find the latest version. =D

I always forget about your repo sorry... probably confused myself by using the link in the OP to update groupinit but went direct to the Roll20 API github for TurnMarker lol (D'OH)
October 13 (9 years ago)
The Aaron
Pro
API Scripter
=D  no worries. 
Ask, and ye shall receive!  Thanks, Aaron!  Everything's working well.
October 13 (9 years ago)
The Aaron
Pro
API Scripter
Great!  Let me know if there are any problems.  Some of that code is kind of old.. =D
October 18 (9 years ago)

Edited October 19 (9 years ago)
chris b.
Pro
Sheet Author
API Scripter
I found an odd bug. I was working on recreating the auto-calculated fields as Attributes for the Pathfinder character sheet, and finally got it working with GroupInitiative. However, it only works if I select one character and run !group-init  If I select more than one, or use the --reroll switch, it bombs out.

Group:
!group-init --add-group --Bare init2 --Tie-Breaker init2

Attributes:
DEX-mod2
[[[[floor([[@{DEX-base}+@{DEX-enhance}]]/2)]]-5+[[floor(@{DEX-temp}/2)]]-[[abs(floor(@{DEX-damage}/2))]]-[[abs(floor(@{DEX-penalty}/2))]]- @{condition-Entangled} - @{condition-grappled} - @{condition-Fatigued}]]
init2
[[@{init-misc}+@{init-trait}+[[@{DEX-mod2}]]]]

Like I said, this works perfectly for one token. But if selecting more than one token I get the following error:
evalmachine.:4827
                                        total: (ird.results.total%1===0
                                                   ^
TypeError: Cannot read property 'results' of undefined
    at evalmachine.:4827:52
    at Array.map (native)
    at Function._.map._.collect (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:97:56)
    at _.(anonymous function) [as map] (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:1073:39)
    at evalmachine.:4824:34
    at checkFinishedOps (
If i just use attributes with numbers in them (rather than attributes with calculations like [[something]] then the same tokens work fine. (also each individual token works with !group-init so it's not any particular token.)
I am not sure how to debug this, since it looks like somewhere undefined objects are being passed, but the error is coming from the evalmachine 
October 18 (9 years ago)
The Aaron
Pro
API Scripter
Are you using the latest version of GroupInitiative?  I recently (this past week) split the way it rolls into separate sendChat() calls instead of a single one.  There is a bug with the API dice roller where it will die (with that error you listed) if there is too much in one sendChat().    If you're still getting it with the new one, I can't really help you, but with the old one, I totally can.  =D
October 18 (9 years ago)
chris b.
Pro
Sheet Author
API Scripter
That fixed it, thanks! Sorry for the bother i should have checked first.
October 19 (9 years ago)

Edited October 19 (9 years ago)
@chris b. -- thanks for sharing the workaround for the PF character sheet! I was shamelessly c/ping your method for my own use when I found an inconsistency: the DEX-mod2 was returning a score with a .5 for characters with odd-numbered Dex scores (and adding .5 to the tie breaker for init...lol). Looking over your equation, I'm pretty sure it's because you close the parentheses for your first two floor expressions before dividing by 2.
October 19 (9 years ago)
The Aaron
Pro
API Scripter

chris b. said:

That fixed it, thanks! Sorry for the bother i should have checked first.
No bother!  Glad that worked out for you! Let me know if you have any other problems!

October 19 (9 years ago)

Edited October 19 (9 years ago)
chris b.
Pro
Sheet Author
API Scripter
Thanks glenn H! last night a player said "why is my init .5?" and since he did not have +50 :) I was not sure. But that is it, i will fix it. 
Note: I had to fix all of the floor statements not just the first two
October 28 (9 years ago)
Coal Powered Puppet
Pro
Sheet Author
The Aaron said:
Which character sheet are you using?
So for most characters, you use 2d6, but for a few special characters, you want to add an additional 1d6?

The basic process is that you create groups and it applies them until it finds one that has all the listed attributes. The biggest problem to this is that for character sheets EVERY attribute exists for the character. The easiest way to handle this is to add an attribute to the character that needs the extra 1d6 with the value '[[1d6]]'. Lets assume it's PreternaturalAwareness. You can then add a rule to GroupInitiative for it like this:
!group-init --add-group --Bare PreternatualAwareness
Make sure that rule is first if you have more than one rule. Just keep using this command with whatever number it has until it is at 1:
!group-init --promote <#>
When you run !group-init, it should then add that [[1d6]] in for the one that has it, and skip it for the rest.

If you have more complex rules, you can just add that as part of it, for example if everyone used the initMod attribute, you might have 2 rules:
!group-init --add-group --Bare initMod --Bare PreternatualAwareness
!group-init --add-group --Bare initMod
Your aware character will match the first one, the rest will fall through to the second.


Anyway, hope that helps. BTW, if you post on the GroupInitiative thread, I'll get an email and respond much faster! =D
I am using my Iron Kingdoms character sheet (just like the one I made for the main Roll20/Github, but with some modifications).

Initiative is [[ 2d6 + @{initiative} + @{Preternatural_Awareness-switch} ]]

@{initiative} is a static, disabled='true' numberbox using a total of four (3 plus 1 random modifier) different traits.  @{Preternatural_Awareness-switch} is (now, after your suggestion) a checkbox with the value of '[[1d6]]'.

Something is going wrong, so...please continue to break this down, Barney style.  Small words and big pictures is how I learn. 
October 28 (9 years ago)

Edited October 28 (9 years ago)
The Aaron
Pro
API Scripter
Assuming you have a character named Bob who has preternatural awareness and one named Tom that doesn't, what is the output of this:
Bob: @{Bob|Preternatural_Awareness-switch}
Tom: @{Tom|Preternatural_Awareness-switch}
I speculate it will be [[1d6]] for each.

When I said "add an attribute", I was referring to the Attributes and Abilities tab, not the Character Sheet.  If you add an attribute in that tab, the following will be and error for any character that does not have it:
Tom: @{Tom|MissingAttr}
If you add it via adding it to the Character Sheet, it will not be an error.  GroupInitiative depends on this relationship in order to match rules (GroupInitiative actually predates the character sheets.

If you want to handle this via the Character Sheets, you'd need to have a checkbox which is either a 1 or a 0 depending on if it is checked (I'm not certain how you handle this in Character Sheets) and an auto calculated field which multiples that checkbox's value by 1d6.  You would then add that attribute to everyone's initiative in a single rule.  The ones who have it checked would then get [[ 1d6 * 1 ]] added to their roll, while the ones without it would get [[ 1d6 * 0 ]].
November 08 (9 years ago)
Hi everyone, 

I started using this very useful script, but i think i done goof :/

I added a bonus stat group like that:

!group-init --add-group --Bare speed_total

and then deleted the dexterity|current  bonus stat group with :

!group-init --del-group1

Now i only have my speed_total|current listed. BUT when i tried to do !group-init, the script crash and give me this in the API output console:

For reference, the error message generated was: /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ SyntaxError: Expected "(", ".", "[", "abs(", "ceil(", "d", "floor(", "round(", "t", "{", [ |\t], [+|\-], [+|\-|*|\/|%] or [0-9] but ")" found.

The script was working fine before i did that, i tried disable it, delete it then re-install it but the bonus stat group list is still in memory.

So now that i know that i mustn't do what i did, is there a way to reset the script ?


November 09 (9 years ago)
The Aaron
Pro
API Scripter
You can remove stat groups with:
!group-init --del-group ##
where ## is the number of the rule for that group. Check the help for the index numbers:
!group-init --help

Probably what is happening is the speed_total attribute has a formula in it that the ALI has problems evaluating. I have a big ticket in with examples of where things break, hopefully it will be fixed in the coming months. 
November 10 (9 years ago)
Hey Aaron! So, in the campaign I GM for, we have a character who has 5E advantage on initiative - rolls 2 d20's, keeps the highest.

There's no default way to enable this, and using a formula attribute seems to drop the boolean k/d commands and ignore them; is there something I'm missing in the formula or is this currently not possible by default? ([[{1d20,1d20}k1]] being the current formula I tried)
November 10 (9 years ago)
The Aaron
Pro
API Scripter
I'm sorry to say this isn't possible in the current version.  I'll add it to a list to get in there when I rewrite the stat group code.  Probably the best way to handle it now is just to run group init on that token twice and manually adjust back to the first roll if it was better.
December 11 (9 years ago)
This script is very helpful, thanks Aaron.

I thought it wouldn't work using the DnD 4e character sheet because the initiative attribute is autocalculated, but I could do it with the add-group command:

!group-init --add-group --Stat-DnD dexterity --Floor halflevel --Bare init-feat --Bare init-item --Bare init-misc

!group-init --promote 2

Luckily it seems that the 'floor(@{level}/2)' value of the 'halflevel' autocalculated attribute is not problematic for the script ^^

However, if I execute !group-init with a selected token already in the Turn Order, it doesn't work: Turn Order window closes and nothing executes. I can see only this on the chat:
GroupInit:
(From GroupInit):
So the script doesn't removes tokens that already have a turn. It stops there and I have to remove them for it (no big deal).
December 11 (9 years ago)
The Aaron
Pro
API Scripter
It should actually expand autocalc fields just fine at this point. 

There is a setting in the help to replace the turn order of tokens that are already in the turn order. I think it's called Replace Roll. Let me know if I misunderstood what you were asking for and I'll see what I can do! :)
December 13 (9 years ago)
I just upgraded to Pro recently and I decided to try this script out. So far, I am loving this, and I reckon it will prove to be very useful for rolling initiative for multiple creatures that my players may face in my campaign!

However, when it comes to multiple creatures, each with their own character sheets, I'm having problems with using the initiative listed on their character sheets (To clarify, I am using the Pathfinder Character Sheet by Vince).

Currently, I tried using solutions mentioned here, but each yield different results, none of them work:


!group-init --bonus [[@{selected|init}]]
On an individual basis (selecting only 1 token), this works perfectly fine, but it breaks when I select multiple tokens at once. Apparently it seems to only take the initiative modifier of only one of the tokens, and applies it to all of them.


!group-init --add-group --Bare init
This one, on the other hand, pretty much breaks the entire script. When I try out !group-init after adding this to the Bonus Stat Groups, the API console returns this error message:
/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1
orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v
                                                                    ^
SyntaxError: Expected "[" or [ |\t] but "0" found.

I tried to go around the problem by manually calculating the initiative through the character sheet:
!group-init --add-group --Bare DEX-mod --Bare init-trait --Bare init-misc
But the same error pops up on the console.


Am I doing something wrong here?