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

[API question] is it possible to detect a token next to specific token?

1433416902

Edited 1433417139
What i want to achieve is following 1) There is a 'poisonous tree' monster token on map(square grid that of 70pixel size), this is not a 'selected' token by player nor GM, but i could provide token ID from @{selected|token_id} 2) I want a script that detects what token is next to(4 sides of right,above,down,left) it, or within range of specific distance(could be either pixel, or anything available) 3) give poison damage to Health(Character Attirubute) on given condition (every turn, when given chat command, etc) is there a way to achieve this?
1433417501
Ziechael
Forum Champion
Sheet Author
API Scripter
I'm by no means an expert with the API but i can safely say that this is most certainly possible (possibly ;) ). Rather than make you wait until later when the real scripters wake up. I would envision something to do with token auras and collision combined with gm notes to provide the damage text/output/information for altering bars etc... excited to see what the true genius' come up with =D
1433417806

Edited 1433417909
The Aaron
Pro
API Scripter
Yes, definitely possible. The important part is when to determine it. You would probably want to do it on('change:graphic:lastmove',...). The basic steps would be: 0) configure script with the ID of the poisonous tree 1) when a token moves, get the poisonous tree object (probably cache it so it's faster) 2) check the page ids are the same. 3) check the positions relative to each other (probably easiest to just check the Pythagorean distance) 4) apply the effects (or notify the GM or player or all) For the distance check, note that the location of objects (left x top) is to the center of the object. The grid is 70 x 70, so an object that is right next to another will be a distance of 70 apart. I would suggest comparing that the distance is less than some threshold (probably 80) just to avoid rounding errors. ( It probably doesn't matter, but you can optimize the distance check by skipping the square root and comparing to the square of the threshold.)
1433417910
Ziechael
Forum Champion
Sheet Author
API Scripter
see... told you so, Aaron should be in bed though which is why i didn't want you to have to wait!
The Aaron said: Yes, definitely possible. The important part is when to determine it. You would probably want to do it on('change:graphic:lastmove',...). The basic steps would be: 0) configure script with the ID of the poisonous tree 1) when a token moves, get the poisonous tree object (probably cache it so it's faster) 2) check the page ids are the same. 3) check the positions relative to each other (probably easiest to just check the Pythagorean distance) 4) apply the effects (or notify the GM or player or all) For the distance check, note that the location of objects (left x top) is to the center of the object. The grid is 70 x 70, so an object that is right next to another will be a distance of 70 apart. I would suggest comparing that the distance iscless than some threshold (probably 80) just to avoid rounding errors. ( It probably doesn't matter, but you can optimize the distance check by skipping the square root and comparing to the square of the threshold.) thank you, i could try writing down a script now. btw its a different question, has anyone found a legit way of moving a selected token from one page to another? I google searched for hours but couldn't find answer to this
1433419498

Edited 1433419569
The Aaron
Pro
API Scripter
The page id of a graphic is read only (that's what the _ on the front means (but you can and should leave it off for .get('pageid')) ), so you can't move them. The alternate option is to create a new graphic with the identical properties on another page. This works part of the time, the limiting factor is where the graphic image is stored. Images in a user library can be created by the API, but marketplace images cannot. That is why you haven't found a solution online. It is entirely possible that a future update will remove this limitation, and then you will see many scripts that make use of the new functionality.