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

ChatSetAttr Question about minimums

March 04 (4 weeks ago)

Edited March 04 (4 weeks ago)

I have a system that uses Magic Points (MP) and would like the spells - which are configured as Ability Cards - to automatically subtract the MP used from their current MP total. I have that already set up. What I'm wondering is there a way to throw up an error if they try and use too many points? Like if they only have 18 MP remaining and try and cast a 20 MP spell it would say, "Nope."


I did see that modbattr will prevent below zero, but is there a way to give warning?


I can paste my spell card if needed.



-Dave

March 04 (4 weeks ago)

I don't believe ChatSetAttr can do that, but you could use Metascripts (APILogic) to do that pretty easily.  

You didn't include your ChatSetAttr command, but it would look something like this (this will still need to be adjusted to correctly do the APILogic):

!{& if 20 - @(CharacterName|MP) < 0}/w "CharacterName" You don't have enough Magic Points!{&else}setattr --name CharacterName --MP|-20 {&end}
March 04 (4 weeks ago)

Okay sounds easy enough. I'll get Metascripts and give it a shot. Thanks!

March 04 (4 weeks ago)
timmaugh
Pro
API Scripter

Just 2 quick points...

1) Because of the order of operations, the math contained in the IF tag will need to be done prior to APILogic evaluating the conditional. That can be with an inline roll:

{& if [[20 - @{CharacterName|MP}]] < 0} 

...or it can be done with a MathOps tag:

{& if {&math 20 - @{CharacterName|MP} } < 0}

Both will work, but you can't leave the math for APILogic to perform; it doesn't recognize that's what you want it to do.

2) If you want the NON-ChatSetAttr side to hit chat (in other words, you want to see the warning that "you don't have enough MP" in chat), you have to include a {&simple} in that case (the true case of the conditional). All of the text between the {&if...} and the {&else} (as well as the {&else} and the {&end} ) will be kept or filtered out depending on the evaluation of the conditional check. So if the TRUE case is kept, you want the {&simple} tag to be in the resulting command line (instructing the mod to dump the message out to chat). If the FALSE case is kept, then {&simple} tag will be eaten, and the message will continue to ChatSetAttr to be evaluated.

Altogether, that would make Jarren's example more like:

!{& if [[20 - @(CharacterName|MP)]] < 0}/w "CharacterName" You don't have enough Magic Points!{&simple} {&else}setattr --name CharacterName --MP|-20 {&end}


Note: in this case, because of the order of operations, you should be able to use *either* the Roll20 formation of:

@{CharacterName|MP}

...OR the Fetch (metascript) construction of:

@(CharacterName|MP)

Both should resolve in time.