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

5e Spell Point API?

Hi folks, I'm running a game trying out the spell points variant, using the 5e OGL sheet. So far it seems like everything is working fine. The one thing I can't figure out if there is any way to have spells automatically deduct from the spell point total? Thanks!
1662087640
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That would be the feature of a script if it existed. I think the Companion script only tracks slots, though.
OK thanks!
1662135844

Edited 1662167412
Oosh
Sheet Author
API Scripter
You can give this script a go if you like. It's very simple, and doesn't check spell level restrictions from the rule variant - only spell points. Spell Points need to be in the Resources section (the sheet puts them here automatically when you switch them on). If the script finds a spell cast by a player with spell points enabled, but can't find spell points to modify, it'll alert the GM. I tried to match the 5e Companion script output - it looks almost the same. If you're also running the Companion script, it might need a slight modification so it shuts the hell up about spell slots - in testing it was still barking out NO SPELL SLOT warnings with spell points switched on. I haven't done much testing here, let me know if there are any problems.
You can use ChatSetAttr to subtract or add.
Thanks guys! This is not going to be a spell-heavy campaign. I only have one caster, so it certainly won't be the end of the world if she has to keep track manually. But the more automated, the better!
Oosh said: You can give this script a go if you like. It's very simple, and doesn't check spell level restrictions from the rule variant - only spell points. Spell Points need to be in the Resources section (the sheet puts them here automatically when you switch them on). If the script finds a spell cast by a player with spell points enabled, but can't find spell points to modify, it'll alert the GM. I tried to match the 5e Companion script output - it looks almost the same. If you're also running the Companion script, it might need a slight modification so it shuts the hell up about spell slots - in testing it was still barking out NO SPELL SLOT warnings with spell points switched on. I haven't done much testing here, let me know if there are any problems. Oosh, I gave this a try, and it's not working. Although, I guess I should ask, what is the expected behavior? I was thinking that when the player casts a first level spell, for example, it will subtract 2 from the available spell points. For example, I tried casting Cure Wounds directly from the character sheet. I got this error: Couldn't find caster for level 1 spellcast. I tried casting the same spell from a list in the chat generated by Token Action Maker. Same result. And yes, companion is still whining about the spell slot. :) Any suggestions as to what to tweak? My next session isn't for almost a month so I have a while to fiddle with this; no rush! Thanks!
1662261109

Edited 1662262984
Oosh
Sheet Author
API Scripter
Make sure you have the character's name switched on to display in templates in the character sheet settings . If it still isn't working, would you be able to grab the macro the sheet is posting to chat? After casting a spell (either a non-attack from the spell tab, or an attack spell directly from the attacks section and not the spell tab) put the cursor in the chat bar and push the UP button, Ctrl-A to select all, then paste it in here. There are other ways to guess at the caster's identity from chat, but they aren't necessarily very reliable. That said.... I thought the 5e templates always posted the character name, even with the setting off. So maybe the issue is something else. Edit - Ahhhh, I had forgotten the text is a little different when "Display character name in rolls" is switched off. Just needed a tweak to the regex for picking up the character name. If you grab the new version, the script should now pick up the character name regardless of your sheet setting. If memory serves correctly, this isn't reliable for NPC's. If you're going to use the script for any NPC sheets, you'll need to set "Display character name in rolls" to ON, otherwise there's no way for the script to find the name. I haven't used the 5e sheet for a while, it's possible this has been fixed, but..... it probably hasn't. Obviously auto-slot tracking for mooks isn't reliable, since there are generally multiple creatures sharing one character sheet, and besides that they rarely live long enough to exhaust spell slots/points.... but something to be aware of, anyway. Custom macros can also break the character name pickup if any text comes after the @{charname_output} attribute call, and Display Name is switched off. So all in all, it's more reliable to have the character name displayed in the roll, but should work without it for a player character clicking spells straight from the sheet.
1662262592
Oosh
Sheet Author
API Scripter
If all of your casters are using spell points, you can disable the Companion spell tracking (I think). Alternately, this modded version will ignore any caster using spell points.
Awesome, thanks. I will give this a try. I have but a single PC caster, and I'm definitely not going to worry about this for NPCs.
Hi all, Additionnaly, Is there a way that Chat set Attr sends a message to chat if the resource is already at 0 when calling a -1 to that resource ? Something like "There's no point left in that resource to achive that action." ? Because if someone calls, for example, for an action that costs 1 KI Point, nothing says that he cannot do it if it's class_resource is already at 0, it keep sending the message saying that this character is spending 1 Ki point... even if he can't.... Here's the Macro I actually use. : &{template:npcaction} {{rname=Utilisation de Ki}} !modbattr --name Scarabée --silent --evaluate --class_resource|-1!!! {{description=Scarabée utilise 1 point de Ki}} I checked on the wiki, but nothing seems to be answering my questionning. Thnaks for your help if you can. Lionel
1662342342

