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

Macro in API scripts

Hello everyone, Could someone explain to me how to call a preexisting macro in a fonction on API ? thanks a lot for answering ! I 'd like to implement effects (in macro ) depending of effectiveDamage [ 09:28 ] < = 2 = > macro Zglow < = 4 = > macro Zbubbling < = 6 = > macro Zbomb < = 9 = > macro Zburn >9 = > macro Znova
1722958604
timmaugh
Pro
API Scripter
If you mean you want to use a pre-built script to handle that, you can use the Metascript Toolbox. If you, instead, mean you want to build a script yourself to handle that, then that would be a longer discussion. As for the first option, once you install the Toolbox, there are a couple of ways to go about it. This is all assuming you mean "macros" as in Collection Tab macros. If you mean Character Abilities, instead, you can still do this... it will just change the syntax a bit. Option 1 - Mule Ability The easiest way to do this would be to set up a mule ability (think of it like a table stored in an ability on a character). It could be on any character, but if multiple people would need to access it, or if you, as GM, would be accessing it to handle multiple tokens/situations in the game, then some dedicated mule character would be the best bet. Just remember that anyone who wants to use this solution would need controlling rights to the character. They don't have to be explicitly named in the list of controlling players ("All players..." will do), and they don't need to see the character in their Journal. On this character (I'll refer to them as "TableMule"), create an ability. I'll name my ability "DamageMacro". In the DamageMacro ability, enter your information like this: <=2=#(Zglow) <=4=#(Zbubbling) <=6=#(Zbomb) <=9=#(Zburn) >9=#(Znova) That uses Fetch constructions (Fetch is another of the metascripts) to retrieve the appropriate macro... you just have to use the right value to look up against the mule table. That construction syntax looks like this: get.Character Name.AbilityName.LookupValue/get So if you wanted to look up based on a 1d10 roll, you could do: get.TableMule.DamageMacro.[[1d10]].value/get (The .value is a way for the metascripts to extract the result of that roll so you can use it in the lookup.) Alternately, if you had the roll somewhere else in the command line, you could use the re-using rolls trick and refer to the correct roll index: get.TableMule.DamageMacro.$[[0]].value/get To use that construction, you'd need to start the command with a bang (!) or use it in a batch set of commands. For instance: !{{   {&template:default}({)name=Attack Result(})({)Damage=[[1d10]] (})    get.TableMule.DamageMacro.$[[0]].value/get }} That would give a template report of the roll (could obviously be expanded with more info), followed by retrieving the macro text. Make sure you see the caveats section, below, for one other syntax consideration. Option 2 - Conditional You could do the same sort of thing with a conditional check (IF/ELSE). To do it this way, you'd want to defer the Fetch retrieval of the macro text (so that any verbiage in the macro didn't break the conditional syntax). Here's an example using that same sort of 1d10 die roll for the condition: !{&if [[1d10]].value <= 2} #\(Zglow){&elseif $[[0]].value  <= 4}#\(Zbubbling) {&elseif $[[0]].value  <= 6}#\(Zbomb) {&elseif $[[0]].value  <= 9}#\(Zburn) {&elseif $[[0]].value  > 9}#\(Znova){&end} (Again, see caveats section, below.) The backslash is a deferral to make the Fetch retrieval slow down long enough so that the conditional can evaluate itself, first. After that, there's only one Fetch construction left in the line. Caveats This is just the general structure for doing this sort of thing with the metascripts. There are a few kinds of messages that can't be sent through a script like this... /fx being one (I think; can't remember off the top of my head). To run an fx command, your macro couldn't send an /fx command but would instead have to use a script which, itself, generated the fx on the VTT. Also, be aware that using a script (like the metascripts) to gather/launch a macro means that the message starts as a message that WILL NOT hit the chat output. If the macro you want to execute would send some text to the chat output (instead of invoking another script which would output the text), you will need to include a {&simple} tag somewhere in the command line. When the metascripts see this, they will output the command line (as it stands when their work finishes) to the chat. This can be confusing if you have SOME macro options that would invoke a script (where you wouldn't want a {&simple} tag) while other scripts should output something to chat. In these cases, you can include the {&simple} tag either in the mule ability table on a per-line basis, or you can include the {&simple} within the IF conditional structure for the relevant outcomes so that if that particular branch of the conditional logic passes, you will either have or not-have the {&simple} tag, as necessary. (If that doesn't make sense but you know you have a situation where only some of your macros should output something to chat, post back with example macro commands and I can help get things converted.) Finally, also be aware that when you launch a command from a script (as this would be: the metascripts would launch whatever final command is in your chosen macro), the final message doesn't come from *you* as a player (with tokens selected on the VTT, etc.). It comes from the Script Moderator (think of it as the embodiment of your script sandbox, sitting at your VTT like another player). This can have implications: Since the Script Moderator can't respond to queries, any queries in your chosen macro will not execute or evaluate. Since the Script Moderator can't select tokens on the VTT, constructions that use the Roll20 syntax for retrieving information from the selected token will not work (i.e., @{selected|ac} ). Since the Script Moderator is not YOU, you might run into a problem where a downstream script won't allow you to do something because it doesn't think you sent the message. There are metascript workarounds for all of these situations, they would just clutter an already long message. If you find you need one of these workarounds, or if you just can't get the solution to work, post back with your setup and what command line you are trying, and I can help get things corrected.
Thanks a lot for your answer