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

[Help] Detecting adjacent tokens

1506537522
Missingquery
Pro
Sheet Author
API Scripter
I'm trying to figure out a way to detect adjacent tokens to a player token, and in the case that there are more than one adjacent enemy tokens (enemy status being based on an attribute, which at least can probably be detected), prompt which one they would like to attack. I was thinking it might be possible to have the player ping on the enemy token that they want to attack, but I'm not sure if there's any way to detect that kind of mouse event. Help?
1506537927
The Aaron
Pro
API Scripter
There isn't a way to detect pings. The basic algorithm will be: For all tokens on the same page and on the same layer, filter to only enemy tokens by represented character's attribute find distances from player token filter on distance < "some threshold" (probably either check horizontal and vertical distance separately for less than ~1 unit) Something else you could do is just have them move their token on top of the enemy they want to attack and have the script check for collisions and move the token back.
1506545168
Lithl
Pro
Sheet Author
API Scripter
The Aaron said: filter on distance < "some threshold" (probably either check horizontal and vertical distance separately for less than ~1 unit) Assuming the game takes place on a grid, ((sqrt(2) + epsilon) * 70) would be less than two squares horizontally or vertically, and more than one square diagonally. =)