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

Comparing/sorting attributes from multiple character sheets

Hello everyone! I've just started using the API and have been reading a lot from the wiki and forums the past few days. First off, there is a lot of awesome information out there, so thank you to everyone who has taken the time to explain things so well. It has been very helpful. Second, it has been about a decade since I've done a substantial amount of coding, so my skills are very rusty. As a result, I was hoping to see if anyone had a script already before I spent the work to get the rust out of my skills and attempt to write the script myself. So with that introduction, here is what I am wanting to do. I would like to call the same attribute from all of the player character sheets, either sort or compare them, and then have it tell me which is the highest or lowest. Ideally, I would like to be able to build macros that could speak to me as GM or to all of the players. So I imagine there would need to be some way to pull the character name, keep it attached to the attribute value, and then return the character name as the output. For example, there are times when I will give a player with the highest passive perception the option of noticing something first if no one else is actively looking. Instead of memorizing everyone's stats, using the token macro for each character, or looking it up on their character sheets, I would like to have a macro in place to do this comparison. Does anyone have something like this already? If not, I will dig up my coding skills and see if I can put this together. Thanks for any feedback.
1424200362
Gen Kitty
Forum Champion
I suggest eyeballing The Aaron's Group Initiative script for ideas on how to do this. It lets you select a bunch of tokens and then looks up their init bonus. It then does things that you don't need, but you can use that framework as a possible launch point for your own script. Good luck, and happy coding! (Always nice to see another fledgling taking his first steps towards becoming a Scriptomancer!)
1424200412
The Aaron
Pro
API Scripter
I don't think I've seen a script that does that, but it should be pretty easy to write. You'll need a way to know which characters are players and which are monsters/npcs. After that, it would just be a matter of finding all the characters, then finding all the attributes with the correct name for those characters, then sort them and displsy them as desired.
Thanks for the feedback. I'll have to sneak in some coding without garnering too much wife aggro. ;-)
1424201761
The Aaron
Pro
API Scripter
Wife aggro is definitely one of the risks of Arcane Scriptomancy!!
1424231747
Lithl
Pro
Sheet Author
API Scripter
Here's something off-the-cuff: var myAttributeName = 'foo', attrCache = {}, playerIds = _.map(findObjs({ type: 'player' }), function(player) { return player.id; }), playerCharacters = _.chain(findObjs({ type: 'character' })) .filter(function(chr) { var controller = chr.get('controlledby'), attr = findObjs({ name: myAttributeName, characterid: chr.id })[0]; if (attr) { attrCache[chr.id] = attr; } return controller && attr && _.contains(playerIds, controller); }).sortBy(function(chr) { var attr = attrCache[chr.id]; return parseInt(attr.get('current'), 10); }).value(); // playerCharacters[0] is the character with the minimum value for the attribute // playerCharacters[playerCharacters.length - 1] is the character with the maximum value for the attribute // attrCache[id] holds a reference to the attribute itself, where id is a character id