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 .
×
Advertisement Create a free account

[Script] WeaponArcs -- Visible arcs that follow your token and maintain their relative rotation.

1595644881

Edited 1596547260
The Aaron
Forum Champion
API Scripter
Update v0.1.3 &nbsp;-- added Arcs on the Edge, as well as Offset distances. (Thanks&nbsp; Angelo ) Update v0.1.2 &nbsp;-- fixed bug where WeaponArcs won't allow any paths to be changed, rather than just the Arc paths. (Thanks&nbsp; David M. ) Update v0.1.1 -- fixed crash when no angle or rotation are specified in the first argument.&nbsp; (Thanks&nbsp; Tim M ) WeaponArcs v0.1.0 WeaponArcs provides a means to add weapon arcs to tokens for visualization of range and targetable tokens. (Space Ships by Wolf's Forge : Super Spaceships Tokens ) Commands !weapon-arc [--help | --add &lt;[angle|]width&gt; &lt;[offset|]range&gt; [fill color] [stroke color] [stroke thickness] | --addEdge &lt;[angle|]width&gt; &lt;[offset|]range&gt; [fill color] [stroke color] [stroke thickness] | --remove-at &lt;angle&gt; [angle ...] | --clear] --help &nbsp;-- Displays this help --add &nbsp;-- Creates an arc attached to each selected token. angle|width &nbsp;-- A pair of numbers in degrees.&nbsp; angle &nbsp;is the direction off of the token that the arc will be centered on. 0 is up on the token (the direction of the Rotation handle), and numbers proceed clockwise.&nbsp; width &nbsp;is the width of the arc, to be centered on the&nbsp; angle &nbsp;direction. If&nbsp; angle| &nbsp;is omitted, it is treated as 0. offset|range &nbsp;-- A pair of numbers that describe the distance where the arc begins and how long it is.&nbsp; offset &nbsp;moves the origin of the arc away from the default (center of the token for&nbsp; --add ).&nbsp; offset &nbsp;defaults to&nbsp; 0 .&nbsp; distance &nbsp;is the length of the arc from the arc origin to the outer edge. You can use&nbsp; u &nbsp;for Roll20 Units (70px),&nbsp; g &nbsp;for grid scale units, or any of&nbsp; s ,&nbsp; ft ,&nbsp; m ,&nbsp; km ,&nbsp; mi ,&nbsp; in ,&nbsp; cm ,&nbsp; un ,&nbsp; hex , or&nbsp; sq &nbsp;for map scale units. fill color &nbsp;--&nbsp; (Optional) &nbsp;This is the color the arc will be filled with. It must be an HTML color code and can include an opacity. It can be any of 3, 4, 6, or 8 letter formats:&nbsp; #RGB ,&nbsp; #RGBA ,&nbsp; #RRGGBB , or&nbsp; #RRGGBBAA &nbsp;Omitting the opacity will default to&nbsp; 99 . The color defaults to&nbsp; #990000 . stroke color &nbsp;--&nbsp; (Optional) &nbsp;This is the color of the line around the arc. It must be an HTML color code and can include an opacity. It can be any of 3, 4, 6, or 8 letter formats:&nbsp; #RGB ,&nbsp; #RGBA ,&nbsp; #RRGGBB , or&nbsp; #RRGGBBAA &nbsp;Omitting the opacity will default to&nbsp; ee . The color defaults to&nbsp; #330000 . stroke thickness &nbsp;--&nbsp; (Optional) &nbsp;This is the thickness of the line around the arc. It can be any positive number and will default to&nbsp; 3 . --addEdge &nbsp;-- Identical to&nbsp; --add , except it starts from the edge of the token. --remove-at &nbsp;-- Removes arcs at the specified angles from all selected tokens. --clear &nbsp;-- Removes all arcs attached to the selected tokens. Instructions Created arcs will maintain their position with regards to the token they are attached to. Moving the token will cause them to move, rotating will rotate them, etc. A token on the objects layer will have attached arcs on the map layer. A token on the gm layer will have attached arcs on the gm layer. If you move a token from the gm layer to the objects layer or vice versa, the arcs will be moved the the correct layer. Note: &nbsp;Because of a bug with the&nbsp; toFront() &nbsp;Roll20 function, arcs on the map layer will take a second to appear. Creating multiple arcs will take 1 second for each arc. Note: &nbsp;Changes made using TokenMod will also be respected. Feel free to rotate, position, and move all you like. You can specify multiple arguments on the command line: !weapon-arc&nbsp;--add&nbsp;90&nbsp;3u&nbsp;--add&nbsp;15&nbsp;7u Note: &nbsp;You can use the&nbsp; {{ &nbsp;and&nbsp; }} &nbsp;to span multiple lines with your command for easier clarity and editing: !weapon-arc&nbsp;{{ &nbsp;&nbsp;--add&nbsp;90&nbsp;3u&nbsp;#660&nbsp;#00ff00cc&nbsp;7 &nbsp;&nbsp;--add&nbsp;-90|60&nbsp;2u &nbsp;&nbsp;--add&nbsp;90|60&nbsp;2u &nbsp;&nbsp;--add&nbsp;180|20&nbsp;8u&nbsp;#600a }} Examples Creating an arc in the forward direction which is 15 degrees wide and 7 units long with the default colors and strokes: !weapon-arc&nbsp;--add&nbsp;15&nbsp;7u Creating an arc in the forward direction, starting 3 units from the center of the token, which is 15 degrees wide and 7 units long with the default colors and strokes: !weapon-arc&nbsp;--add&nbsp;15&nbsp;3u|7u Creating an arc in the forward direction, starting at the edge of the token, which is 15 degrees wide and 7 units long with the default colors and strokes: !weapon-arc&nbsp;--addEdge&nbsp;15&nbsp;7u Creating an arc in the forward direction, starting 3 units from the edge of the token, which is 15 degrees wide and 7 units long with the default colors and strokes: !weapon-arc&nbsp;--addEdge&nbsp;15&nbsp;3u|7u Inline rolls are supported, including rollable tables. !weapon-arc&nbsp;--add&nbsp;[[(1d8*45)]]|[[20+(1d6*5)]]&nbsp;[[5+1d3]]g&nbsp;[[1t[arcColorAndSize]]] Removing the arc at 90 degrees. !weapon-arc&nbsp;--remove-at&nbsp;90 Removing the arcs at 90, 45, 120, and 180 degrees. !weapon-arc&nbsp;--remove-at&nbsp;90&nbsp;45&nbsp;120&nbsp;180 Clearing all arcs. !weapon-arc&nbsp;--clear Clearing all arcs, then adding four new ones !weapon-arc&nbsp;{{ &nbsp;&nbsp;--clear &nbsp;&nbsp;--add&nbsp;90&nbsp;3u&nbsp;#660&nbsp;#00ff00cc&nbsp;7 &nbsp;&nbsp;--add&nbsp;-90|60&nbsp;2u &nbsp;&nbsp;--add&nbsp;90|60&nbsp;2u &nbsp;&nbsp;--add&nbsp;180|20&nbsp;8u&nbsp;#600a }} Github: <a href="https://github.com/shdwjk/Roll20API/blob/master/WeaponArcs/WeaponArcs.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/WeaponArcs/WeaponArcs.js</a> Support my work on If you use my scripts, want to contribute, and have the spare bucks to do so , go right ahead. However, please don't feel like you must contribute just to use them! I'd much rather have happy Roll20 users armed with my scripts than people not using them out of some sense of shame. Use them and be happy, completely guilt-free! Disclaimer: This Patreon campaign is not affiliated with Roll20; as such, contributions are voluntary and Roll20 cannot provide support or refunds for contributions.
1595647383
This seriously blows my mind that you had a request 4 days ago and now you've written a script like this!&nbsp; I don't do any spacefaring roleplaying, but this is totally useful for D&amp;D cones (especially breath weapons) and spheres and things.&nbsp; Nice work!&nbsp;
1595647504
I don't play in any game that requires this, but mind = blown nonetheless. :)
1595649607
The Aaron
Forum Champion
API Scripter
Thanks!&nbsp; Wish I'd had time to work on it before today. =D
1595654923

