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

Help with Calling an Ability Macro using the %{target... function. Or something like that...

1643075489

Edited 1643075794
TIA! I am looking for a function that allows me to pull an NPC ability macro when I use the target function. It would be very helpful for my use case which is a function to automate pulling the NPC's reaction abilities into chat. When I try %{target|Defender|Reactions} (Reactions being an ability macro in the NPC's character sheet.), I get the error message: You attempted to use a roll command looking for the value of a selected token, but no tokens are selected. Any help would be much appreciated. Thank you. *Edit* I'm aware that I can select the token, but that's an extra step that I'm trying to avoid if possible.
1643080480
timmaugh
Forum Champion
API Scripter
I think you have to use an API to do that. The only way to trigger the targeting mechanic is by using the @{target} handle, which can only return an attribute or property. However... You can embed that in a Fetch construction and have it return what you're looking for. Just return the token id of a token you know is connected to a character sheet: @{target|Target|token_id} Then use that as the source of the Fetch: %(@{target|Target|token_id}.abilityName) To actually have this run, you need the ability to hit the chat, which means you'll also need ZeroFrame: !%(@{target|Target|token_id}.abilityName){&simple} REQUIRED SCRIPTS: ZeroFrame, Fetch
1643084279
timmaugh
Forum Champion
API Scripter
Yeah, I meant to point out that abilities can get pretty complex pretty quickly, so this isn't a foolproof method. That said, it's typically just a matter of what gets interpreted/processed first, and what we can do to put things back together. Can you share the full ability you're trying to return?
1643084758

