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 .
×
Advertisement Create a free account

[Script] Paladin Aura 5E D&D API

1598343036

Edited 1623758942
Layton
API Scripter
Paladin Aura   A Roll20 API that automatically shows when a token is in range to receive a Paladin's aura-bonus, and reminds users in the chat when the bonus should be applied. Available on the Roll20 one-click API menu! Depreciated version (not optimized enough to work p roperly): Roll20 Forum | GitHub Links GitLab Repository Download the JS Notes If you are an API developer: I am trying to get this API onto the Roll20 API Repository. Please pass on any advice you may have. The API is only compatible with the Roll20 D&D 5E OGL Sheet. The API only runs on the player-ribbon page and only if the grid-type is square. Distances are calculated depending on the "measurement" setting of the page. Large and small tokens are accommodated. If a token that represents a character is manually included / excluded from a paladin's aura, it will apply to all of that character's tokens. For more, see Aura-Bonus Inclusions / Exclusions. Usage The API requires next-to-no user input. By default, measurements are calculated based on the page measurement settings, and any token that represents a non-npc will be granted a paladin's aura bonus. Aura-Bonus Inclusions / Exclusions The paladin aura can be toggled for any token by the paladin. To do so, select the paladin token, and use the character ability that appears at the top of the screen: ~ToggleAuraTarget You will be prompted to select a target. Once you do so, whether the target is affected by the selected paladin's aura will be toggled. If the target has a character sheet, this will also apply to any other tokens representing that sheet. Saving Throws When a saving throw is made using the Roll20 5E OGL Sheet template (even if the roll came from the Beyond20 browser plugin) the API will try to find a token who's name contains the first name of the name attached to the roll template. Upon finding one or more token(s), it will post to chat to remind the player of the aura-bonus. Issues Either leave a message on this API Forum Post or a New Issue Report on GitLab and I'll reply as soon as I can. Updates 1.0.3 - Reduce chat error output on pages that are not compatible when users start drawing. 1.0.2 - Character sheet saving throws are now detected. 1.0.1 - Improve chat output when a page is loaded. Previews (click images to play)      
1598364335
Looks fantastic!
1598392248

Edited 1598392323
Works great, I especially like that it works with Beyond20 . Gj
1600077591
Layton
API Scripter
Updated to 1.0.3 Reduced error outputs.
1601977599

Edited 1601977650
Joe
Pro
Hi there, I applaud your putting PaladinAura into the one-click install API library, but when I switch to this one vs. the deprecated version (from June 5th, 2020), I get the following errors when my sandbox spins up: TypeError: Cannot read property 'search' of undefined TypeError: Cannot read property 'search' of undefined at apiscript.js:18533:24 at Array.find (<anonymous>) at charIsPaladin (apiscript.js:18531:41) at new TokenObj (apiscript.js:18369:42) at apiscript.js:19188:34 at Array.forEach (<anonymous>) at pageLoad (apiscript.js:19187:24) at Object.startup [as Startup] (apiscript.js:19147:9) at apiscript.js:19235:17 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16)
1607104399
Dodo
Pro
Im having this issue as well so I went to an older version and that worked until I kept getting an infinite loop error
1607106618
Dodo
Pro
TypeError: Cannot read property 'search' of undefined TypeError: Cannot read property 'search' of undefined at apiscript.js:9237:24 at Array.find (<anonymous>) at charIsPaladin (apiscript.js:9235:41) at new TokenObj (apiscript.js:9073:42) at apiscript.js:9887:34 at Array.forEach (<anonymous>) at pageLoad (apiscript.js:9886:24) at Object.startup [as Startup] (apiscript.js:9846:9) at apiscript.js:9934:17 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16)
1607112741

