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

Changing rtype with macros?

September 23 (4 years ago)

Hey all. So I have a character with Elven Accuracy and need to be able to roll 3d20s at certain times when I get advantage. I found a nifty little way to do this over on Reddit with the following code: 


{{query=1}} ?{Advantage?|Normal Roll,&#123&#123normal=1&#125&#125 &#123&#123r2=[[0d20|Advantage,&#123&#123advantage=1&#125&#125 &#123&#123r2=[[2d20k1|Disadvantage,&#123&#123disadvantage=1&#125&#125 &#123&#123r2=[[1d20}



The unfortunate part about this is it requires me to go into Attributes and Abilities and change the rtype to this code when I need the extra advantage, then go back to it and paste the regular code in when I don't need it. Is there a macro or api I could use to change the rtype between the 2 different codes?

September 24 (4 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Unfortunately, editing the character sheet via macro requires the API.

September 24 (4 years ago)

Alrighty, and which API would that be? I was trying with TokenMod at first but then I remembered I was trying to change the sheet and not the token itself. Would it be ChatSetAttr? Through the use of the --replace function I'm guessing? Not quite sure how though ^^

September 24 (4 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

ChatSetAttr is the script, yes. I'm not sure how easy the command would be. There are a lot of escaped characters in there.

Also, I believe --replace has to do with character substitution.

September 24 (4 years ago)

Edited September 24 (4 years ago)

Hmm, so I tried it with --replace and it mostly worked. This is what I tried:


!setattr --sel --replace --rtype|{{query=1}} ?{Advantage?|Normal Roll,&#123&#123normal=1&#125&#125 &#123&#123r2=[[0d20|Advantage,&#123&#123advantage=1&#125&#125 &#123&#123r2=[[2d20k1|Disadvantage,&#123&#123disadvantage=1&#125&#125 &#123&#123r2=[[1d20}


So when I click this macro it gives me a drop down menu that asks for Normal/Advantage/Disadvantage. If I pick Advantage it doesn't set to Query Advantage but to Always Roll Advantage. It also displays this in the chat(Cynric is the name of the token/character selected):


Setting attributes

Setting rtype to {{query=1}} {{advantage=1}} {{r2=[[2d20k1 for character Cynric.


It then proceeds to Always Roll Advantage, and the 2nd result is indeed a 2d20k1. That part I can at least leave with, but then switching back is also tricky. I tried using the same command but with Advantage Toggle and it wouldn't work. So using this macro:


!setattr --sel --replace --rtype|@{advantagetoggle}


just gives me this error:


TypeError: Cannot read property 'substring' of undefined

September 24 (4 years ago)

Edited September 24 (4 years ago)
Oosh
Sheet Author
API Scripter

It looks like ChatSetAttr is parsing all those entities, which means it will no longer work when called from a Query. I'm not sure if the script has a command for preserving entities or not.

How many weapons/spells do you use which qualify for EA? If it's only a few, you might be best off just storing the modified rtype as a new Attribute, say @{rtypeEA}, and making a few custom macros for your main attacks - they would then call @{rtypeEA} instead of @{rtype} - a little bit of set up, but after that you don't need to change anything - they only need 2 characters added to the attacks ripped straight from the sheet, so it's minimal work.

I've just noticed you're trying to set the sheet back to Toggle Advantage - so presumably you normally use Toggle? In that case, you'd probably want to use these values for rtype:

Elven Accuracy:
{{query=1}} {{advantage=1}} {{r2=[[2d20k1


Normal:
{{query=1}} {{advantage=1}} {{r2=[[@{d20}


No idea why they both have {{query=1}} in there, you could leave that out if you want to. But that second one is the default contents of @{advantagetoggle}. The reason ChatSetAttr didn't like it was that it doesn't know what sheet to look on - it would probably work if you changed it to rtype|@{cynric|advantagetoggle}.

September 25 (4 years ago)

Yep indeed I do normally prefer to run Advantage Toggle. So this almost worked but still isn't just quite there yet. So the Elven Accuracy portion works. When I run:

!setattr --name Cynric --replace --rtype|{{advantage=1}} {{r2=[[2d20k1


It sets the sheet to Always Roll Advantage and rolls the 2d20 on the 2nd roll. But when I try to run:

!setattr --name Cynric --replace --rtype|{{advantage=1}} {{r2=[[@{d20}


I only get the TypeError: Cannot read property 'substring' of undefined error. But if I try

!setattr --name Cynric --replace --rtype|@{cynric|advantagetoggle}


I get the message in chat saying:

Setting attributes

Setting rtype to {{query=1}} {{normal=1}} {{r2=[[0d20 for character Cynric.


Which shows on the sheet as Always Roll Advantage, but in reality it actually just Never Rolls Advantage.

September 25 (4 years ago)
Oosh
Sheet Author
API Scripter

Ah, whoops, yeah you probably want "@{advantagetoggle}" back in the @{rtype} field once you're done (rather than its value). So:

!setattr --name Cynric --replace --rtype|\at{advantagetoggle}

should revert {rtype] to it's default toggle value of "@{advantagetoggle}", so it'll go back to listening to the sheet setting.

September 25 (4 years ago)

There we go, that worked perfectly! Thank you very much for your time and your patience. I really appreciate it ^^

September 25 (4 years ago)
Oosh
Sheet Author
API Scripter

No problem! I haven't really used Toggle before, at least I know how it works now.