Edited 1595654935
GiGs
Pro
Sheet Author
API Scripter
wow, what a great concept.
1595655268
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Looks like a great way to do cone spell templates.
1595708793
I am blown away...&nbsp; Very very cool, thanks.
1595712490
The Aaron
Forum Champion
API Scripter
Sweet.&nbsp; Let me know if you have any enhancement requests, of if you hit any bugs.
1595812269

Edited 1595812332
timmaugh
Pro
API Scripter
Meant to post this, earlier. Was too busy looking for my lower jaw.
1595815063
The Aaron
Forum Champion
API Scripter
HAHAHAAHAHA
1595836155
Snow
Pro
I love this script. One of my players is a wizard and he was asking about Cone and Burst AoE markers he could use. This will come in handy for that. One problem I am having and I know it is probably something easy but I have a macro that I created and works fine as a GM since I can target any token to put the effect onto. But what I want to do is set it up so my player can use it and it will ask them to pick a target and then put the type they pick onto the target token. !weapon-arc --add ?{Type|Cone, 60|Burst, 360} ?{Size|} ?{Color|Red, #ff0000|Blue, #6d9eeb|Green, #00ff00} I'm not sure where of how to put&nbsp; @{target|token_id} into this, as I have tried and it asks for the target, drop down menu for Type, Size, &amp; Color come up but then nothing happens.
1595846700
HI Aaron.&nbsp; I've been fiddle-farting around with this and loving it.&nbsp; I was just playing with the two first arguments, angle|width and range.&nbsp; I'm having difficulty understanding the definitions of angle and width.&nbsp; Anyway, I tried: !weapon-arc --add |70 12km And this generated a scripting error that I was unsure about clearing - I had to close my console and the game and restart and all was OK.&nbsp; Here's a screen shot of the console: FYI.&nbsp; All the best, -- Tim
1595851149
David M.
Pro
API Scripter
This is super cool! @Tim M -- Looks like you just omitted the angle in your command. If you include the pipe (|) in the --add option, seems to be looking for both angle (the direction of the centerline of the cone relative to token) and width (the full cone angle), e.g. --add 90|45 creates a cone with centerline 90deg clockwise from the top of the token, and a 45deg cone angle. The help says if you want to use the default rotation direction (straight up), omit angle and the pipe.
1595854488

Edited 1595854654
The Aaron
Forum Champion
API Scripter
What David M. said. =D&nbsp;&nbsp; Update v0.1.1 &nbsp;-- fixed crash when no angle or rotation are specified in the first argument.&nbsp; (Thanks&nbsp; Tim M )
1595874789
Angelo
API Scripter
this looks amazing! it would be great to have an "offset-mode" that makes the area start at the edge of the current square. For instance in these cases i would expect the area to start at the circled anchor point !weapon-arc --add 90 3u #00ffff33 #00ffffff 3 !weapon-arc --add 45|90 3u #00ffff33 #00ffffff 3
1595875104
The Aaron
Forum Champion
API Scripter
Angelo, is that more about the range being 3u from the edge, or about the arc a 90|45 arc not including half the squares in front of the token, or both?&nbsp;&nbsp; The two points you circled are at 2 different distances from the center of the token: .5u and (.5*sqrt(2))u&nbsp; Would the intent of an offset for you mean starting a constant distance from the center or starting on the edge of the bounding square?&nbsp; Would you expect a 90|45 arc on a token rotated 45º to be on the grid edge, or the token edge?&nbsp; And would you expect it to update if you rotate the token?
1595879455

Edited 1595880770
Angelo
API Scripter
i am just thinking in terms of D&amp;D 5e, if i say "3u" i would expect the area to start in front of my token and the edge to go all the way to 3 squares away (so to answer your question, both). Diagonals are tricky but i was expecting them to be counted in the same way the ruler tool does (not sure if this is the same in all systems). maybe it should always make it start in the square in front of my token, and from there pick the point on the edge/corner closest to my token? (half distance back towards the token) EDIT: found this in the compendium showing a 30ft cone
1595888047
The Aaron
Forum Champion
API Scripter
Your ruler is currently set to 4e, which is basically the longer of x or y.&nbsp; If you set it to Euclidian, you'll se 15ft at the arc edge: You can add an extra half unit in: !weapon-arc --add 45|90 3.5u I think the offset is a good idea regardless, so I'll try to add some options around that in a future update.&nbsp; I would like to take this idea and extend it to more of a spell effect sort of script.
1595889372

Edited 1595889543
David M.
Pro
API Scripter
Angelo said: i am just thinking in terms of D&amp;D 5e, if i say "3u" i would expect the area to start in front of my token and the edge to go all the way to 3 squares away (so to answer your question, both). Diagonals are tricky but i was expecting them to be counted in the same way the ruler tool does (not sure if this is the same in all systems). maybe it should always make it start in the square in front of my token, and from there pick the point on the edge/corner closest to my token? (half distance back towards the token) EDIT - Cross posted with Aaron&nbsp; Using the diagonal measuring tool approach would result in a cone that extends farther than 3u along the XY axes, which wouldn't make much sense in 5e. To keep the XY also 3u, it would be a square! (4e, anyone?). So I think the range must remain a true radius.&nbsp; I agree that an --origin|[center/edge/corner] option would be awesome. Take the case of a Huge (3x3) creature casting burning hands (15ft cone, 3u range and 3u wide at the outer edge). Doesn't work as-is. See picture below, which used&nbsp;&nbsp;--add 90|45 3u. Even if we did the extra math ahead of time o force the cone to extend the proper amount, it would be much wider at the "origin" than it should, and also too wide at the edge of the range (picture 2, forgive my reference triangle "cone").&nbsp; You could get closer by reducing the cone angle, but again more math. Using the approximated --add 90| 34 5 u gives us picture 3 (almost there). As-is, accounting for token size could be built into formulas in the macros, but would require separate macros for each token size with the current version.
1595891759

Edited 1595895110
Angelo
API Scripter
The Aaron said: Your ruler is currently set to 4e, which is basically the longer of x or y.&nbsp; If you set it to Euclidian, you'll se 15ft at the arc edge: You can add an extra half unit in: !weapon-arc --add 45|90 3.5u I think the offset is a good idea regardless, so I'll try to add some options around that in a future update.&nbsp; I would like to take this idea and extend it to more of a spell effect sort of script. I have never changed the ruler options, but from what i see in the page settings it's the same for 5e/4e, they don't use euclidean. The problem with just adding the size to compensate is that it's still covering squares directly to your left/right that it's not supposed to be covering. like David M was saying, having an "--origin|edge" option that automatically shifts it based on the token size would be amazing something like this works, you would need to get the token size dynamically, but for non-euclidean the formula needs to be changed to something else &nbsp;const addWeaponArc = (token,rotation,angle,length,c1,c2,stroke) =&gt; { &nbsp; &nbsp; let data = buildArc(angle,length); &nbsp; &nbsp; let visible = 'objects' === token.get('layer'); &nbsp; &nbsp; let newTop = token.get('top'); &nbsp; &nbsp; let newLeft= token.get('left'); &nbsp; &nbsp; let tokenSize = 70; &nbsp; &nbsp; let theta = degreeToRadian(rotation); &nbsp; &nbsp; newTop = newTop - tokenSize * 0.5 * Math.cos(theta); &nbsp; &nbsp; newLeft = newLeft + tokenSize * 0.5 * Math.sin(theta); &nbsp; &nbsp; let arc = createObj('path',{ &nbsp; &nbsp; &nbsp; fill: c1, &nbsp; &nbsp; &nbsp; stroke: c2, &nbsp; &nbsp; &nbsp; stroke_width: stroke, &nbsp; &nbsp; &nbsp; rotation: token.get('rotation')+rotation, &nbsp; &nbsp; &nbsp; width: 2*data.maxX, &nbsp; &nbsp; &nbsp; height: 2*data.maxY, &nbsp; &nbsp; &nbsp; top: newTop, &nbsp; &nbsp; &nbsp; left: newLeft, &nbsp; &nbsp; &nbsp; scaleX: 1, &nbsp; &nbsp; &nbsp; scaleY: 1, &nbsp; &nbsp; &nbsp; controlledby: token.id, &nbsp; &nbsp; &nbsp; layer: visible ? 'map' : 'gmlayer', &nbsp; &nbsp; &nbsp; path: pathDataFromPoints(data.points,rotation), &nbsp; &nbsp; &nbsp; pageid: token.get('pageid') &nbsp; &nbsp; });
1595910121
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
A 5e cone is approximately 60°. Or exactly &nbsp;53.13°... So I've been told. I'd use 60.
1595964751
Opacity Question Aaron, where in the command is opacity specified?&nbsp; Your help entry indicates a default of 99, but where would one but an alternate value in an example like this one? !weapon-arc&nbsp; --add&nbsp; 120 @{selected|bar2}km #b6d7a8 #000000 1
1595964946
David M. said: This is super cool! @Tim M -- Looks like you just omitted the angle in your command. If you include the pipe (|) in the --add option, seems to be looking for both angle (the direction of the centerline of the cone relative to token) and width (the full cone angle), e.g. --add 90|45 creates a cone with centerline 90deg clockwise from the top of the token, and a 45deg cone angle. The help says if you want to use the default rotation direction (straight up), omit angle and the pipe. Roger that, thanks, David. -- Tim
1595965056
The Aaron
Forum Champion
API Scripter
Tim M said: Opacity Question Aaron, where in the command is opacity specified?&nbsp; Your help entry indicates a default of 99, but where would one but an alternate value in an example like this one? !weapon-arc&nbsp; --add&nbsp; 120 @{selected|bar2}km #b6d7a8 #000000 1 It's in the HTML Color Entry.&nbsp;&nbsp; !weapon-arc --add 120 @{selected|bar2}km #b6d7a8 99 #000000 33 1 RRGGBB(AA)
1595965818
The Aaron said: What David M. said. =D&nbsp;&nbsp; Update v0.1.1 &nbsp;-- fixed crash when no angle or rotation are specified in the first argument.&nbsp; (Thanks&nbsp; Tim M ) Honoured to have been of help.&nbsp; Is the update in the same location as your first post mentions on github?&nbsp; I just copied what was there, but it appears to be the same, at least according to the help. -- Tim
1595965998
The Aaron
Forum Champion
API Scripter
Whoops!&nbsp; grab it now, it should be there.&nbsp; =D
1595977310
The Aaron said: Tim M said: Opacity Question Aaron, where in the command is opacity specified?&nbsp; Your help entry indicates a default of 99, but where would one but an alternate value in an example like this one? !weapon-arc&nbsp; --add&nbsp; 120 @{selected|bar2}km #b6d7a8 #000000 1 It's in the HTML Color Entry.&nbsp;&nbsp; !weapon-arc --add 120 @{selected|bar2}km #b6d7a8 99 #000000 33 1 RRGGBB(AA) Thanks so much for both replies! -- Tim
1595978193
The Aaron
Forum Champion
API Scripter
WeaponArcs 0.1.1 is in the 1-click installs now!
1596220597
David M.
Pro
API Scripter
Accidentally ran across this: I've noticed that when I have weapon-arcs enabled, I am unable to move any non-arc paths on any layer. They just snap back to their original location. When I disable the script, I can move stuff again.
1596220920
The Aaron
Forum Champion
API Scripter
Oh!!&nbsp; I'll take a look.
1596221408
The Aaron
Forum Champion
API Scripter
Update v0.1.2 &nbsp;-- fixed bug where WeaponArcs won't allow any paths to be changed, rather than just the Arc paths. (Thanks&nbsp; David M. )
1596498075

Edited 1596498795
Angelo
API Scripter
Hey Aaron,&nbsp; hope you don't mind but i took the liberty of slightly modifying the script and adding support for "edge areas". I have added a new "--onEdge" option to toggle it (on --add) , it also fixes the scaling problems that another user was having. In case you wanna merge it with yours here is a gist&nbsp; <a href="https://gist.github.com/ocangelo/cbb398bf9b5367d8b426d28bfa0d6d64" rel="nofollow">https://gist.github.com/ocangelo/cbb398bf9b5367d8b426d28bfa0d6d64</a> I have changed addWeaponArc, and&nbsp;onGraphicChange and added a new&nbsp;refreshArcGraphic to support scaling and areas along edges if you just care about those changes. The tricky part with the option is that i had to store that info somewhere and change how you were storing the original rotation, if you run this script and have some areas already saved/displayed those might be messed up (but you can clear all your areas with "!weapon-arc --clear" and then readd them), not sure if you can find a better solution EDIT:&nbsp; I have added an "--onOrigin" option as well and inside the defaults at the top a new one ("onEdge: false") to specify the default behavior
1596500853
The Aaron
Forum Champion
API Scripter
I'll take a look. I probably won't pull the code, but I plan on adding the functionality at least, though I might do it a different way. I have a way of dealing with updating the data storage based on the scemaVersion. You can look at checkInstall() in GroupInitiative fir an example of what it looks like.&nbsp;
1596513749

Edited 1596513836
Victor B.
Pro
Sheet Author
API Scripter
omfg, if you are using optional facing rules, this is golden.&nbsp; And shit you are forcing me to keep pace.&nbsp; I've got to come up with something else :)
1596547801

Edited 1596547851
The Aaron
Forum Champion
API Scripter
Update v0.1.3 &nbsp;-- added Arcs on the Edge, as well as Offset distances. (Thanks&nbsp; Angelo ) For arcs that begin at half the token's width away from the token, use the --addEdge subcommand: !weapon-arc --addEdge 60 2u You can also use --addE for convenience.&nbsp; It's case insensitive, so --addedge and --adde work fine also. This operates in all over ways just like --add. For offsets, you can preface the distance with an offset amount, just like you preface the width with an angle.&nbsp; Here is a 1u offset. !weapon-arc --add 60 1u|2u Offset with addEdge will offset from the edge: !weapon-arc --addedge 60 1u|2u And of course, you can chain a bunch of them together: This should be in the 1-click next week.&nbsp; I'm pretty sure I missed the cut off for this week.
1596562958
Angelo
API Scripter
nice! in that version there seems to be a bug when scaling a token, it doesn't refresh the offsets properly; also if the scale is non uniform it messes it up (e.g. 3u on height and 2u on width)
1596563125

Edited 1596563316
The Aaron
Forum Champion
API Scripter
Yeah, I was noticing the scale, problem the non-uniform I hadn't considered.&nbsp; I'll look at that for 0.1.4. =D On the non-uniform scale, where would you expect the edge to put it?
1596563728
Angelo
API Scripter
The Aaron said: Yeah, I was noticing the scale, problem the non-uniform I hadn't considered.&nbsp; I'll look at that for 0.1.4. =D On the non-uniform scale, where would you expect the edge to put it? I am personally not using non uniform scales (i play 5e), i am not sure what kind of behavior other systems would expect... if you look at the gist i have shared i was using cos/sin with the width/height separately and it seemed to be handling it fine