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]

August 19 (9 years ago)
OMG FINALLY, got it thanks mucho gracias Aaron!
August 19 (9 years ago)
The Aaron
Pro
API Scripter
Great!  Glad to hear it!  =D  Definitely let me know if there's anything else I can help with. =D

The Aaron said:

Great!  Glad to hear it!  =D  Definitely let me know if there's anything else I can help with. =D

You could help by making your script have an option to reroll all characters currently in the Initiative tracker!  Old-school D&D did that.

Oh, and the fact that I would like to try it doesn't have anything to do w/ my asking for it. I'm just trying to help out Rorary.  ;)

August 20 (9 years ago)
vÍnce
Pro
Sheet Author
Isn't  that what "Replace Roll is currently" is for?  Or do you mean automagically reroll only those tokens in the tracker without having to reselect tokens?  That might be cool.
August 20 (9 years ago)

Edited August 20 (9 years ago)
The Aaron
Pro
API Scripter
Like this?

Update v0.9.9 -- Added --reroll to reroll all the tokens in the Turn Order as if they had all be selected. (Thanks Three of Swords!)
August 20 (9 years ago)
The Aaron
Pro
API Scripter
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
August 20 (9 years ago)
vÍnce
Pro
Sheet Author
Pesky TurnMarker...  Thanks Aaron.
August 20 (9 years ago)
The Aaron
Pro
API Scripter
Actually, I've already got a solution, just have to drop it in TurnMarker. (I cringe going in that code!  Got to finish that rewrite!!)
Oh, yeah!  Looking forward to it.  :)
August 20 (9 years ago)
Kryx
Pro
Sheet Author
API Scripter
Has anyone made this work with the 5e Shaped sheet? I've tried a few times, but have given up every time.

Problems:
  • "dexterity_bonus" which is a number input, but shows up as blank when I add it
  • "jack_of_all_trades" which is calculated from "floor(@{PB} / 2)" which is calculated from other things

Shamefully I'm a bit lost. I really just want to replicate the initiative button from the sheet. :(
August 20 (9 years ago)
Kryx,

This is done quite easily.  First remove all bonus groups, by default there is 1.

!group-init --del-group 1

Then add a "Bare" group for the autocalculated field for "initiative_overall"

!group-init --add-group --Bare initiative_overall|current

The rest of the settings should be default (individual roll, die size, die count, etc...).
August 20 (9 years ago)

Edited August 20 (9 years ago)
Kryx
Pro
Sheet Author
API Scripter
Thank you very much! I can now finally use this script instead of clicking init on every token that is hidden on the GM layer.

Now my players won't know how many enemies there are based on how long it takes me! :D

This plus Bump would really help me speed up my play.
August 20 (9 years ago)
If you want to implement the tiebreaker, then you first need to set the decimal places to 2 (using buttons in !group-init --help).

Then you can run:
!group-init --add-group --Tie-Breaker overall_init|current
!group-init --promote 2

This should put the Bonus Stat Group Ordering as:
1. Tie-Breaker (initiative_overall|current)
2. initiative_overall|current
August 20 (9 years ago)

Edited August 20 (9 years ago)
Kryx
Pro
Sheet Author
API Scripter
It should be "initiative_overall", not "overall_init", right?