Edited 1662342544
Oosh
Sheet Author
API Scripter
From the CSA documentation : --modb works like --mod , except that the attribute's current value is kept between 0 and its maximum . You can use !modbattr as a shortcut for !setattr --modb . That said, you can't stop the message actually getting to chat - not unless the original is sent as an !api command, then processed by a script before being sent as a normal chat message. So you'll still get the ability/spell posted to chat, followed by a warning from CSA. Stopping a spell from being posted to chat when no slots/points are left is possible on the character sheet side, and relatively straight forward, but hasn't been implemented for the 5e sheet. It might also be a level of automation which some people don't particularly want.
1662348353
Oosh
Sheet Author
API Scripter
Steven B. said: Awesome, thanks. I will give this a try. I have but a single PC caster, and I'm definitely not going to worry about this for NPCs. I did find a random bug, make sure you grab the current version from the repo (if you'd already installed it).
Oosh said: From the CSA documentation : --modb works like --mod , except that the attribute's current value is kept between 0 and its maximum . You can use !modbattr as a shortcut for !setattr --modb . That said, you can't stop the message actually getting to chat - not unless the original is sent as an !api command, then processed by a script before being sent as a normal chat message. So you'll still get the ability/spell posted to chat, followed by a warning from CSA. Stopping a spell from being posted to chat when no slots/points are left is possible on the character sheet side, and relatively straight forward, but hasn't been implemented for the 5e sheet. It might also be a level of automation which some people don't particularly want. Hi, thanks you for your answer. I'm not using spells or abilities on that macro, but only a resource. I hope the macro could react like companion is currently doing.that's a level of automation i think a lot of people is using. Maybe i should put the ki point as a resource and track it as i would with arrows or any ammunitions, but i would have preferred just a message saying, no points left or something like that from the macro used. Too bad if it's not a functionality available with CSA. Thanks fo rthe link for documentation, and it's because i read it and couldn't find my answer that i posted this message. Best
1662375144

Edited 1662375204
Oosh
Sheet Author
API Scripter
Ah sorry! I didn't read your question properly. You could try either ScriptCards or the Meta Toolbox to handle that. Going the Meta path and using APILogic, you could do a conditional output based on the outcome of the CSA command with the _CURJ and _TCURJ text replacers. I'll leave that to the Metamancer to explain though - might be worth starting a new thread, since that's got some pretty broad applications.
1662390148

