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

Getting Plugger and TokenMod to work together in a macro with text output

I'm attempting to create a macro that rolls the damage of an attack and displays this in chat (this part works fine) and then proceeds to use the result of the roll as a sort of lifesteal mechanic adding some of the damage back up to one of its own bars, I got great insight into this from Timmaugh yesterday on the tokenmod page but I can't seem to get it to work properly.

For a little more indept explanation, we are playing a naruto game with a chakra system, I'm able to summon swarms that when using their bite attack absorb an amount of chakra equal to the dice roll of the bite attack, since I can summon more than 1 swarm and they can in theory hold an infinite amount of chakra i wanted to store the chakra each swarm absorbs in the token as they all use the same character sheet, and even though i tried to follow Timmaugh's instruction and experimented a little with different things in general i can seem to get Plugger to work at all

Example of my macro and its output:

&{template:npcdmg}{{description=They bite down hard dealing [[[[1d4]][1d4]+3]] piercing damage and absorbing $[[0]] Chakra}}{&eval}token-mod --set bar2|+$[[0]] --ids|-MwyWa8Sdz4sxWTsA8K8 {&/eval}


As far as I can tell and understand it should work and the chat output works perfectly well but the tokenmod command doesn't seem to get executed at all as there is no error message or anything either so my questions are:
Am I doing something wrong?
Is there a way to see if plugger is active and working?
Any other suggestions?

March 01 (3 years ago)
timmaugh
Forum Champion
API Scripter

Ah! I forgot you were coming from a frame of reference of ChatSetAttr, which will listen to *every* message to look for an inline handle... not just an API message.

Plugger (and the rest of the metascripts) only work in API messages -- or at least, messages that start as API messages. But you can still use them to do exactly what you want to do. The only change is that you have to *start* the message as an API message (with a  ! ) before you turn it into a "basic" message (that is, non-API). To finish with a basic chat message, you just have to use the {&simple} tag from ZeroFrame. So your message would be:

!&{template:npcdmg}{{description=They bite down hard dealing [[[[1d4]][1d4]+3]] piercing damage and absorbing $[[0]] Chakra}}{&eval}token-mod --set bar2|+$[[0]] --ids|-MwyWa8Sdz4sxWTsA8K8 {&/eval}{&simple}

Give that a try and it should work.

REQUIRED SCRIPTS

Token-Mod, ZeroFrame, Plugger

Thank you again for the help, my DM has just added zeroframe and selectmanager and i started to work on it and after 1 attempt where it changed the bar to dislay +$[[0]] i decided to make the roll happen in the tokenmod command since, if i understand plugger correctly, it makes the inline commands execute first and hoped to solve it that way, but instead my dm now gets an error message displaying



Did i mess up somewhere and cause this or is there potentially some error in one of the scripts thats not correctly caught upon trying to execute the code posted above and causing this?

March 02 (3 years ago)
timmaugh
Forum Champion
API Scripter

Hmm... it works for me in that it doesn't throw an error...

...but to get it to work the way you want it to, you'll have to fix something. It won't cause the error, but TM won't work properly unless you change it.

Any inline roll in the embedded token-mod command line (or any plugger command) needs to be either deferred (so that it happens in the dispatched command), or it needs to be extracted so that the value is sent (using .value). I'll explain why in just a second, but this is the command that I dispatched to make the above output (and I watched it update bar2 of the selected token):

!&{template:npcdmg}{{description=They bite down hard dealing [[[[1d4]][1d4]+3]] piercing damage and absorbing $[[0]] Chakra}}{&eval}token-mod --set bar2|+$[[0]].value  {&/eval}{&simple}

Note, too, I deleted the --ids argument from token-mod, because I obviously don't have a token with that ID. Also, with SelectManager installed, you can rely on that script to give back the selected token... so that's how I let it run: affecting the token I had selected.

Why You Have to Defer or Extract the Roll

What happens is that Roll20 has a turn at the command line before the message gets to the stack of API scripts. Roll20 processes the inline roll and adds the roll data to the message object that is being handed off from script to script. So... the original message has the original inline rolls.

Then the metascripts get a hold of that same message first (before normal scripts get a chance), and do what they need to do. In the case of Plugger, it sees that it has to send a secondary message. By the time it gets the command line that it will need to send (everything between the {&eval} syntax), the inline rolls that have been detected and parsed by Roll20 have been replaced with the roll markers: $[[0]]. But remember, the data for that roll is in the original message.

So when Plugger sends the command line, it sends the roll marker as part of the string of text. That command line gets parsed by Roll20 (looking for any new inline rolls, or sheet attribute calls, etc.), and then a NEW message object is created. Unfortunately, for a simple outbound command like that, Plugger can't (currently) pass on the original roll data that's in the original message... so what TokenMod sees when it gets the new message is a roll marker that *should* point to roll data, but there's no data there (it's in the original message).

That's why you want to extract the roll value before you send the command to TokenMod (so that TM only sees a value in that position in the command line), or you want to defer the roll until the TokenMod message is processed, so that the roll data is attached to the new message.

Specific to What You Are Trying...

All that said, I don't think you want to embed the roll in the TokenMod command line... because if the Roll20 parsers detect the inline roll formation, they are going to process it anyway as a part of the original message. There's no reason, in this case, to defer the roll until Plugger dispatches the TM command. The whole point to what you're doing is to be able to use a part of the roll you need in the outer command (the full attack value) as a component to the TM command.

If You Still Have an Error

Like I said, I couldn't produce that same error, so if you still get an error after you apply all of this advice to what you're trying to do, share your full command line. If I still can't replicate it, maybe your GM can invite/promote me and I can jump in the game and poke around, see if I can figure out what is going on.

I have posed the question to my DM, for now it seems that all scripts are disable due to that error so im waiting to hear back from him to see if restarting the API sandbox makes it tick again or potentially doing the save thingy as it says, however our DM is code illiterate and if it werent for the one click api adding he wouldnt trust adding scripts himself.

A restart of the sandbox seems to have solved all issues and its working  perfectly right now, thank you so much!!