Edited 1607112771
Hi. I spent a bit of time trying to help Dodo out. I've never touched the roll20 api, but I've done a good amount of JavaScript dev before  So I took a look at charIsPaladin and the issue is that in const palClass = classesToCheck. find ( c => {             const val = getAttrByName ( charID , c ) ;             return val. search ( /paladin/gi ) !== - 1 ;         } ) ; val in some circumstances (it worked on some pages and not others -- interestingly, the pages it was crashing on had an animated background, but I don't know if that could even possibly be related)  comes back as something falsey. I added a check before the return if (!val) {return false;} and that prevented the crash, but there's another issue in that case -- while the badge is applied to the token, when a saving throw is made, nothing is appearing in chat to imply that the bonus itself is being applied. Unfortunately, this is the first time I've ever so much as looked at the Roll20 API, so I don't know how helpful that was or not
1607132089

Edited 1607132766
Nice one Emily, that will sort out the error. It's also probably worth finding out where the error is coming from - it looks like there are two options: bad character ID, or one of the Attributes is not present on the sheet. If we add a bit of debugging to it: function charIsPaladin(charID) { if (getObj('character', charID)) { const multiclasses = []; const classesToCheck = ['class']; ['multiclass1', 'multiclass2', 'multiclass3'].forEach(a => { multiclasses.push(getAttrByName(charID, a + '_flag')); }); multiclasses.forEach(a => { if (a === '1') { classesToCheck.push(a); } }); const palClass = classesToCheck.find(c => { const val = getAttrByName(charID, c); if (!val) { sendChat('PaladinAura', `/w gm Attribute: '${c}' not found on charId: ${charID}`); return false;} return val.search(/paladin/gi) !== -1; }); if (palClass === 'class') return true; else if (palClass !== undefined) return palClass; else return false; } else { sendChat('PaladinAura',`/w gm Error: bad charID: ${charID}`) return false; } } It'll probably give some hints as to where the issue is. I'm not using the script at all (or DMing anything for that matter) so probably not much help on that front. At a guess, it's a bad charID from somewhere else in the script, or sheets can be created without a 'class' attribute (e.g. some NPC sheets).
1607197616

Edited 1607199006
Layton
API Scripter
Emily  and  Oos h I'm currently finishing College (Computer Science with Math and Further Math all in UK A-Levels) so I don't have time to work on this API right now. That said, I'll add Oosh's change to the One-Click and Master branches. Thank you both :) Edit: I've submitted the changes but they usually take time to go through.
Oh, I just suggested those sendChat lines temporarily to find out where the error is creeping in from, so it can be fixed properly - Emily stopped it crashing, but said bonuses aren't being applied to saving throws further down the line.
1607212543
Layton
API Scripter
Oosh said: Oh, I just suggested those sendChat lines temporarily to find out where the error is creeping in from, so it can be fixed properly - Emily stopped it crashing, but said bonuses aren't being applied to saving throws further down the line. Bonuses were never applied to saving throws, there was simply a chat output to remind people that bonuses should  be applied. This fix is about all I have time for, but if you really wanna get it working I'm happy to push a better fix through.
1607213613

Edited 1607213680
Ohhhhh ok, sorry I haven't actually used the script, I was just making a suggestion so someone could get some more info on the error next time the it happens. I also misread Emily's post - all she said was that the reminder isn't appearing in chat after this happens, nothing about bonuses being applied. That was me making stuff up.
1609474897
GM
Pro
getting this error in API Sandbox. "Error: No attribute or sheet field found for character_id -MBBG8lsUHMpwGXdB8SE named 1"
1609980146
Joe
Pro
I really like the “just works” of the latest 1.1 version, putting a reminder in chat is plenty useful for me. Thank you for fixing the crashing! I am getting these errors when I start up in my new game with the 1.1 version one-click installed. This new game was a copy of a game that was using the older 1.0.x version. (From PaladinAura):  Attribute: '1' not found on charId: -KTycuDdXdCIoGEmGV_b (From PaladinAura):  Attribute: '1' not found on charId: -KTycuDdXdCIoGEmGV_b (From PaladinAura):  Attribute: '1' not found on charId: -KTycuDdXdCIoGEmGV_b (From PaladinAura):  Attribute: 'class' not found on charId: -KzPaFBR9Nqn5zxrVgtR (From PaladinAura):  Attribute: 'class' not found on charId: -M7PrVRlRjzEPCFQ64UU Then it said it was ready.  Any idea what it going on?  I will say that it seems to be working fine, so it’s only a little annoying that it is filling chat with whispers each time.
1610234903
Layton
API Scripter
Joe said: I really like the “just works” of the latest 1.1 version, putting a reminder in chat is plenty useful for me. Thank you for fixing the crashing! I am getting these errors when I start up in my new game with the 1.1 version one-click installed. This new game was a copy of a game that was using the older 1.0.x version. (From PaladinAura):  Attribute: '1' not found on charId: -KTycuDdXdCIoGEmGV_b (From PaladinAura):  Attribute: '1' not found on charId: -KTycuDdXdCIoGEmGV_b (From PaladinAura):  Attribute: '1' not found on charId: -KTycuDdXdCIoGEmGV_b (From PaladinAura):  Attribute: 'class' not found on charId: -KzPaFBR9Nqn5zxrVgtR (From PaladinAura):  Attribute: 'class' not found on charId: -M7PrVRlRjzEPCFQ64UU Then it said it was ready.  Any idea what it going on?  I will say that it seems to be working fine, so it’s only a little annoying that it is filling chat with whispers each time. I'm really glad that update has sorted the crash!  The API should run fine, but some tokens (I haven't investigated which) keep causing an error. The whisper is made whenever the workaround (see above in other messages) is required. I'll remove the whisper ASAP and things should run smoothly from there. Honestly, it was a bad idea to keep the whisper in; I was rushing when I added the update. Due to the Roll20 update rollouts, expect the update within the next 1-2 weeks.
1610235712
Joe
Pro
Thanks so much!  I appreciate that. My party’s paladin just hit level 18 and the transition to 30 foot auras was instant and seamless, so great! :-) Players expressed appreciation of the nice auto-post to chat when it applies, also. 
1610434464