Edited 1643084882
I'm going to break down each of the macros I'm running and what I'm trying to do: The first macro is intended to pull a subsequent macro of either Hit or Miss . This works fantastic and there are no problems and looks like this: !token-mod --ids @{target|Attacker|token_id} --set statusmarkers|?{Action Type?|Action,red|Bonus Action,yellow|Reaction,green} ! /w gm {& if [[?{Attack Strength}+1-@{target|Defender|npc_ac}]].value > 0}#Hit {& else}#Miss {&end}{&simple} The Hit macro is what I'm trying to use to pull the NPC's reactions. The bold/underlined section is what I'm trying to replace. The Hit macro currently looks like this: /w gm &{template:npcaction}{{name=?{Attack Strength}   **vs.** @{target|Defender|npc_ac}}}{{rname=Hit!}}{{description=**@{target|Defender|character_name}'s Info** *HP*: [[@{target|Defender|Bar1}]]/@{target|Defender|hp|max} *Vulnerabilities*: @{target|Defender|npc_vulnerabilities} *Resistances*: @{target|Defender|npc_resistances} *Immunities*: @{target|Defender|npc_immunities} *Condition Immunities*: @{target|Defender|npc_condition_immunities} [Apply Damage](! #HitDmg) **@{target|Defender|character_name}'s reactions:** [Reactions (selected)](~selected|Reactions) {& if [[@{target|Defender|initiative_bonus}-@{target|Attacker|initiative_bonus}]].value>0}[Yes! (select defender)](! #Defend){& else} {&end}{&simple} }} I want to either click on the Reaction (selected) button without having to select the token beforehand or have the Reactions ability pulled into the Hit macro. (The latter is preferable.) I hope that all makes sense. Thank you again.
1643085281

Edited 1643085455
P.S. Here is the ability: /w gm &{template:npcaction} {{name=Reactions}} {{rname=Reactions}} {{description=[Counter Attack](~selected|Counter Attack) }} This is an ability that I manually create. However, what may be easier is to pull in the "Reaction" repeating rows into the Hit macro. But not sure how to do this in a way that will be minimal as a button/link to click and cause chat to display the ability and it's description. Counter Attack is an ability macro that calls the repeating row of the selected token which looks like this: /w gm @{selected|wtype}&{template:npcaction} {{name=@{selected|npc_name} }} {{rname=@{selected|repeating_npcreaction_$0_name}}}{{description=@{selected|repeating_npcreaction_$0_description}}}
1643086597

Edited 1643086674
To better explain: I'm trying to pull in a clickable list of the Defender's reactions within the Hit macro or populate an ability in chat that has a clickable list of the Defender's reactions with as little amount of in-game effort as possible.
1643133530
timmaugh
Forum Champion
API Scripter
OK. Sooooo, that button syntax can take "selected" or it can take a character name: [Button Label](~Character Name|ability) And you can supply that either with standard scripts or metascripts, if you can find a way to provide the character name. We need to save it from the first call (your TokenMod call), and be able to recall it in your Hit and/or Reactions macro. You could do it either of two ways... 1) store it in an attribute on a mule character during the first message, then recall it in the second 2) store it in a Mule ability (capitalization = Muler metascript reference), and then recall it in the second Here's what each would look like: OPTION 1 Setup : create a mule character; I'll assume the character is named "OhMuleBoy" ChatSetAttr will set an attribute to a specified value for you. Interestingly, you can run CSA that is embedded in a roll template very easily, but what we need to do is embed it in the TokenMod call. To do that, we'll use Plugger (a metascript). Here is the CSA command we need to run to put the name of the targeted character (npc) into the HitTarget attribute on the OhMuleBoy character: !set-attr --silent --name OhMuleBoy --HitTarget|'@{target|Defender|character_name}' To run that through Plugger (so we can embed it in the TokenMod command line), we wrap it in {&eval}  ... {&/eval} blocks: {&eval}set-attr --silent --name OhMuleBoy --HitTarget|'@{target|Defender|character_name}'{&/eval} With that attribute getting set in the TokenMod call, you can recall it later to help you build the button, like this: [Reactions](~@{OhMuleBoy|HitTarget}|Reactions) OPTION 2 Setup: create a mule character; I'll asume the character is named "OhMuleBoy"; create an ability on that character called "Tracker" We'll save the result of the targeting statement to the Mule, then recall it in the second statement. Put this somewhere in your first macro: set.OhMuleBoy.Tracker.HitTarget = @{target|Defender|character_name}/set {&mule OhMuleBoy.Tracker} Then include the same {&mule} statement in the second macro, somewhere: {&mule OhMuleBoy.Tracker} And you can reference that as part of the button like this: [Counter Attack](~get.OhMuleBoy.Tracker.HitTarget/get|Counter Attack) Finally, since we're using meta constructions in the macro, we'll need to start it as an API call (using a ! at the start), then using a {&simple} to dump it out to chat. Altogether, your Reactions macro would look something like this: !/w gm &{template:npcaction} {{name=Reactions}} {{rname=Reactions}} {{description=[Counter Attack](~~get.OhMuleBoy.Tracker.HitTarget/get|Counter Attack)}}{&mule OhMuleBoy.Tracker}{&simple} That's more verbiage to include, but it does come with some flexibility in that you can track a bunch of different data in the same Mule ability (minimizing the footprint on the character), it's stored in an ability and not an attribute (some people prefer not to touch their attributes, especially on a Roll20 sheet), and you can use the same value to drive different returns (with other metascripts). Bonus - Virtually Selecting a Token This situation doesn't rise to needing this, but just to answer your point about wanting to be able to reference a selected token without having to actually select the token... you can do that with SelectManager. {& select Bob} {& select Bob, Floopy, Volcano Man} {& select -M1234567890abcdef} {& select @{target|Defender|token_id}, @{target|Someone Else|token_name} } {& select @{selected|token_id} } {& select @{OhMuleBoy|HitTarget} } {& select get.OhMuleBoy.Tracker.HitTarget/get }{&mule ...} It takes a comma-separated list of token identifying information, and returns the tokens to the message. This is mostly helpful in calls to a script that require tokens to be selected. Like I said, that's not what you actually need for your use-case. Double Bonus - A Dynamic Menu You spoke of adding the buttons for the reactions manually. InsertArg is a script that can prepare a command line for you on the fly based on parameters you pass it. You could basically instruct it to present you a panel of buttons, building one for each of the abilities that have a particular prefix in their name, ie, "Reaction". If you want to go down this path, I'm game.
timmaugh said: OK. Sooooo, that button syntax can take "selected" or it can take a character name: [Button Label](~Character Name|ability) And you can supply that either with standard scripts or metascripts, if you can find a way to provide the character name. We need to save it from the first call (your TokenMod call), and be able to recall it in your Hit and/or Reactions macro. You could do it either of two ways... 1) store it in an attribute on a mule character during the first message, then recall it in the second 2) store it in a Mule ability (capitalization = Muler metascript reference), and then recall it in the second Here's what each would look like: OPTION 1 Setup : create a mule character; I'll assume the character is named "OhMuleBoy" ChatSetAttr will set an attribute to a specified value for you. Interestingly, you can run CSA that is embedded in a roll template very easily, but what we need to do is embed it in the TokenMod call. To do that, we'll use Plugger (a metascript). Here is the CSA command we need to run to put the name of the targeted character (npc) into the HitTarget attribute on the OhMuleBoy character: !set-attr --silent --name OhMuleBoy --HitTarget|'@{target|Defender|character_name}' To run that through Plugger (so we can embed it in the TokenMod command line), we wrap it in {&eval}  ... {&/eval} blocks: {&eval}set-attr --silent --name OhMuleBoy --HitTarget|'@{target|Defender|character_name}'{&/eval} With that attribute getting set in the TokenMod call, you can recall it later to help you build the button, like this: [Reactions](~@{OhMuleBoy|HitTarget}|Reactions) OPTION 2 Setup: create a mule character; I'll asume the character is named "OhMuleBoy"; create an ability on that character called "Tracker" We'll save the result of the targeting statement to the Mule, then recall it in the second statement. Put this somewhere in your first macro: set.OhMuleBoy.Tracker.HitTarget = @{target|Defender|character_name}/set {&mule OhMuleBoy.Tracker} Then include the same {&mule} statement in the second macro, somewhere: {&mule OhMuleBoy.Tracker} And you can reference that as part of the button like this: [Counter Attack](~get.OhMuleBoy.Tracker.HitTarget/get|Counter Attack) Finally, since we're using meta constructions in the macro, we'll need to start it as an API call (using a ! at the start), then using a {&simple} to dump it out to chat. Altogether, your Reactions macro would look something like this: !/w gm &{template:npcaction} {{name=Reactions}} {{rname=Reactions}} {{description=[Counter Attack](~~get.OhMuleBoy.Tracker.HitTarget/get|Counter Attack)}}{&mule OhMuleBoy.Tracker}{&simple} That's more verbiage to include, but it does come with some flexibility in that you can track a bunch of different data in the same Mule ability (minimizing the footprint on the character), it's stored in an ability and not an attribute (some people prefer not to touch their attributes, especially on a Roll20 sheet), and you can use the same value to drive different returns (with other metascripts). Bonus - Virtually Selecting a Token This situation doesn't rise to needing this, but just to answer your point about wanting to be able to reference a selected token without having to actually select the token... you can do that with SelectManager. {& select Bob} {& select Bob, Floopy, Volcano Man} {& select -M1234567890abcdef} {& select @{target|Defender|token_id}, @{target|Someone Else|token_name} } {& select @{selected|token_id} } {& select @{OhMuleBoy|HitTarget} } {& select get.OhMuleBoy.Tracker.HitTarget/get }{&mule ...} It takes a comma-separated list of token identifying information, and returns the tokens to the message. This is mostly helpful in calls to a script that require tokens to be selected. Like I said, that's not what you actually need for your use-case. Double Bonus - A Dynamic Menu You spoke of adding the buttons for the reactions manually. InsertArg is a script that can prepare a command line for you on the fly based on parameters you pass it. You could basically instruct it to present you a panel of buttons, building one for each of the abilities that have a particular prefix in their name, ie, "Reaction". If you want to go down this path, I'm game. These all have very promising and unique use cases to make my life easier. In this particular case, I am very interested in the Double Bonus - A Dynamic Menu option. Thank you!