Edited 1662470268
timmaugh
Pro
API Scripter
The quick answer is that the Meta Toolbox can preempt the script handle in a number of different ways, which is exactly what you might need in order to sidestep CSA. APILogic does seem to be the best fit to what you're looking to do. Here's an example also using the ZeroFrame syntax of {&simple} to output to chat: !{&if a = b}True part for IF test{&elseif a = c}True part for ELSEIF test{&else}Default part{&end}{&simple} Install APIL and ZF, then paste that into chat. Since the text 'a' does not match the text 'b', the first test will fail. Since 'a' does not match the text 'c', the ELSEIF test will fail.  That leaves us with the ELSE case, and you should see in your chat the message 'Default part'. Change the tests to get true outputs: {&if a = a} will give you the text conditional to the IF block {&elseif c = c} will give you the text conditional to the ELSEIF block if the IF has failed Change the location of the {&simple} tag to get NO output: !{&if a = a}This passed!{&else}It did not pass{&simple}{&end} Because 'a' is the same as 'a', the IF block passes and the text dependent on the ELSE block gets dropped, including the {&simple}. That means that what continues to the rest of the ModDeck is: !This passed! ...and you probably don't have a script intended to catch a handle like that. So, with all of that as a primer, imagine your test for having enough spell points would be in the IF block conditional. If the character has enough spell points... then do the CSA command. On the other hand, if the test fails, all of the CSA verbiage is dropped and CSA never takes action. You could, if you have ZeroFrame installed, output a message alerting you that the character lacks the resources to do what they are attempting. Or, if you have something like DiscreteWhisper, you could use it to send a message. In either case, the conditional text for the ELSE case will only stay in the message if the IF test fails. In other words, only if the character lacks the resources will the part of the command line that responds to lacking resources remain in the message. Also, to preempt Roll20 recognizing that part of the message might start out as a templated message, we'll use the ZeroFrame construction of {&template:npcaction} instead of the Roll20 version of &{template:npcaction}. All that together gives you this: !{&if @{Scarabée|class_resource} > 0}{&template:npcaction}  {{rname=Utilisation de Ki}}   !modbattr --name Scarabée--silent --evaluate --class_resource|-1!!! {{description=Scarabée utilise 1 point de Ki}}{&else}The resource was already at 0{&end}{&simple} ...which will output a line if the class_resource was already at 0. You could, of course, remove any output from that section by deleting the conditional text, but I find that leads to people repeatedly clicking a command because they have no feedback to tell them, "Yes, I understand, but the answer is still 'no'." TL;DR Solution So, maybe a hybrid macro, taking the best parts of this, would be to conditionally change the contents of the template message based on the results of the resource check? !&{template:npcaction} {{rname=Utilisation de Ki}} {&if ([ResourceCheck]@{Scarabée|class_resource} > 0)}!modbattr --name Scarabée --silent --evaluate --class_resource|-1!!!{&end} {{description={&if ResourceCheck}Scarabée utilise 1 point de Ki{&else}Scarabée essayé d'utiliser ki, mais n'a pas de ki à dépenser{&end}}}{&simple} Note we're back to using the Roll20 template syntax, since either way we're going to output the template (just with different content). Note, the EDIT : also notice that we're naming our conditional check to be ResourceCheck because we have to use it in different parts of the command line. This just makes it so the condition doesn't need to be evaluated twice. First we define the ResourceCheck conditional to be the check of the class resource against 0, then later we can just check that result directly like this: {&if ResourceCheck} REQUIRED SCRIPTS: APILogic, ZeroFrame, ChatSetAttr
1662393013