But doing that and then promoting the tie breaker to the 1st slot makes the overall bonus not add. :(

August 20 (9 years ago)
The Aaron
Pro
API Scripter
You have to put them in as a single rule:
!group-init --add-group --Bare initiative_overall --Tie-Breaker initiative_overall
Sorry the syntax is so arcane, I've been meaning to rewrite it but haven't gotten to it yet. 

Also sorry you were having such trouble with it to begin with!

August 20 (9 years ago)
Kryx
Pro
Sheet Author
API Scripter
That does it, thanks so much !

I understand the arcane nature - sheet generated values are difficult to use.
August 20 (9 years ago)
That was a typo indeed on my part Kryx, and thank you Aaron for clarifying... I have always had trouble getting the tie-breaker to work and now I understand why!

The Aaron said:

Like this?

Update v0.9.9 -- Added --reroll to reroll all the tokens in the Turn Order as if they had all be selected. (Thanks Three of Swords!)

You're awesome!  I considered modifying your code on my own, but my scriptomancy skills aren't that powerful yet.  Probably never will be since this is the only place I write code for.


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?
August 21 (9 years ago)
The Aaron
Pro
API Scripter
Totally slipped my mind, sorry about that.  I'll endeavor to test it tomorrow night. 
I thought to update my script from 0.41 and I had to revert for when I used the simple command to start a roll, this error would appear.

/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 10 has no method 'replace'
at evalmachine.<anonymous>:5828:37
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>:5824:18at /home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:158:20
at Array.some (native)
at _.some._.any (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:207:59)
at Function._.find._.detect (/home/symbly/www/d20-api-server/sandcastle/node_modules/underscore/underscore.js:157:5)
at findInitiativeBonus (evalmachine.<anonymous>:5822:11)

Does anyone know what is causing this?
August 31 (9 years ago)
The Aaron
Pro
API Scripter
Which stat are you using for your initiative bonus and how is it being set?

Attributes contain strings, but it looks like yours contains a number, the number 10.  That's kind of odd.

If you go to line 672 and add +'' to the end of it, just before the ;, it should fix the problem:
var stat=getAttrByName(char.id,details.attribute, details.type||'current')+'';

Well my mobs have a stat called Initiative and it's purely a number. But it works now though, so thanks!
August 31 (9 years ago)
The Aaron
Pro
API Scripter
Cool!  Glad to hear it!

I'll roll that into the standard version.  I've got another little fix I'm working on to allow the token bars to be used instead of attributes. 

The Aaron said:

Cool!  Glad to hear it!

I'll roll that into the standard version.  I've got another little fix I'm working on to allow the token bars to be used instead of attributes. 


Thanks, I use a modified version of Honey Badger's old 4E mob importer, so it makes Power Card V3 moves for them. It pulls the initiative number straight from the monster files, hence why it's a single unit and not a calculation. It'd be useful to include it in later versions incase others use similar methods.

August 31 (9 years ago)
The Aaron
Pro
API Scripter
I suspected a script was involved in setting the value, otherwise, it would come in from a text field, which would make it a string. =D
September 01 (9 years ago)

Edited September 01 (9 years ago)

The Aaron said:

Which stat are you using for your initiative bonus and how is it being set?

Attributes contain strings, but it looks like yours contains a number, the number 10.  That's kind of odd.

If you go to line 672 and add +'' to the end of it, just before the ;, it should fix the problem:
var stat=getAttrByName(char.id,details.attribute, details.type||'current')+'';


I hoped this might work out for me as well, but it didn't. Instead of the old error, I get this one.

/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 7 has no method 'replace'
at _substituteShortForms (


Same set-up as before (using a script to change the value), but updated to the most recent version of this script.
September 01 (9 years ago)
The Aaron
Pro
API Scripter
Oh!  Good eye. That is the same problem, just a different location. I'll sift through this morning and find it. 
September 01 (9 years ago)
The Aaron
Pro
API Scripter
Dylan, can you link me to the !tracker script you're using?  I can't find it.
September 01 (9 years ago)

Edited September 01 (9 years ago)
That's probably because it doesn't have it's own thread. The person who wrote (well you wrote it, he modded it) it posted it in the thread for your Ammo script.

https://github.com/happywanderer/Tracker-API/blob/...
September 01 (9 years ago)
The Aaron
Pro
API Scripter
Ah, that's right. It's the rename of Ammo. Ok. 
September 03 (9 years ago)
The Aaron
Pro
API Scripter

Dylan S. said:

The Aaron said:

Which stat are you using for your initiative bonus and how is it being set?

Attributes contain strings, but it looks like yours contains a number, the number 10.  That's kind of odd.

If you go to line 672 and add +'' to the end of it, just before the ;, it should fix the problem:
var stat=getAttrByName(char.id,details.attribute, details.type||'current')+'';


I hoped this might work out for me as well, but it didn't. Instead of the old error, I get this one.

/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 7 has no method 'replace'
at _substituteShortForms (


Same set-up as before (using a script to change the value), but updated to the most recent version of this script.

Ok, unfortunately, this is an internal error.  On the bright side, I talked to Riley about it and he plans to fix it shortly.  I don't know anything about timeframe for it to be out.

In the interim, this should fix the current issues:
on('ready',function(){
	"use strict";

	filterObjs(function(o){
		if('attribute' === o.get('type')) {
			if( 'string' !== typeof o.get('current')){
				o.set('current', o.get('current')+'');
			}
			if( 'string' !== typeof o.get('max')){
				o.set('max', o.get('max')+'');
			}
		}
		return false;
	});
});

Some script you are using is setting attributes to numbers, which that function does not expect.  This snippet will check all of your attributes and turn them into strings if they are something else.

Of course, using that other script will still set them to numbers, but at least each restart of the sandbox will fix any issues until such time as the function is fixed.
September 03 (9 years ago)
Interesting, I'm always breaking the API somehow.

So i just plug this snippet into your script or do i make a separate script for it?
September 04 (9 years ago)
The Aaron
Pro
API Scripter
As a separate script. :)
September 04 (9 years ago)
Cool. Thanks for looking into it for me!
September 04 (9 years ago)
The Aaron
Pro
API Scripter
My pleasure. :)
September 14 (9 years ago)
So I am having issues with this script... Here is the error:
For reference, the error message generated was: 
evalmachine.<anonymous>:16181
                                        total: (ird.results.total%1===0
                                                   ^
TypeError: Cannot read property 'results' of undefined
    at evalmachine.<anonymous>:16181: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>:16178:34
    at checkFinishedOps (

What is really strange is that this configuration was running several weeks ago... then just stopped working for some reason.  Also if I select an individual token it works great.  If I select multiple tokens it fails. 
September 14 (9 years ago)
The Aaron
Pro
API Scripter
Hmmm...  I'll take a look.
September 14 (9 years ago)
Two things of interest in testing:

1)  I have one player with a -1 modifier (5e initiative_overall) and frequently I get the following result (notice the tooltip):


After getting the above result !group-init roll that includes this specific character crashes with (I beleive) the same error.

2) If I disable the tie-breaker (setup using this singe rule:  !group-init --add-group --Bare initiative_overall --Tie-Breaker initiative_overall) it kind of works until the problem above occurs.

Thanks
September 15 (9 years ago)
The Aaron
Pro
API Scripter
That's good info, somewhere I must be checking if the value exists, but with adjustments the value is 0, which is seen to be false and causes the wrong thing to happen.  That will definitely help track down the issue.

September 16 (9 years ago)
Is there a way to call the Initiative bonus from the Pathfinder Character sheet or do I have to add an attribute manually for initiative?
September 16 (9 years ago)
vÍnce
Pro
Sheet Author
@{init} is the attribute.  On phone...else I would check.
September 16 (9 years ago)

Edited September 16 (9 years ago)
I must be doing something wrong.  I'm using  [Sheet created by Samuel Marino, currently maintained by Vince, Samuel Terrazas and Nibrodooh | Last updated: 09.03.2015] from production server:

!group-init --bonus @{selected|init}

Getting this in chat:
(From GroupInitiative): Not a valid bonus: (((floor((14


I'll keep messing around with it.  I just upgraded to PRO today so I am a noob.
September 16 (9 years ago)

Edited September 16 (9 years ago)
vÍnce
Pro
Sheet Author
You can test for the presence of the init attribute by just using @{selected|init}
I'm using
init|current + Tie-Breaker( init|current )
September 16 (9 years ago)
The Aaron
Pro
API Scripter
The argument to --bonus is a simple number, it doesn't get evaluated as a formula.  You could use something like:
!group-init --bonus [[@{selected|init}]]
To replace it with the evaluated value in that attribute, however if you expect everything to have that attribute, you should set it up as a group:
!group-init --add-group --Bare init
You'll probably need to remove the default rule with:
!group-init --del-group 1
You can read all about this in the help:
!group-init --help

September 17 (9 years ago)
Lucian
Pro
API Scripter

Kevin said:

So I am having issues with this script... Here is the error:
For reference, the error message generated was: 
evalmachine.<anonymous>:16181
                                        total: (ird.results.total%1===0
                                                   ^
TypeError: Cannot read property 'results' of undefined
    at evalmachine.<anonymous>:16181: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>:16178:34
    at checkFinishedOps (

What is really strange is that this configuration was running several weeks ago... then just stopped working for some reason.  Also if I select an individual token it works great.  If I select multiple tokens it fails.
I have this same issue - works fine if you have one token selected, reliably happens with multiple tokens. I'm using the 5e shaped character sheet with
!group-init --add-group --Bare initiative_overall --Tie-Breaker initiative_overall
as suggested higher up in this thread.

Cheers,
Lucian

September 17 (9 years ago)

Edited September 17 (9 years ago)
Aaron, thx for the help but still no go.  I use @{selected|init} in the PF macros I use right now and they work fine.  Just not getting it to work with your script.  This is the one we are using and I have my players rolling their own initiative.

&{template:pf_generic} {{character_name=@{selected|character_name}}} {{character_id=@{selected|character_id}}} {{name=Initiative}} {{check=[[ (1d20 + [[ @{selected|init} ]][init] + [[ abs(0.01 * @{selected|init}) ]][tie-breaker]) &{tracker} ]]}}

This is the error that I get in the API Output Console:

/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'll just have my players continue to do their own initiative.  I really just wanted it to Auto Sort the results...I'm so lazy.  :)

September 17 (9 years ago)
The Aaron
Pro
API Scripter
Ha.  Ok.  Do you want to PM me a join link and GM me and I can take a look?
September 17 (9 years ago)
Lucian
Pro
API Scripter
Hey,

Just did a bit of amateur debugging on this, and to my partially-trained eye it looks like something v. strange is happening on the Roll20 side here. When one token is selected, Aaron's script sends a chat message something like this:
[[((@{Dark Goblin|dexterity_mod} + @{Dark Goblin|initiative} + @{Dark Goblin|jack_of_all_trades}) + (@{Dark Goblin|global_check_bonus})+(0.01*((@{Dark Goblin|dexterity_mod} + @{Dark Goblin|initiative} + @{Dark Goblin|jack_of_all_trades}) + (@{Dark Goblin|global_check_bonus})))) + (1d20)]]
and it gets back a response that looks like:
$[[2]]
which it then parses and indexes against the rollResults in the returned message. All fine.

But when you have multiple tokens selected, and Aaron's script sends something like this:
[[((@{Dark Goblin|dexterity_mod} + @{Dark Goblin|initiative} + @{Dark Goblin|jack_of_all_trades}) + (@{Dark Goblin|global_check_bonus})+(0.01*((@{Dark Goblin|dexterity_mod} + @{Dark Goblin|initiative} + @{Dark Goblin|jack_of_all_trades}) + (@{Dark Goblin|global_check_bonus})))) + (1d20)]][[((@{Dark Goblin|dexterity_mod} + @{Dark Goblin|initiative} + @{Dark Goblin|jack_of_all_trades}) + (@{Dark Goblin|global_check_bonus})+(0.01*((@{Dark Goblin|dexterity_mod} + @{Dark Goblin|initiative} + @{Dark Goblin|jack_of_all_trades}) + (@{Dark Goblin|global_check_bonus})))) + (1d20)]]
Roll20 seems to cough up a hairball and sends back this:
$[[2]][[((1 + 0 + 0) + (0)+(0.01*(($[[3]] + 0 + 0) + (0)))) + (1d20)]]
Naturally, Aaron's script barfs fairly hard since it's just expecting two numbers in square brackets, not all of this! What's especially weird is that if I paste the problematic message into my chat window, it just prints the two modified dice rolls next to each other as I would expect, without all the other mad gubbins strewn in there. To make matters worse, of the two placeholders in the message content ($[[2]] and $[[3]]), only the first resolves to the correct inline roll, the other resolves to the expression that calculates the dexterity mod! It all seems a bit borked :-(


Cheers.

Lucian

September 17 (9 years ago)
The Aaron
Pro
API Scripter
Weird!