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] getAPL - Average Party Level (APL) and assigning Party Strength for 5e AL Games

1509049877

Edited 1509054461
GrumpyOldDM
Sheet Author
getAPL allows a DM to select PC tokens and auto calculate the party APL and strength for Adventure League Games . Commands: !getAPL (target APL 1-20) The Script will kick back your number of players (based off the # of PC tokens selected), current APL, party strength (very weak, weak, average, strong, very strong), and target APL. getAPL Github: &nbsp; <a href="https://github.com/GrumpyOldDM/getAPL" rel="nofollow">https://github.com/GrumpyOldDM/getAPL</a> Raw Script: <a href="https://raw.githubusercontent.com/GrumpyOldDM/getAPL/master/getAPL.js" rel="nofollow">https://raw.githubusercontent.com/GrumpyOldDM/getAPL/master/getAPL.js</a>
1509051180
The Aaron
Pro
API Scripter
Nice! You might be interested in this more succinct check for a number from 1-20: _.range(1,21).includes(parseInt(args[1],10)||0);
The Aaron said: You might be interested in this more succinct check for a number from 1-20: _.range(1,21).includes(parseInt(args[1],10)||0); Nice, I didn't realize JavaScript had a builtin range function - that makes it much cleaner! I added it as well as a fix for no tokens being selected throwing an undefined error&nbsp; to version 1.1
1509054928

Edited 1509108718
The Aaron
Pro
API Scripter
It doesn't, but Underscore.js does, which is what that _ is.&nbsp; Underscore is included in the API, you can read up on it at <a href="http://underscorejs.org" rel="nofollow">http://underscorejs.org</a> . You can do this with Javascript ES6 but it's a bit uglier: Array.from(Array(20), (_,i)=&gt;1+i).includes(parseInt(args[1],10)||0);
1509055011
The Aaron
Pro
API Scripter
This is a nice Underscore to ES6 reference:&nbsp;<a href="https://www.reindex.io/blog/you-might-not-need-underscore/" rel="nofollow">https://www.reindex.io/blog/you-might-not-need-underscore/</a>
1509105965
Jakob
Sheet Author
API Scripter
I'd prefer [...Array(21).keys()].slice(1) which is a bit less ugly.
1509107726
The Aaron
Pro
API Scripter
Ah, good point!&nbsp; Their solution supports a starting number (which I just replaced with the 1 constant for the example).&nbsp; The spread operator is awesome. =D
1509108177
Jakob
Sheet Author
API Scripter
The Aaron said: Ah, good point!&nbsp; Their solution supports a starting number (which I just replaced with the 1 constant for the example).&nbsp; The spread operator is awesome. =D This one does too, the 1 in slice(1) is the starting number! To be fair, the linked article is a Underscore to ES5 article, so it makes sense that it wouldn't take advantage of spread awesomeness.
1509108479
The Aaron
Pro
API Scripter
Yeah, though performance might make you choose the former method if you're starting at a good sized number. =D
1509109153
Jakob
Sheet Author
API Scripter
The Aaron said: Yeah, though performance might make you choose the former method if you're starting at a good sized number. =D Fair enough. You could use .map(), but then it's essentially the same ugliness level as your example :).
1509109590
The Aaron
Pro
API Scripter
I'd just hide it in a function. =D
1509109807

Edited 1509109816
Jakob
Sheet Author
API Scripter
The Aaron said: I'd just hide it in a function. =D Like _.range()? :P
1509110606
The Aaron
Pro
API Scripter
You read my mind! =D
It is like seeing two aliens talk, you know they are using words, but it means nothing in english...
1509318177
The Aaron
Pro
API Scripter
=D