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] AttrInit a simple group initiative script using an attribute as a bonus

1438049184

Edited 1438128901
update 0.5: Added !agi -calc [attr] which will perform all nested operations needed allowing you to have an attribute that looks like this: 6*(5d3)+floor(([[6d2+@{numa}]]+@{numb}+@{akvan|numc}+@{random})/8)+3d12 Even if the attributes don't exist, or exist on other journals etc. It can meat grind it into a usable modifier. This version simply delegates much of the resolution to the roll engine so it'll hammer the server with messages. The performance penalty is directly related to how busy the server is (negligible unless you're doing over 30 tokens) , hence why !agi [attr] will always be faster for simple cases as it uses a single message. A simple script that rolls initiative for a group of tokens using an attribute as a bonus. If the attached journal to a token has the attribute, and if it's numeric, then it will be included in the initiative tracker. All tokens that do not have an attached journal or have an journal without the searched for attribute, it will ignore. It's a simple, minimal, fast, script. For more functionality, see Aaron's  GroupInitiative script.   SCRIPT: Github Link
1438050784
The Aaron
Pro
API Scripter
Cool!  GroupInitiative started out very simple, but oh how it has grown.  I'm sure many will appreciate a simple alternative.  (And competition is good for the consumer!  =D )
Not really planning on it being any bigger than this. Pretty much just like Growit.
1438091213

Edited 1438091561
Kryx
Pro
Sheet Author
API Scripter
Does this work on calculated fields from a character sheet? Does it work with inline roll stuff? For example [[@{initiative_bonus} + @{other_bonus}]]
Mark said: Does this work on calculated fields from a character sheet? Does it work with inline roll stuff? For example [[@{initiative_bonus} + @{other_bonus}]] Nope, but that's simple enough that I can add it for tonight. It'll probably not get any more complex than that. The whole point of this script is that it's light weight compared to all the heavy stuff out there.
1438092456
The Aaron
Pro
API Scripter
It does not.  Line 73: bonus = bonus.match(/\+*\-*\d+/); will only accept attributes which contain an integer preceded by 0 or more + or - signs: 0 1 -1 +10 which it then calls parseFloat() on to get a value. As an aside, it will also match some pretty strange constructs, which is why the isNaN() check on line 74 is needed.  A more robust regular expression for matching valid bonuses would probably be: bonus = bonus.match(/^\s*(-|\+)?\d+(\.\d*)?$/); which will only match valid floats in standard form.
You can make it pop open the turn order tracker too.  if (!Campaign().get("initiativepage")) Campaign().set("initiativepage", true);
1438127302

Edited 1438128887
update 0.5: Added !agi -calc [attr] which will perform all nested operations needed allowing you to have an attribute that looks like this.. or worse: 6*(5d3)+floor(([[6d2+@{numa}]]+@{numb}+@{akvan|numc}+@{random})/8)+3d12 Even if the attributes don't exist, or exist on other journals etc. It can meat grind it into a usable modifier. This version simply delegates much of the resolution to the roll engine so it'll hammer the server with messages. The performance penalty is directly related to how busy the server is (negligible unless you're doing over 30 tokens) , hence why !agi [attr] will always be faster for simple cases as it uses a single message.
The Aaron said: As an aside, it will also match some pretty strange constructs, which is why the isNaN() check on line 74 is needed.  A more robust regular expression for matching valid bonuses would probably be: bonus = bonus.match(/^\s*(-|\+)?\d+(\.\d*)?$/); which will only match valid floats in standard form. A NaN check is computationally faster than throwing more regex, not by much; but I deal with low level systems so it's a habit. Given the odd nuances of javascript I may be wrong but it's fine as is. HoneyBadger said: You can make it pop open the turn order tracker too.  if (!Campaign().get("initiativepage")) Campaign().set("initiativepage", true); You can; the script is short, sweet and self-documenting. I didn't do this on purpose as perhaps other people are using their own tracker script (as I do) or want it simply to do the minimum, which is this script's goal.
Thank you ;_;!
1438727045
Kryx
Pro
Sheet Author
API Scripter
Would be great if you could include a tie breaker. For example on 3.X you use initiative and then any ties uses the highest initative modifier. For roll20 that means you would use initative modifier plus initiative modifer/100.
Mark said: Would be great if you could include a tie breaker.  I'll probably add that, but that would be the limit. Any more feature creep and it'll become too bloated. Aaron's script is more fully featured in that regard.
1438734472
Kryx
Pro
Sheet Author
API Scripter
Awesome. That's all that is needed for basic group initiative imo.
1439506842
Kryx
Pro
Sheet Author
API Scripter
Any update on adding a tie breaker?
Mark said: Any update on adding a tie breaker? Not yet, I've been using my roll20 script time to build a turn tracker script that tracks status durations. It kinda grew into supporting favorites so you could say 'favorite' a poison effect so you could easily apply the status to a group of tokens, edit them individually or in group etc... I'll see what I can do tonight but there's also some open tickets for a few other foss projects I'm in.
1439507569
Kryx
Pro
Sheet Author
API Scripter
I wonder if it might be easier for me to just roll the token macro from my sheet. I think that is possible, right? I have a nice selected tokens function and with each token could then call a sheet macro - though I'm not sure I've ever done that it should be possible.
Mark said: I have a nice selected tokens function and with each token could then call a sheet macro - though I'm not sure I've ever done that it should be possible. I don't think you can access sheet macros (as least as far as I know). I know that sheet attributes are different from actual existing attributes (this script doesn't get a sheet calculated attribute unless it creates a real attribute and puts a value there).
I am using the 3.5 character sheet and am trying to integrate this script into it, but every time I type !agi init it does nothing.  I am a complete noob here, so it's likely my fault.  One thing I have noticed is that the 3.5 character sheets do not have an "init" attribute (there is an npcinit for NPCs and the sheet itself for PCs has an init box, but no attribute called init). I create sample 'testinit' attributes and ran '!agi testinit' but that did nothing as well.
1441871910
Ziechael
Forum Champion
Sheet Author
API Scripter
If the API is completely unresponsive rather than throwing an error into the chat window make sure to check your API console (on the game details page under 'settings>API Scripts'). It may be that your console has crashed in which case a simple 'save script' will refresh the sandbox and hopefully get you up and running. If it still fails to work check the console again to see if running the command has caused the crash in which case there may be a fault with your script (an old version, a mistake in copying it or an accidental amendment when installing it). If none of that helps there may be a deeper issue that the author will easily be able to help with (these guys with their magic code are awesome!).
Thanks.  That did it.  I just disabled and re-enabled the script and everything works.   I am currently using the 3.5 character sheet which is a bit of a pain because PCs do not have an init attribute; however, they do  have an init on the character sheet.  How can I access that init on the character sheet for these PCs?  Another frustration with the 3.5 sheet is that NPCs have a completely different attribute, called npcinit, for initiative.  Why the NPC sheet has npcinit listed as a usable attribute and the PC sheet does not have init as a usable attribute baffles me.
1442083994

Edited 1442084089
Roy S. said: I am currently using the 3.5 character sheet which is a bit of a pain because PCs do not have an init attribute; however, they do  have an init on the character sheet.  How can I access that init on the character sheet for these PCs? AttrInit only looks at real attributes that appear in the attributes section as opposed to the sheet. The reason for this was personal as I had a need to disregard 'unconfigured' character sheets where I would create a 'character' journal but not populate it. In this case, if I blanket selected these unprepared tokens along with tokens I desired to roll for, it would ignore them and only roll for the desired lot. I put that fix on my to-do list, it should be relatively minor but I'm wrapped up at the moment so it could be some time before I get to it. The group initiative script by TheAaron looks for sheet attributes (link in the initial posting). I personally don't use sheets so I didn't have the need for it.