Edited 1662397078
Wow perfect !this solution is absolutely brilliant and effectively works perfectly ! And I want to thank you so mu s ch in the effort you made for adding the rest of the text in french !! very much obliged !
1662395650
timmaugh
Pro
API Scripter
It's nothing. I had the tire. And the jack. And a handful of metascripts. =D
Hi again Timmaugh, following our macro discussion on checking if there's still some resource points left on a character sheet and issue a different answer if not, is there a possibility to include an attack in that condition ? Let me explain : the macro is : !&amp;{template:npcaction} {{rname=Utilisation de Ki}} {&amp;if ([ResourceCheck]@{Scarabée|class_resource} &gt; 0)}!modbattr --name Scarabée --silent --evaluate --class_resource|-1!!!{&amp;end} {{description={&amp;if ResourceCheck}Scarabée a utilisé 1 point de Ki pour renvoyer le projectile reçu{&amp;else}Scarabée a trop puisé dans son Ki et ne peut plus l'utiliser avant un repos.{&amp;end}}}{&amp;simple} in the yes part, i'd like to then add an attack :(the following is obtained with the up arrow in the chat) @{Scarabée|wtype}&amp;{template:atkdmg} {{mod=+5}} {{rname=Shuriken}} {{r1=[[@{Scarabée|d20}cs&gt;20 + 3[DEX] + 2[PROF]]]}} @{Scarabée|rtype}cs&gt;20 + 3[DEX] + 2[PROF]]]}} {{attack=1}} {{range=4/18}} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[1d4 + 3[DEX]]]}} {{dmg1type=Piercing}} 0 {{dmg2=[[0]]}} {{dmg2type=}} {{crit1=[[1d4[CRIT]]]}} {{crit2=[[0[CRIT]]]}} 0 {{desc=}} {{spelllevel=}} {{innate=}} {{globalattack=@{Scarabée|global_attack_mod}}} {{globaldamage=[[0]]}} {{globaldamagecrit=[[0]]}} {{globaldamagetype=@{Scarabée|global_damage_mod_type}}} ammo= @{Scarabée|charname_output} I tried to insert it before the {&amp;else} but the output isn't working well (the attack and the damages are correct but there's a strange addition on the output Shuriken ATT.&nbsp;: 9 Scarabée a utilisé 1 point de Ki pour renvoyer le projectile reçu {{mod=+5 DÉGÂTS 1&nbsp;: <span class="userscript-userscript-inlinerollresult userscript-showtip userscript-tipsy-n-right" style="font-family: &quot;helvetica neue&quot; , &quot;helvetica&quot; , &quot;arial&quot; , sans-serif ; color: #404040 ; line-height: 1.25em ; background-color: #fef68e ; padding: 0 3px 0 3px ; font-weight: bold ; cursor: help ; font-size: 1.1em ; border: 2px solid #3fb315" title="Rolling 1d4 + 3[DEX] = ( 4 )+3">7 Piercing I guess one of the }} is somehow breaking the macro at some point, but would there be a possibility to achieve that ? Thx for your help if there's an easy solution
1663250027
timmaugh
Pro
API Scripter
I would think you can do this adding Plugger (and possibly Fetch) to your ModDeck. Plugger will let you embed that secondary attack into your code on the correct side of the IF/ELSE series. If you reference the macro or character ability that houses the secondary attack in the EVAL block, but you defer detection (using a deferral character), you can run it only if that side of the conditional survives. So let's say the secondary attack is on&nbsp;Scarabée in an ability named "SecondaryAttack. A normal Plugger EVAL block for that might look like this: {&amp;eval(^)}%^{Scarabée|SecondaryAttack}{&amp;simple}{&amp;/eval} EVAL is going to issue what is inside of the EVAL &amp; /EVAL tags as a new message. That message will be prepended with a bang ('!'), to make it a script message, so we give it a {&amp;simple} tag to make sure the template still hits the chat window. The EVAL block will declare a caret ('^') to be a deferral character, so that we can break up text constructions using that character. Plugger will remove that character before issuing the outbound command, so for our new/second message, those constructions will be detectable. (This means that the secondary attack will not be "expanded" into this command line, which means it won't interrupt our {{...}} closures.) The only formation that needs hiding in this way is the Roll20 construction of the character ability. Great, right? Except there's one more thing: we need to slow this down because EVALs typically run before APILogic IF blocks. You can see this if you issue a chat command of: !0 That will show you the default order of your metascripts (with relative priorites as a clickable number, giving you the ability to slot the order as you see fit): So if the EVAL fires off before the conditional is evaluated, you'll always get that secondary attack. There are two ways to slow the EVAL down. The first is to use ZeroFrame deferral characters (backslashes) to slow down the detection of the EVAL block until the second metascript loop: {\&amp;eval(^)}%^{Scarabée|SecondaryAttack}{&amp;simple}{\&amp;/eval} One backslash is one loop-deferral... so instead of going EVAL =&gt; IF =&gt; LOOP, it will go IF =&gt; LOOP =&gt; EVAL (if necessary). The EVAL block won't be detected in the first pass of the loop. The other option is to use a ZeroFrame ordering syntax token, which will control the order of scripts for this message, only: {&amp;0 apil eval} That will tell ZeroFrame -- again, for this message only -- to run APILogic first, then Plugger. You can put that anywhere in your command line. If it is there, it will be the absolute first thing ZeroFrame detects. Whichever form you choose, the end result is the same: The EVAL block only survives to be detected/issued if the IF conditional turns out to be in the correct circumstance. TL;DR Solutions Just looking for the solution options? Here they are with your original macro. Change "SecondaryAttack" to be whatever the name of the character ability is that you want to trigger. If it's a macro instead of an ability and you can't figure out the modification after reading (above) how I came to this command line structure, post back and I'll lend a hand. Option 1 (ZeroFrame Loop Deferral) !&amp;{template:npcaction} {{rname=Utilisation de Ki}} {&amp;if ([ResourceCheck]@{Scarabée|class_resource} &gt; 0)}!modbattr --name Scarabée --silent --evaluate --class_resource|-1!!! {\&amp;eval(^)}%^{Scarabée|SecondaryAttack}{&amp;simple}{\&amp;/eval}{&amp;end} {{description={&amp;if ResourceCheck}Scarabée a utilisé 1 point de Ki pour renvoyer le projectile reçu{&amp;else}Scarabée a trop puisé dans son Ki et ne peut plus l'utiliser avant un repos.{&amp;end}}}{&amp;simple} Option 2 (ZeroFrame Ordering Syntax Token) !&amp;{template:npcaction} {{rname=Utilisation de Ki}} {&amp;if ([ResourceCheck]@{Scarabée|class_resource} &gt; 0)}!modbattr --name Scarabée --silent --evaluate --class_resource|-1!!! {&amp;eval(^)}%^{Scarabée|SecondaryAttack}{&amp;simple}{&amp;/eval}{&amp;end} {{description={&amp;if ResourceCheck}Scarabée a utilisé 1 point de Ki pour renvoyer le projectile reçu{&amp;else}Scarabée a trop puisé dans son Ki et ne peut plus l'utiliser avant un repos.{&amp;end}}}{&amp;simple}{&amp;0 apil eval}
1663256150

