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]

OMG FINALLY, got it thanks mucho gracias Aaron!
1440023359
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.  ;)
1440035472
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.
1440037601

Edited 1440037632
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!)
1440037792
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
1440039663
vÍnce
Pro
Sheet Author
Pesky TurnMarker...  Thanks Aaron.
1440041114
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.  :)
1440062741
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. :(
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...).
1440067953

Edited 1440067999
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.
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
1440068963

Edited 1440069123
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. :(
1440070039
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!
1440072448
Kryx
Pro
Sheet Author
API Scripter
That does it, thanks so much ! I understand the arcane nature - sheet generated values are difficult to use.
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?
1440128903
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?
1441033377
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!
1441035453
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.
1441038500
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
1441092625

Edited 1441092718
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.
1441106524
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. 
1441110825
The Aaron
Pro
API Scripter
Dylan, can you link me to the !tracker script you're using?  I can't find it.
1441127508

Edited 1441127575
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. <a href="https://github.com/happywanderer/Tracker-API/blob/" rel="nofollow">https://github.com/happywanderer/Tracker-API/blob/</a>...
1441128421
The Aaron
Pro
API Scripter
Ah, that's right. It's the rename of Ammo. Ok.&nbsp;
1441289035
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. &nbsp;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. &nbsp;On the bright side, I talked to Riley about it and he plans to fix it shortly. &nbsp;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. &nbsp;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.
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?
1441325824
The Aaron
Pro
API Scripter
As a separate script. :)
Cool. Thanks for looking into it for me!
1441394386
The Aaron
Pro
API Scripter
My pleasure. :)
So I am having issues with this script... Here is the error: For reference, the error message generated was:&nbsp; evalmachine.&lt;anonymous&gt;:16181 total: (ird.results.total%1===0 ^ TypeError: Cannot read property 'results' of undefined at evalmachine.&lt;anonymous&gt;: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.&lt;anonymous&gt;:16178:34 at checkFinishedOps ( What is really strange is that this configuration was running several weeks ago... then just stopped working for some reason. &nbsp;Also if I select an individual token it works great. &nbsp;If I select multiple tokens it fails.&nbsp;
1442239443
The Aaron
Pro
API Scripter
Hmmm... &nbsp;I'll take a look.
Two things of interest in testing: 1) &nbsp;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: &nbsp;!group-init --add-group --Bare initiative_overall --Tie-Breaker initiative_overall) it kind of works until the problem above occurs. Thanks
1442320073
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. &nbsp;That will definitely help track down the issue.
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?
1442421548
vÍnce
Pro
Sheet Author
@{init} is the attribute. &nbsp;On phone...else I would check.
1442425196

Edited 1442427145
I must be doing something wrong.&nbsp; I'm using&nbsp; [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.&nbsp; I just upgraded to PRO today so I am a noob.
1442437381

Edited 1442437418
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&nbsp;+&nbsp;Tie-Breaker( init|current )
1442437787
The Aaron
Pro
API Scripter
The argument to --bonus is a simple number, it doesn't get evaluated as a formula. &nbsp;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
1442520322
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:&nbsp; evalmachine.&lt;anonymous&gt;:16181 total: (ird.results.total%1===0 ^ TypeError: Cannot read property 'results' of undefined at evalmachine.&lt;anonymous&gt;: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.&lt;anonymous&gt;:16178:34 at checkFinishedOps ( What is really strange is that this configuration was running several weeks ago... then just stopped working for some reason. &nbsp;Also if I select an individual token it works great. &nbsp;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
1442528875

Edited 1442528974
Aaron, thx for the help but still no go.&nbsp; I use @{selected|init} in the PF macros I use right now and they work fine.&nbsp; Just not getting it to work with your script.&nbsp; 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.&nbsp; I really just wanted it to Auto Sort the results...I'm so lazy.&nbsp; :)
1442529577
The Aaron
Pro
API Scripter
Ha. &nbsp;Ok. &nbsp;Do you want to PM me a join link and GM me and I can take a look?
1442530528
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
1442533262
The Aaron
Pro
API Scripter
Weird!