Edited 1610435688
Layton said: The API should run fine, but some tokens (I haven't investigated which) keep causing an error From what was posted above, it looks like the first problem is NPC's not being created with the 'class' attribute... getting rid of the sendChat is all that's needed there, as you said (you could also exit the function early with an NPC check... I don't think it will be any more efficient though, it still needs to string search an Attribute for that, and people might be using Pally NPCs that need the bonus). The "'1' Attribute not found"  is more of an issue. I think this part is the problem: ['multiclass1', 'multiclass2', 'multiclass3'].forEach(a => { multiclasses.push(getAttrByName(charID, a + '_flag')); }); multiclasses.forEach(a => { if (a === '1') { classesToCheck.push(a); } }); The getAttrByName is only returning the current value from the multiclassX_flag Attribute, and the multiclasses.forEach() part is then returning "1" (the value) instead of "multiclassX" (the name) of the Attribute. I just did a quick test and the script wasn't working at all with multiclass... though I might be doing something wrong as I'm not familiar with it. That would make sense though, as I don't see how the multiclassX Attribute names are getting passed down to the /paladin/gi regex search at all, and it would explain why it's searching for an Attribute named '1'. Replacing it with this should fix it, I think: ['multiclass1', 'multiclass2', 'multiclass3'].forEach(a => { let x = getAttrByName(charID, a + '_flag'); if (x && x == '1') classesToCheck.push(a); }); (and also getting rid of the sendChat... maybe leave a log() in there to make sure multiclasses are being picked up though? Not sure... ). Hopefully that gets rid of the errors, and gets multiclasses working. edit - Just did a quick test and it seems to work fine with that change... after some confusion. My test game has all kinds of crazy settings for characters, and the one I picked for a paladin multiclass happened to have the Proficiency Die variant switched on. This breaks the template search in your handeInput() function. A very minor change that would fix that (very few people use the rule, likely as not it will never be an issue) would be to change the first conditional on line 109 from msg.rolltemplate === 'simple' to msg.rolltemplate.match(/simple/i) (or any other kind of string search you like), as the Proficiency Die rule variant uses a template called simple3D. Really though.... pretty much no one uses the rule :)
1610706493

Edited 1610707121
Layton
API Scripter
Oosh said: A lot of things Looking it over that definitely seems to be the issue! Fantastic job finding it. I think I'll leave the fix as it is now and just remove the chat notification. About your fix with multiclassing - I swear I'd tested it but honestly my code looks wrong  and yours looks like it'll work. If you say you've tested it I'll trust that and put it in now. Big thanks for keeping a project I've neglected running smoothly :) EDIT: I've queued all the updates (log removal and multiclass fix) for merging. They should go through within 2 weeks.
1610707314
Layton
API Scripter
Joe said: Thanks so much!  I appreciate that. My party’s paladin just hit level 18 and the transition to 30 foot auras was instant and seamless, so great! :-) Players expressed appreciation of the nice auto-post to chat when it applies, also.  It's so nice to hear people are using the API :D congrats to you and your players for getting to 18th level!
1611326048