Edited 1663258316
Hi again,&nbsp; And thank you for all the time taken explaining everyone how your metascripts function. I tested both of your version using this macro (so basically using the attack id) and it works well except that the attack isn't triggered... I have the damages etc but not the attack : player|API: 4/18 (range) Shuriken (+5) Scarabée 7 Piercing Here's the macro I used : !&amp;{template:npcaction} {{rname=Utilisation de Ki}} {&amp;if ([ResourceCheck]@{Scarabée|class_resource} &gt; 0)}!modbattr --name Scarabée --silent --evaluate --class_resource|-1!!! {\&amp;eval(^)}%^{Scarabée|repeating_attack_-NA5RngQmsSWJitzh0ga_attack}{&amp;simple}{\&amp;/eval}{&amp;end} {{description={&amp;if ResourceCheck}Scarabée a utilisé 1 point de Ki pour renvoyer le projectile reçu{&amp;else}Scarabée a trop puisé dans son Ki et ne peut plus l'utiliser avant un repos.{&amp;end}}}{&amp;simple} Did i&nbsp; miss something ? I used your !0 just in case you need these infos 20 :Select Manager 50 :Fetch 50 :Plugger 70 :APILogic EDIT : also tried to use the full attack code (as in my previous post) but then i got this : player|API: $[[0]] 4/18 Shuriken (+5) Scarabée} $[[2]] Piercing Thx
1663259079
timmaugh
Pro
API Scripter
ok, if your secondary attack is a repeating attribute, we can't reference it as an ability (with '%'). So instead of %^{Scarabée|repeating_attack_-NA5RngQmsSWJitzh0ga_attack} ...try... @^{Scarabée|repeating_attack_-NA5RngQmsSWJitzh0ga_attack}
1663261408

Edited 1663261580
There's probably a typo somewhere, but it won't work.... i checked on the RepItem id and it's correct, but the chat posts that no attribute was found... here's the complete macro i intend to use....&nbsp; !&amp;{template:npcaction} {{rname=Utilisation de Ki}} {&amp;if ([ResourceCheck]@{Scarabée|class_resource} &gt; 0)}!modbattr --name Scarabée --silent --evaluate --class_resource|-1!!! {&amp;eval(^)}@^{Scarabée|repeating_attack_-NA5RngQmsSWJitzh0ga_attack}{&amp;simple}{&amp;/eval}{&amp;end} {{description={&amp;if ResourceCheck}Scarabée a utilisé 1 point de Ki pour renvoyer le projectile reçu{&amp;else}Scarabée a trop puisé dans son Ki et ne peut plus l'utiliser avant un repos.{&amp;end}}}{&amp;simple}{&amp;0 apil eval} EDIT : I found a temporary workaround using this but i wish i could understand why the previous doesn't work as intended.... !&amp;{template:npcaction} {{rname=Utilisation de Ki}} {&amp;if ([ResourceCheck]@{Scarabée|class_resource} &gt; 0)}!modbattr --name Scarabée --silent --evaluate --class_resource|-1!!!{&amp;end} {{description={&amp;if ResourceCheck}Scarabée utilise 1 point de Ki pour [Renvoyer le projectile](~Scarabée|repeating_attack_-NA5RngQmsSWJitzh0ga_attack){&amp;else}Scarabée a trop puisé dans son Ki et ne peut plus l'utiliser avant un repos.{&amp;end}}}{&amp;simple}
1663270293
timmaugh
Pro
API Scripter
If you enter this into chat and hit ENTER, do you get the result you want? @{Scarabée|repeating_attack_-NA5RngQmsSWJitzh0ga_attack} Once you get the return you're looking for, add the deferral character ('^') and put this construction in your original macro. That should work... at least, it is on my end.
It says&nbsp; No attribute was found for @{Scarabée|repeating_attack_-NA5RngQmsSWJitzh0ga_attack} But when i use it as a chat button it works.... if you wanna have a look i'm personnaly lost lol
1663279785
timmaugh
Pro
API Scripter
Sure .. I'm away from my laptop at the moment, but invite me and promote me when you see me. I'll see what I can find.
PM'd you