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

Coding question hope someone can help NPC/Player Spell lookup macro

Hi all by no means am I good at coding and all that. But I play around with it and I was wondering if there is a way to have a lookup find how many cantrips, 1 st level ect… spells a NPC or selected player has and have it show in the chat. This is what I have as on now, I wanted to see if you can call up an attribute like “spells_count_cantrip” to get the count of cantrips and have the macro just get that amount so I do not get errors like the one in the screen shot " selected|repeating_spell-cantrip_$4_spellname" . Thanks w gm &{template:default}{{name=@{selected|character_name} Spellcasting }}{{ Spell DC [[@{selected|spell_save_dc}]] = +[[@{selected|spell_attack_bonus}]] spell attacks }}{{ Cantrips = [@{selected|repeating_spell-cantrip_$0_spellname}](~selected|repeating_spell-cantrip_$0_spell)[@{selected|repeating_spell-cantrip_$1_spellname}](~selected|repeating_spell-cantrip_$1_spell) [@{selected|repeating_spell-cantrip_$2_spellname}](~selected|repeating_spell-cantrip_$2_spell) [@{selected|repeating_spell-cantrip_$3_spellname}](~selected|repeating_spell-cantrip_$3_spell) [@{selected|repeating_spell-cantrip_$4_spellname}](~selected|repeating_spell-cantrip_$4_spell) }}{{ 1st (SLOTS) = [@{selected|repeating_spell-1_$0_spellname}](~selected|repeating_spell-1_$0_spell) }}{{ 2nd (SLOTS) = [@{selected|repeating_spell-2_$0_spellname}](~selected|repeating_spell-2_$0_spell) }}{{ 3rd (SLOTS) = [@{selected|repeating_spell-3_$0_spellname}](~selected|repeating_spell-3_$0_spell) }}
1631329499
timmaugh
Forum Champion
API Scripter
Built in? No. But there are scripts that can help. InsertArg can do what you're looking for. You would basically instruct it to get the cantrips (and/or slots), and produce a button for each. InsertArg produces its own menu, so it wouldn't be a roll template anymore. Here is an example where I used it to produce a menu of attributes (which represented character injuries). Another option would be a combination of metascripts like Muler, Plugger, APILogic, ZeroFrame, and Fetch, which could work right in your roll template. The basic idea would be to retrieve a muled variable that would be an APILogic test. If we could Fetch a cantrip at the position of the muled variable (which we would increment at every pass using Plugger), then we would return the API button syntax to the command line *as well as* ANOTHER retrieval of that same variable (which would test the next incremented muled variable). The only way that loop stops is if there isn't a cantrip, so we return nothing. In the end, we've plugged a button into the roll template for each cantrip. If you want an example of that, I can try to put one together tomorrow.
What character sheet are you using? (E.g. ‘D&D 5E by Roll20’ or something else?) Do you want a list of all the spells or just a number of how many spells are known for each level? Do you want a list of all spells or just prepared spells or both? Do you want a non-API solution or an API solution?
1631337155
GiGs
Pro
Sheet Author
API Scripter
Since you're a Pro user you could install the Universal Chat Menu script in the second post here: <a href="https://app.roll20.net/forum/post/7474530/script-call-for-testers-universal-chat-menus/?pagenum=1" rel="nofollow">https://app.roll20.net/forum/post/7474530/script-call-for-testers-universal-chat-menus/?pagenum=1</a> Then run a macro like !chatmenu @{selected|character_id} @{selected|character_name}'s Spellcasting --title:Cantrips --repeating_spell-cantrip|spellname|spell --title:1st (SLOTS)&nbsp; --repeating_spell-1|spellname|spell --title:2nd (SLOTS)&nbsp; --repeating_spell-2|spellname|spell --title:3rd (SLOTS)&nbsp; --repeating_spell-3|spellname|spell --title:4th (SLOTS)&nbsp; --repeating_spell-4|spellname|spell --title:5th (SLOTS)&nbsp; --repeating_spell-5|spellname|spell --title:6th (SLOTS)&nbsp; --repeating_spell-6|spellname|spell --title:7th (SLOTS)&nbsp; --repeating_spell-7|spellname|spell --title:8th (SLOTS)&nbsp; --repeating_spell-8|spellname|spell --title:9th (SLOTS)&nbsp; --repeating_spell-9|spellname|spell It should only show sections for which spells actually exist.
Using D&amp;D 5E Roll20 and was looking for prepared spells. Either way when it comes to API Thanks Jarren said: What character sheet are you using? (E.g. ‘D&amp;D 5E by Roll20’ or something else?) Do you want a list of all the spells or just a number of how many spells are known for each level? Do you want a list of all spells or just prepared spells or both? Do you want a non-API solution or an API solution?
Thanks for all the info, l as for API I'm not that up to date on how to go about that. Slowly teaching myself how that all works. So anything will help. Thanks timmaugh said: Built in? No. But there are scripts that can help. InsertArg can do what you're looking for. You would basically instruct it to get the cantrips (and/or slots), and produce a button for each. InsertArg produces its own menu, so it wouldn't be a roll template anymore. Here is an example where I used it to produce a menu of attributes (which represented character injuries). Another option would be a combination of metascripts like Muler, Plugger, APILogic, ZeroFrame, and Fetch, which could work right in your roll template. The basic idea would be to retrieve a muled variable that would be an APILogic test. If we could Fetch a cantrip at the position of the muled variable (which we would increment at every pass using Plugger), then we would return the API button syntax to the command line *as well as* ANOTHER retrieval of that same variable (which would test the next incremented muled variable). The only way that loop stops is if there isn't a cantrip, so we return nothing. In the end, we've plugged a button into the roll template for each cantrip. If you want an example of that, I can try to put one together tomorrow.
Ocsnapper said: Using D&amp;D 5E Roll20 and was looking for prepared spells. Either way when it comes to API Thanks Jarren said: What character sheet are you using? (E.g. ‘D&amp;D 5E by Roll20’ or something else?) Do you want a list of all the spells or just a number of how many spells are known for each level? Do you want a list of all spells or just prepared spells or both? Do you want a non-API solution or an API solution? For a non-API solution, you can use this Universal NPC Statblock macro &nbsp;for prepared spells.&nbsp; Caveat: For the ‘prepared spells macro’, you must create a character named 'DIV' with an attribute named 'sel' with '@{selected' in the current value.&nbsp; And you'll have to call it from a macro in order to not get any error messages, because of Roll20 Order of Operations.
1631374243
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Here is a helpful video on installing API scripts. It's easier than it sounds: How to Install Roll20 API Scripts