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

[Script] Automatic Trap Detection - An advanced approach to pathing for token movement

&nbsp; Ok, this turned out to be a lot harder than I thought it would be. I have created a script which takes a given tokens path, and checks to see if it has crossed another token. I set up a sensativity meter as well. Essentially, it takes the token (in this case a trap token) and breaks each square it occupies down into 9 points (4 corners and 5 halfway points). If 5 (default) of the points appear in the token's path, it reads and displays the "DMNotes" on that token.&nbsp; To use it, copy and paste this script into a new script. Change the DM Name to the DM's display name (this does not effect settings, just shows who is sending the information is chat). Lastly, set the trap Prefix as you see fit. If you use default, your trap tokens name need to begin with "xTrap". You are all set to go. Place tokens on the GMLayer, name them xTrap___ and put the details of the trap in the GMNotes of the token. You can even include rolling information, which it will roll.&nbsp; As a nerd-warning, the below may not interest you if you don't want to understand how it works, and just want to use it. I want to break down how I built it so I can get feed back on how to make it run better. To build this, first I create a polygon build of the path of the characters movement. This turned out to be a huge challenge because you need all the outside points but need to delete the inside points or else they misshape the polygon. Then it needs to be sorted properly.&nbsp; Since it is all in a grip, you can get the min and max values on the X and Y axis, and if any point does not lie on either edge, it is a middle point and can be deleted.&nbsp; To sort it, I did a sort of the remaining points clockwise around from a center point (the average of the xMin / xMax and yMin/yMax. It picks each point as it goes in a circle until it is done. Essentially, you are drawing a polygon around the starting point and ending point of the given path. Then, once the system has a polygon, it then tests all tokens on the GM Layer for traps. If the tokens polygon path crosses your sensitivity rating in points of the trap-tokens square coverage, it executes. Building a formula for testing points was also a challenge. Here is the GIST:&nbsp; <a href="https://gist.github.com/DarokinB/5961100" rel="nofollow">https://gist.github.com/DarokinB/5961100</a> Here is a quick screen print:
Please note, this is not perfect and still having a problem with certain directions of movement giving an incorrect numbers of positive hits, so I need to clean this up. If others have ideas, please feel free to share.