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]

1435846083

Edited 1435846128
You're just talking about reducing all the selected token's initiative's by some number, not rerolling them, right? That's very doable. I'll see if I can get that rolled in soon. We are going to play tonight, you don't have something in the very secret and special git repository already :)?
1435894293
The Aaron
Pro
API Scripter
No, I'm sorry. =( I started on it, I'm 50% finished, just haven't had a chance to finish it with all the work before the holiday. I'll try to wrap it up this weekend so you at least don't have to go another week without it!
No, I'm sorry. =( I started on it, I'm 50% finished, just haven't had a chance to finish it with all the work before the holiday. I'll try to wrap it up this weekend so you at least don't have to go another week without it! No hurry! I feel a little bit impolite constantly poking you for it already. I am just happy it is still on your task list (beside all the other projects you are working on... and real life)
1437929994

Edited 1437930691
Fine piece of work Aaron! My only issue is that it's very picky about the bonuses. In my use-case, I just want to roll initiatives for my mobs, but if I'm doing this quickly, I select everything on the token layer in the room, and run the script. Here lies the problem. My players don't have the initiative attribute that my mobs do, and this causes the script to crash and burn.  Is there a quick point to mod such that it simply won't process tokens that lack an attribute or parameter as required by the group syntax? From what I've scanned, your logic chain is stacked under the 'blue skies' assumption. I can't exactly pin point where it hiccuped, I'll check back later tonight with another look.
So for those who want it to skip tokens that lack any attribute in the syntax and have no manual bonus:                         rollSetup = _.chain(msg.selected)                             .map(function(s){                                 return getObj(s._type,s._id);                             })                             .reject(_.isUndefined)                             .reject(function(s){                                 return _.contains(_.pluck(turnorder,'id'),s.id);                             })                             .map(function(s){                                 pageid=pageid || s.get('pageid');                                 return {                                     token: s,                                     character: getObj('character',s.get('represents'))                                 };                             })                             .map(function(s){                                 var hasbonus = false;                                 s.roll=[];                                 if(s.character) {                                     hasbonus = findInitiativeBonus(s.character);                                     s.roll.push( hasbonus );                                 }                                 if(manualBonus) {                                     s.roll.push( manualBonus );                                 }                                 s.roll.push( initFunc(s) );                                 if (!hasbonus && !manualBonus)  {                                     s.invalid = true;                                 }                                 return s;                             })                             .reject(function(s) {                                 return s.invalid;                             })                             .value(); @ LN896
1437937743
The Aaron
Pro
API Scripter
So, the intent of this is to ignore tokens that are not characters when no bonus was specified?  As written above, I'm pretty sure it will ignore anyone whose bonus just happens to be 0 when the manual bonus is also 0. It would probably be better to add a config option to ignore any tokens that are not characters, do you agree?   Possibly with a subconfig to allow them if a manual bonus was specified?
1437944603
The Aaron
Pro
API Scripter
Update v0.9.7 -- Added Observable Pattern notifications (Taken advantage of by Bump v0.2.4 and higher). Other scripts can register to observe when GroupInitiative makes changes to the turn order. Sample code (from Bump): if('undefined' !== typeof GroupInitiative && GroupInitiative.ObserveTurnOrderChange){ GroupInitiative.ObserveTurnOrderChange(handleTurnOrderChange); } Registered functions currently don't receive any parameters (I'm working on a generalized solution but this is my test case.).
The Aaron said: So, the intent of this is to ignore tokens that are not characters when no bonus was specified?  As written above, I'm pretty sure it will ignore anyone whose bonus just happens to be 0 when the manual bonus is also 0. It would probably be better to add a config option to ignore any tokens that are not characters, do you agree?   Possibly with a subconfig to allow them if a manual bonus was specified? Well tokens that could be characters, but may be missing the any of the specified syntax by the 'rollable'. I just did a quick patch only realizing the error afterwards. Could this be an option? In other words, if any within the selection, are either not a character, or are missing any of the required syntax attributes, do not include them in the initiative group. This is useful for blanket adds. My players typically control their own initiatives and could start combat surrounded. Rather than selectively pick each token I know can satisfy the syntax, it would be neat if it could just reject it for me. Also the crash occurs when a token is connected to a journal/character that does not have an attribute it's looking for.
1438008666
The Aaron
Pro
API Scripter
I can certainly can set it up to ignore tokens without a represented character, no problem. " missing any of the required attributes " is problematic as every character has all of the attributes of the selected character sheet, but not as attribute objects.  That makes it impossible to tell if an attribute blank (when it comes from a character sheet). For characters that should be ignored, it would be easier to add an attribute (like groupinit_ignore) and exclude them if that is present.  I intend to overhaul the rules engine in the near future and will definitely add options like this then. As for the crash, I'll take a look at that (but probably after GenCon).
The Aaron said: " missing any of the required attributes " is problematic as every character has all of the attributes of the selected character sheet, but not as attribute objects.  I don't use character sheets in most of my games so it's a non-issue for myself. It does make sense though, but on the flip side it could also be said that those tokens are not configured which turns it into ignoring unprepared  tokens. It could be an option but that decision makes sense. In the meantime I'll write my own script to handle this case for my next session as I only figured out this error mid game.
I can confirm that if a character does not have a dexterity ability, the script crashes the API.  We do not use character sheets in my game, so I had to go and add a dex score to the over 200 characters in my journal.  Thank goodness for programmable keyboards! Hopefully Aaron develops a robust fix.  Having options for skipping bad characters, putting them into the initiative order but logging that they had no ability score, putting them into the order with 0 turn order until manually fixed, etc. 
1438040684
The Aaron
Pro
API Scripter
Bummer!!!  Sorry to hear that!!!  I'll try to get something out post haste. 
1438043875
The Aaron
Pro
API Scripter
Update v0.9.8 -- Fixed crash bug when a character doesn't have an attribute for a rule. (Thanks Ken L and Three of Swords)
1438091497
Kryx
Pro
Sheet Author
API Scripter
Aaron - does the new API support inline stuff now? Any info on an update?
1438091752
The Aaron
Pro
API Scripter
I'm not precisely sure what you mean?   It does support quoting the names of people you whisper to: sendChat('','/w "'+player.get('name')+'" a secret message!'); What inline stuff do you mean?
1438093513
Kryx
Pro
Sheet Author
API Scripter
<a href="https://app.roll20.net/forum/permalink/2121194/" rel="nofollow">https://app.roll20.net/forum/permalink/2121194/</a> That inline stuff I remember seeing an API update that contained nested stuff.
1438094190
The Aaron
Pro
API Scripter
Ah, Nested Inline Rolls, yes, that's deployed. &nbsp;I asked about it specifically in the release thread:&nbsp; <a href="https://app.roll20.net/forum/post/2212062/api-upda" rel="nofollow">https://app.roll20.net/forum/post/2212062/api-upda</a>... Riley confirmed that it is out.
1438094740
Kryx
Pro
Sheet Author
API Scripter
Does your script not need updates to support it? It'll just work?
1438094962
The Aaron
Pro
API Scripter
Correct. &nbsp;It "should" just work. I put in the patch I made for Powercards to deal with constructed queries (Bug:&nbsp; <a href="https://app.roll20.net/forum/post/2217884/api-regr" rel="nofollow">https://app.roll20.net/forum/post/2217884/api-regr</a>... ), so you should be able to put anything you like in there and it should work fine. &nbsp;I have mild concerns for the speed of parsing the rolls, but there's not much that can be done about that. I guess, give it a try and let me know if it breaks. =D
The Aaron said: Correct. &nbsp;It "should" just work. I put in the patch I made for Powercards to deal with constructed queries (Bug:&nbsp; <a href="https://app.roll20.net/forum/post/2217884/api-regr" rel="nofollow">https://app.roll20.net/forum/post/2217884/api-regr</a>... ), so you should be able to put anything you like in there and it should work fine. &nbsp;I have mild concerns for the speed of parsing the rolls, but there's not much that can be done about that. I guess, give it a try and let me know if it breaks. =D I haven't noticed any issues with speed.
1438095890
The Aaron
Pro
API Scripter
Good to hear! &nbsp;It was Devilishly slow on dev in the past. &nbsp;Riley must have tuned it up a bit. &nbsp;(I was also testing with about 30 inline expressions with 2-3 nested inlines each, so might still be slow.. =D)
The Aaron said: Good to hear! &nbsp;It was Devilishly slow on dev in the past. &nbsp;Riley must have tuned it up a bit. &nbsp;(I was also testing with about 30 inline expressions with 2-3 nested inlines each, so might still be slow.. =D) Well I haven't tested it with anything as complex as that.
1438097008
The Aaron
Pro
API Scripter
Yeah, GroupInitiative for 30 characters in Vince's Pathfinder campaign, with the nested inline rolls in the attributes. &nbsp; Brutal. =D
1438099277
vÍnce
Pro
Sheet Author
29
1438099595
The Aaron
Pro
API Scripter
Bah, close enough! &nbsp;=D
Is there a way to re-roll Initiative for all combatants in the Turn Tracker w/o selecting the tokens? &nbsp;I'd like to experiment w/ re-rolling every round, but I don't want to select everything since there are often tokens of spell effects, dead combatants, etc in the field.
1438130016
The Aaron
Pro
API Scripter
Hmm. Not yet! &nbsp;That's a great suggestion!
If you're taking suggestions... &nbsp;;) How about allowing a token to have an Ability called SetInit (or something like that). &nbsp;If a character has that ability, then their initiative value is always set to that value. It would useful in 5e D&D campaigns because Legendary creatures have Lair abilities that always occur on Initiative value 20. &nbsp;Thus I'd create a token called Lair Ability for my Journal and throw it on the board when necessary.
1438137473
The Aaron
Pro
API Scripter
That's a fantastic idea!
1438725888
The Aaron
Pro
API Scripter
Something like: !group-init --add-group --Stat-DnD dexterity --Tie-Breaker dexterity Then promote it with: !group-init --promote 2 This is one of my oldest scripts and could benefit from having the rules system revamped. Sorry.&nbsp;
Is there any way to make this work with token bars? I'm using this for SR5 (love the added functionality btw) and i use the bars for condition monitors.&nbsp; In SR your condition monitors start at 0 and count up. I put this modifier:&nbsp; " [[[[floor(0@{selected|bar1}/3)]] + [[floor(0@{selected|bar2}/3)]]]] "&nbsp; into every action where wound modifiers would apply (which is almost everything). Initiative is also affected by wound modifiers and while i'd love a way to have a character's tracker score go down as their bars go up, i'd really just like to be able to apply their wound modifiers to their initiative score when starting combat/a new round. So far the best thing i can think of is to use the modded Ammo script "Tracker" to set the value for a wound modifier attribute "e.g. @{character|woundmodifier} (I get a lot of mileage out of Tracker as a way to reconfigure cyberdecks so it's not a hard thing to do) and adjust it myself everytime their bars go up or down. Thoughts? &nbsp;
1439507225
The Aaron
Pro
API Scripter
Wow! &nbsp;Sounds complicated. &nbsp; &nbsp;So the basic idea is 2 fold: 1) Take a special formula into account which is based on the token's bars 2) And event that readjusts the tracker score when the certain conditions are met (bar value is changed). The first one is certainly doable and not overly difficult. &nbsp;The second is a bit more complicated but still possible. Neither of these is something I can work on right now, but when I rewrite the rule system, definitely something I'd like to support.
Yeah i definitely figured the second one would be a lot more work. No rush, I just didn't want to waste more time trying to do something if it can't be done right now. For now i think i'll add the wound modifier attribute to my PCs and just subtract the penalties from mooks myself. Probably just make a macro that removes the wound modifier from the selected token's tracker score. If i get really motivated i'll make it ask for a variable number of targets.
1439510517

Edited 1439510640
hmm....ran into a weird bug. I used "Tracker" to make a switch for Hotsim and Coldsim (the button is basically just a +1 or -1 to the initiative dice attribute) which changes the attribute no problem. Only thing is, now the script won't work for that token. The API crashes if i try to use the group initiative script on a token i modify using Tracker and gives me this error message. I don't get this issue if i change the attribute back by going directly into the charsheet. TypeError: Object 3 has no method 'replace' at buildInitDiceExpression (evalmachine.&lt;anonymous&gt;:1502:29) at rollers.Individual-Roll.func (evalmachine.&lt;anonymous&gt;:1543:28) at evalmachine.&lt;anonymous&gt;:2208: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.&lt;anonymous&gt;:2200:30) at eval ( :edit: Part of what worries me about this is that one of the more commonly reconfigured attributes for Matrix use also applies to the initiative bonus.
I think i might just duplicate the Charsheets and change make seperate versions of each character with the different initiative dice scores to work around this.
1439525281
The Aaron
Pro
API Scripter
Interesting. &nbsp;Can you post your Tracker macros? &nbsp;What is happening is they are adjusting (apparently) whatever attribute is your diceCountAttribute. &nbsp;Through normal setting, the attribute ends up being a string. &nbsp;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. &nbsp;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. &nbsp;The solution to this is to verify that it is a string and convert it to one if it isn't. &nbsp;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. &nbsp;The output of !group-init --help should be sufficient.
these are the macros. <a href="https://gist.github.com/downtheladder/8c18962531b5" rel="nofollow">https://gist.github.com/downtheladder/8c18962531b5</a>... I don't really know how to use a github account so i'm not sure if this is adequate or not.
1439577245
The Aaron
Pro
API Scripter
Looks good, I'll try to replicate and fix it tonight. =D
I'm not doing so good in trying to make it do what I need. I'm running D&D Basic (1981) and only use a d6 for initiative (I want the option for bonus from dex). However, even after changing the diesize to roll in the api from 20 to 6 it still rolls a d20 and it's adding the whole dexterity stat instead of the bonus. I even changed the script of attribute to 'initiative' but it still takes the dexterity stat. Help please?
1439957326

Edited 1439957392
Specifically I changed line 341 to read "attribute: 'initiative'" and 299 to "dieSize: 6," 348 to "dieSize: 6," I still get d20 on the roll adding the entire dexterity stat (not bonus). :(
I use D6 for initiative also, but it works for me.&nbsp; Try running the help (!group-init --help), and there should be a toggle in there to configure the die size.&nbsp; As far as the bonus, I don't know how to set that up - mine draws from an attribute.
1439988293
The Aaron
Pro
API Scripter
Rorary, you should never need to edit the code. &nbsp;All of the settings are accessed in the chat via the help screen: !group-init --help Once the code has run once, it sets all the defaults into the state, which is persisted and changed by the settings code. &nbsp;Changing the code won't change what is already stored in the state. There is a button for changing the die size that says Set Die Size . &nbsp;Click that and it will prompt you for the new size, put 6 in. For the attribute to add, it's a bit clunky as I have yet to replaced the system I wrote for it over a year ago. &nbsp;First you need to remove the default rule that is there: !group-init --del-group 1 Then you need to add a new attribute: !group-init --add-group --Bare initiative That should get you setup the way you want it.
You guys are the best! I can see so much more clearly once I've pulled my head out of my ass:)
1439991625
The Aaron
Pro
API Scripter
No problem. &nbsp;=D &nbsp; Actually, this illustrates that I need to do a better job of directing people to the in game help. &nbsp;Probably should add a readme with that info at the very least (I keep planning to duplicate the info in the readme and the wiki, but there's just not enough time in the day!).
Just the fact that you have inline help, and have worked hard to make your scripts usable by total coding idiots (like myself) is already a huge step above. &nbsp;Thanks for your hard work for the rest of us.
Just one more question. I use an api to import monster stats and it creates an attribute "npc_dexterity". I've tried to create a group for this attribute but it's not working. Options tried, "!group-init --add-group --Stat-DnD npc_dexterity|current" and "!group-init --add-group --Stat-DnD npc dexterity|current" neither of which is adding their bonus to the roll even though both options 'create' named group.
1440007568
The Aaron
Pro
API Scripter
When you add groups, it appends them to the end of a list. &nbsp;It starts considering them at the top of the list and works down. &nbsp;The first one that is able to produce a value is used. &nbsp;Run the help again and look to see if there is one earlier in the list that is still being used. !group-init --help You can remove any groups by supplying it's index: !group-init --del-group 1 or just swap the order by move one up: !group-init --promote 2 Stat-DnD will apply the DnD 3.0 and up calculation to the specified attribute, so (Attr/2)-5 or some such. &nbsp;That probably isn't what you want for Basic DnD. &nbsp;If you can write a formula for it, you can put it in an attribute and use it with the --Bare attribute command, otherwise, you'll either need to calculate it and put it in for each character, or we might be able to come up with some other options. &nbsp;Try the above and see if it gets you closer to what you need.
OK. So, what if my player characters have a 'dexterity' attribute but my api used to pull in monsters/npc's has npc_dexterity. Will it do both or because the character's attribute is first it uses that one and doesn't bother to do the npc's since their's is labeled different? I.e. can only one be used at at time? Thus, I should group the pc's and the npc's separately to roll seperatelY?
1440011966
The Aaron
Pro
API Scripter
No, both can be used, but you have to setup the first rule to only match in one case. The easiest thing to do is add an attribute manually to your PCs named something like pcinit with a value of 0. &nbsp;Then you setup the first rule to include it as part of the expression: !group-init --add-group --Stat-DnD dexterity --Bare pcinit Second group without it: !group-init --add-group --Stat-DnD npc_dexterity The PCs with the pcinit attribute will match the first rule and get the bonus from it, the monsters who don't have that attribute will fail the first rule and fall through to the second one.