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

API/Token Association

Is there a way to have a token tied with an effect in such a way that when you drop the token onto your map that the effect happens? Let me give you an example. NPC #3 casts darkness... is there a way to tie the blindness condition automatically to the area of effect of the spell? I know I can use dynamic lighting to do so but I am talking about a way to do it quickly with little or no effort beyond the drag and drop?
1553255123

Edited 1553255182
GM Michael
API Scripter
Yes.  on('add:graphic', handler) will call the provided handler function.  You can then use established collision detection for tokens.  Then, if it's a character token, set the token's HasSight to false.  As for how to give them sight back, you call always just schedule another check in 500ms or so or have a handler for on('change:graphic', handler) that checks for things that normally have sight but presently don't and see if they still collide with darkness.
O.o Can I get that in english or perhaps non-tech speak? lol
Or maybe a better question perhaps is there a way an non-codey type can do it? :D
1553351646

Edited 1553351845
GM Michael
API Scripter
Unfortunately, no.  I'm not aware of an existing script that does what you're asking specifically, though a general-purpose spell handling script would be nice... In hopes that this way makes more sense, you'll want something like the below...  (warning: untested) // DEPENDENCY: Token Collisions // (in script library) // When a token is added on ( 'add:graphic' , ( newToken ) => { // Only bother if the newly-created token is a Darkness spell effect if ( token . get ( 'name' ) !== 'Darkness' ) return ; // get list of tokens on token layer on this page const currentPageTokens = findObjs ({ _pageid : Campaign (). get ( "playerpageid" ), _type : "graphic" , layer : 'objects' }); // define an array let collidingTokens = []; // Check each token for collisions currentPageTokens . forEach (( existingToken ) => { // Ignore tokens without attached sheets or vision if ( ! existingToken . get ( 'represents' ) || ! existingToken . get ( 'light_hassight' )) return ; // Using Token Collision's isOverlapping() function if ( isOverlapping ( newToken , existingToken , false )) { // Add this to the list collidingTokens . push ( existingToken ); // Blind the token existingToken . set ( 'light_hassight' , false ); } }); // Every 500ms, check to see if the tokens have moved away from the darkaness // and should get their sight back setTimeout ( checkForVisionClear , 500 , newToken , collidingTokens ); }); // Check to see if they are no longer overlapping. If they are, erase them from the list const checkForVisionClear = ( darknessToken , characterTokens ) => { let stillOverlapping = []; characterTokens . forEach (( charToken ) => { // If it's still overlapping, let's try again later if ( isOverlapping ( darknessToken , charToken , false )) { stillOverlapping . push ( charToken ); } else { // Restore the token's sight existingToken . set ( 'light_hassight' , true ); } }); if ( stillOverlapping . length > 0 ) { setTimeout ( checkForVisionClear , 500 , darknessToken , stillOverlapping ); } };