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 .
×

Token-Mod and moving targeted tokens away from a selected token

1768972138

Edited 1769007904
Hello Roll20 super geniuses! I've got a specific use case that might spawn some new functionality if it doesn't already exist.&nbsp; I have been trying to MathOps and Token-Mod my way into a macro that will let me push a targeted token (ideally multiple targeted tokens at once) away from a selected token, to no avail, using an atan2(DeltaX,DeltaY) formula to set the angle for "!token-mod --move" to do its things and push tokens a specified distance away. Here's the macro I've set up that doesn't work.&nbsp; !token-mod --move ={&amp; math atantwo([[@{selected|position-x}-@{target|position-x)]],[[@{selected|position-y}-@{target|position-y}]])}|4g This specific use case is a DnD metallic dragonborn's repulsion breath, which pushes creatures who fail a save 20 feet away and knocks them prone.&nbsp;&nbsp; I was trying to see if anyone else had any luck with this kind of operation and stumbled upon this old thread: <a href="https://app.roll20.net/forum/post/10008422/slug%7D#newtopic" rel="nofollow">https://app.roll20.net/forum/post/10008422/slug%7D#newtopic</a> Has any headway been made on this front, or does anyone have corrections to be made on my non-functional macro, or is there an API somewhere that does this (not Kaboom) that I am unaware of? If Kaboom could isolate targets, it'd be perfect, but I don't believe it does.&nbsp;
1769129110
timmaugh
Forum Champion
API Scripter
Hey, Rocklobster... For this kind of thing you're going to probably want: 1) a forselected construction to the TokenMod line, to allow for differentiated "expulsion" from the central point, and 2) a working {&amp;math} operation =D Let's start with the second one, first. The only way to get the x and y position of tokens in the command line of a script is via a Fetch construction: @(selected.left) @(selected.top) Next, the atantwo function is going to return the angle of divergence in radians from the radial plane where "straight right" is 0 radians. So we'd have to convert it to degrees (for TokenMod), but then the TokenMod --move argument is based around a radial plane where "the current orientation of the token determines 0". That gets... ugly. Let's try it with the --set argument for TokenMod, instead, and set the left and top of the selected token. We can do this using the hypot() function of MathOps to get the current distance, then adding our "expulsion" distance and dividing the result by the original distance. In other words, we're getting the transformation factor for the hypotenuse, which we can apply to either leg of the imaginary triangle. For a single token, that would look like this: !token-mod --set top|{&amp;math round(@(sourceToken.top) - ((@(sourceToken.top) - @(selected.top)) * (hypot((@(sourceToken.top) - @(selected.top)),(@(sourceToken.left) - @(selected.left))) + ?{How many units?|1|2|3|4|5} * 70) / hypot((@(sourceToken.top) - @(selected.top)),(@(sourceToken.left) - @(selected.left)))))} left|{&amp;math round(@(sourceToken.left) - ((@(sourceToken.left) - @(selected.left)) * (hypot((@(sourceToken.top) - @(selected.top)),(@(sourceToken.left) - @(selected.left))) + ?{How many units?|1|2|3|4|5} * 70) / hypot((@(sourceToken.top) - @(selected.top)),(@(sourceToken.left) - @(selected.left)))))} For that to work, you need to replace "sourceToken" with the actual name of a token, or the ID of a token (in every instance). So if you want to put this together for a dragon character named "Charry Night", you would substitute "Charry Night" into every place you find "sourceToken". If you instead wanted to be able to use a DIFFERENT source token every time, you could replace it with a targeting statement like: @{target|Source Token|token_id} Then, to run it, you would SELECT the token you wanted to move (the one being pushed away). Note that this is setup to use a query for the amount of distance, from 1 to 5 units of 70 pixels (the default setting for a page, unless you change it). You can replace this query with a hard and fast number, but since we're performing the math instead of TokenMod, we have to use that 70px value (or whatever your pages are set to). To expand this to multiple tokens, we need to convert it to a forselected construction. For that to work, we need to "defer" all of the meta-work so that they DO NOT RESOLVE until the individual messages are dispatched for each token (that's what forselected does). So we start our line this way: !forselected(^) token-mod ... ...which will set up that we can use the caret character as a way to mask the formations for now (in the parent message), but which will then be removed for the messages dispatched for each token. Once we have that character, we insert it everywhere we have a meta-construction that we need to have wait until the token-iterated message. That means: @(selected.top) ...becomes... @^(selected.top) Note we don't have to defer the formations having to do with our source token since that WILL be the same for every token radiating away from the center of the expulsion. What changes for each message is the selected token, so THOSE are the formations we need to defer, as well as any formations (like the {&amp;math} tag) that depend on them. TL;DR All together, that should look something like: !forselected(^) token-mod --set top|{^&amp;math round(@(sourceToken.top) - ((@(sourceToken.top) - @^(selected.top)) * (hypot((@(sourceToken.top) - @^(selected.top)),(@(sourceToken.left) - @^(selected.left))) + ?{How many units?|1|2|3|4|5} * 70) / hypot((@(sourceToken.top) - @^(selected.top)),(@(sourceToken.left) - @^(selected.left)))))} left|{^&amp;math round(@(sourceToken.left) - ((@(sourceToken.left) - @^(selected.left)) * (hypot((@(sourceToken.top) - @^(selected.top)),(@(sourceToken.left) - @^(selected.left))) + ?{How many units?|1|2|3|4|5} * 70) / hypot((@(sourceToken.top) - @^(selected.top)),(@(sourceToken.left) - @^(selected.left)))))}