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

Get Number of Statusmarker in API

Hey i want to write a small script reducing an roll by the number of a statusmarker set on a token. So for example i have statusmarker exhaustion with value 3. This means all rolls should be reduced by 3. While i found how to get if there is a statusmarker on a token i don't know how to get the number value of the statusmarker. Thanks for your help
1718025292
timmaugh
Forum Champion
API Scripter
If you install the Metascript Toolbox, Fetch can retrieve that number for you. In this post , scan down to the "Token Status Properties" section to see the syntax options that are available. For instance: @(selected.status.broken-skull) ...or... @(selected.status.broken-skull?all) ...or... @(selected.status.broken-skull?all+) The first one returns the value associated with the first broken-skull marker on the token (if there's no value, an empty string is returned). The second one concatenates all of the values of the broken-skull markers... since markers can only take values of 0-9, sometimes people use one marker for the ones-digit and a second instance of the marker on the same token for the tens-digit. The third one totals all of the values of the broken-skull markers on the token. You can refer to the token in a lot of different ways other than "selected", those are discussed further up in the linked thread. Your roll would require ZeroFrame since you need to "defer" the roll one time so that Fetch can supply the value you need. So, a simple example of a roll being reduced by a particular status marker could be: ![\][\] { [\][\]1d20 - 0@(selected.status.broken-skull)\]\],0}kh1 \]\] {&simple} That will give you the roll minus the status marker value, bounding the result to be greater than or equal to 0. If you don't need the bounding, you can remove the "keep" syntax, and the interior roll... that would be: ![\][\]1d20 - 0@(selected.status.broken-skull)\]\] {&simple} These will work in the command line of another script, too, so if you needed to pass this roll on to another script's command line you can. You would just leave off the {&simple} tag, in that case.
Thanks, Will this also work with as part of an api so it automatically reduces the rolls when there is for example an attack roll?
1718041500
timmaugh
Forum Champion
API Scripter
As long as the message starts with a bang (!), these formations will be discovered and processed. As long as the intended-destination script is built in such a way as to work with metascripts, these formations will be discovered and processed prior to the destination script receiving the message. Most scripts people commonly use from the 1-click repo are built this way (ChatSetAttr, TokenMod, SmartAoE, Spawn, ScriptCards, GroupCheck, etc.). If you just use the Fetch construction (to get the value from the status-marker), then by the time the destination script sees the message, that formation will be a number (or an empty string, if there was no value). If you use that value in a roll, then by the time the destination script sees the message, there will be a roll in that position of the command line. These metascript constructions won't do the alterations to the value on the marker, themselves, but you can use the value in other calculations and a script designed to handle the alterations, directly (like TokenMod). Does that make sense?
1718044500

Edited 1718047574
I think so thank you, i guess my original idea to simple manipulate every roll doesnt work. Maybe i can do it like the Paladin aura api and output a chat message as a reminder to reduce value
1718065715
timmaugh
Forum Champion
API Scripter
Well, once you've gone in for scripts, your in for any script you need! And there are ways to automate decrementing values. I've only just been answering your questions as you ask them, but it seems like maybe we have an A/B problem. Can you describe what you want to have happen with a given attack? Try not to rely on me knowing 5E jargon... I'm much more of a Hero gamer. If there is a conditional, note it (if X is true, I want it to do this, otherwise, do that). We might be able to get you sorted after all 
To clarify i didnt want to use the syntax !myapi but rather a passive listening script that adjusts rolls. Lets say Player A performs an attack roll / saving throw / ability check i wanted to decrement the value originally(1d20 + modifers) to the adjusted value of  (1d20+modifers-value of statusmarker exhaustion of player A). And then output the adjusted value to chat . I thought about using the on chat:message syntax, to get the modifiers of the roll and then use sendChat message function with the new calculation?  But then there would be 2 chat messages one with the original roll and one with the adjusted.
1718106171
timmaugh
Forum Champion
API Scripter
Ah... OK, now I understand. Yes, you're going to run into a problem of multiple messages. If the original message is not a bangsy message, then it will hit the chat. Any passive listener script can output its own message, but it can't intercept that first message. On the other hand, a bangsy message means a dedicated script (or at least using something like the Metascript Toolbox). That can pre-empt the first roll, but it requires an active rewrite of every roll it would interact with. One thing you might look into, before going the path of your own script, would be Customizable Roll Listener. IIRC, you instruct it with combinations of who is sending the message and what roll template to watch for, and you associate with that combination a new command line. When it sees those combinations come across the transom, it issues the command you've associated. In your case, that could be as simple as outputting a message to remember to decrement by X-amount (you could probably still use the Fetch construction I mentioned, above, to get the value)... or, depending on the syntax available to you from CRL, you might even be able to reference a roll in the output of the first message. If you can reference the roll, then you can probably use metascript constructions to perform math on the roll and produce a new output (basically performing the reduction yourself, and producing the final result in the CRL message).
The customizable roll listener is interesting i read throught the doku, but it doesnt seem there is a way  to get the roll values. My idea would be to use the roll listener to run an api everytime there is a roll. The api should check if there is a statusmarker on the token and if so output the value of the statusmarker using fetch like you suggested as a reminder Or do you see a better way? 
1718138769
timmaugh
Forum Champion
API Scripter
No, you're probably right. You could use CRL as a starting point, though. When a script has a chat listener, it receives the message as a parameter to the callback... so CRL is getting the message. Whether or not you would want to implement the same sort of testing CRL does (for whether this is a message on which it should take action), you can at least take advantage of how it builds  what command lines are in its bank of actions to take. Then you can expand the script slightly to give "substitutable" command line handles for the rolls. For instance, this CRL-clone script will have received the message. That message, since you've set it up to listen for some certain parameter (roll template, etc.), should have an inline rolls property. You then provide a standard syntax for transmitting those rolls to the new message... something that won't step on other Roll20 or common scripting syntax. Maybe: $0$ $1$ $2$ ...etc... (That second $ is important so as to not step on repeating list item row numbers.) You can use a regex to trap the digits between the $s, and use this in a replace() operation, returning the value from the referenced roll from the original message. That way, people could use the original roll and perform math on it in a new roll in a new message. Just a thought.