Edited 1611326097
Layton
API Scripter
Updates should now be live on the one-click-install! :)
1611329222
Joe
Pro
Thanks again!
Hello,  I recently tried using this in my campaign, but I don't think it's functioning entirely as it should for me, to my understanding. It puts a bolt shield 3 marker on the tokens within the radius, but it doesn't post a bonus reminder to chat when the marked tokens make a save, nor does it add bonus to the roll. Am I missing something?  Thanks in advance. 
1614722980
Layton
API Scripter
Rocklobster said: Hello,  I recently tried using this in my campaign, but I don't think it's functioning entirely as it should for me, to my understanding. It puts a bolt shield 3 marker on the tokens within the radius, but it doesn't post a bonus reminder to chat when the marked tokens make a save, nor does it add bonus to the roll. Am I missing something?  Thanks in advance.  It should not  add any bonuses to any rolls, but a reminder should post to chat when an affected token makes a saving throw, yes. Why it's not doing that could be due to any number of reasons, and I'm currently in college and so don't have time to work on this API at the moment. I hope you can find a way to get it working!
1616264772
I get a few of different error: -Most of the time i get: The selected token is not registered as a paladin. Try restarting the API if this is an error. afther 20 restart and continue to make new token of the paladin i got it working but only for the paladin and if i try to toggle the aura for someone else i get: (From PaladinAura): Attribute: '1' not found on charId and then i have to make another 20 restart for try it again....
1616431439
Layton
API Scripter
Hi master, sorry to hear its causing you so much trouble!  Can you please confirm for me, what character sheet template are you using? 
I know this ALL is for 5E OGL sheet but would it be possible for someone (including myself) to go into the code and tweak it for other similar systems?  It sounds like the premise could be app!did to a variety of aura based abilities, such as fear, inspiration, protection, damaging auras etc but I'm completely a level 0 (or lower) coder.
1618508529
Layton
API Scripter
Peacekeeper B said: I know this ALL is for 5E OGL sheet but would it be possible for someone (including myself) to go into the code and tweak it for other similar systems?  It sounds like the premise could be app!did to a variety of aura based abilities, such as fear, inspiration, protection, damaging auras etc but I'm completely a level 0 (or lower) coder. I actually started learning to code just so I could make Roll20 APIs - if you're considering getting started then I'd strongly recommend going for it. That said, adapting this module to other systems is not the easiest or best idea, and here's a bit of a rundown as to why: Most of the module is dedicated to finding and storing user-character data in an efficient way, so that the Javascript system can quickly measure distances between the paladins and other characters without constantly asking Roll20 for more information. Looking past that and just thinking of auras in a more general sense, sure one could create a system that lets the gm set an icon representing fear and set tokens to emit a "fear aura" using the same distance calculations I've used in this system, but then half the code in this system would need to be replaced. And really, half is an understatement. My advice is that if you're interested in coding just give it a go and see if you enjoy it. Personally I found myself hooked and I'm now going to university to study Artificial Intelligence. Roll20 is a great place to start. If this was more a question about whether I could just easily get that ready for you and others to use, the answer is no.
1620864468

Edited 1620864639
Ven
Pro
Master said: I get a few of different error: -Most of the time i get: The selected token is not registered as a paladin. Try restarting the API if this is an error. afther 20 restart and continue to make new token of the paladin i got it working but only for the paladin and if i try to toggle the aura for someone else i get: (From PaladinAura): Attribute: '1' not found on charId and then i have to make another 20 restart for try it again.... I'm getting this same issue however I've never gotten it to work. I double checked and I am using the Roll20 D&D 5E OGL Sheet and I've tried removing the paladin token and readding it and connecting it to the paladin's sheet. I'm still new to APIs so am I missing something?
1620977300

Edited 1620977321
Layton
API Scripter
I'm getting this same issue however I've never gotten it to work. I double checked and I am using the Roll20 D&D 5E OGL Sheet and I've tried removing the paladin token and readding it and connecting it to the paladin's sheet. I'm still new to APIs so am I missing something? It's most likely it's just my bad code, but I've no longer got a roll20 pro account, so I can't test it. If the API isn't working for you, I recommend finding an alternative. If I get time I'll come back to the project in a month or so and post here as and when any fixes are released.
1621403428
Ven
Pro
Layton said: I'm getting this same issue however I've never gotten it to work. I double checked and I am using the Roll20 D&D 5E OGL Sheet and I've tried removing the paladin token and readding it and connecting it to the paladin's sheet. I'm still new to APIs so am I missing something? It's most likely it's just my bad code, but I've no longer got a roll20 pro account, so I can't test it. If the API isn't working for you, I recommend finding an alternative. If I get time I'll come back to the project in a month or so and post here as and when any fixes are released. Ah, ok. Thanks for the heads up! I think it might be something on my end since people have been using it fine. 8) I'll deal.