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

Trying to make a Script that Clears Statuses on New Round

So to add context to this question: I have a turn in the turn order named Round and it counts +1 every time it reaches its turn. This is to help track the rounds that pass during combat for very specific mechanics. What I'm trying to accomplish is making an API that clears a specific status from all tokens on the map when it reaches the new Round and it counts up. So if any tokens had say, the Stasis status, the API would clear it from all tokens when the turn order gets to Round. My knowledge of JavaScript is decent but I'm having trouble figuring out how to have the API either find the status marker itself on tokens and remove it or go through all tokens on the map and check for the status and then clear it. I managed to sorta make the latter work but it was prone to lag in larger group fights. I have also failed miserably to find any documentation for statuses specifically, and have basically tested other existing APIs and learned what worked from those. Any help or ideas would be greatly appreciated. In the past I did have success with clearing specific statuses from tokens using their order in the turn order, EG clearing Poison when it reaches someone's turn but that's not what I'm after this time.
1636427927
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Combat Master will do this. It has the ability to trigger macros and statuses on certain events, including a new round. It's available in the One Click install.
You need to also install statusinfo api if you want this to work with statusmarkers I think.  And a few mainstay 5e conditions need to be added as they aren't in by default.  
1636562379
The Aaron
Roll20 Production Team
API Scripter
Do you only care about tokens in the turn order, or do you literally mean all the tokens on the current map page?  (and do you just me on the objects layer, or GM Layer also?)
1636563037
The Aaron
Roll20 Production Team
API Scripter
Something like this should let you do the clearing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 const ClearStatusOnPage = ( pageid , status , layers = [ 'objects' ]) => { let tokens = findObjs ({ type : 'graphic' , pageid : pageid }). filter ( g => layers . includes ( g . get ( 'layer' ))); const burndown = () => { let t = tokens . shift (); if ( t ){ t . set ( ` status_$ { status } ` , false ); setTimeout ( burndown , 0 ); } }; burndown (); }; /* ... */ ClearStatusOnPage ( somePageid , 'statis' ); ClearStatusOnPage ( somePageid , 'statis' ,[ 'objects' , 'gmlayer' ]); This will do the clearing asynchronously, which will prevent the API from hanging while it does it.  The findObjs() on line 2 builds a list of the tokens that are on the page (either on the objects layer only, or on multiple layers if those are passed in).  The burndown() function on line 7 takes a token off the array of tokens to change, then sets the status to false (removing it), then sets a timeout to call itself on the next cycle. When the array is empty, it won't set another timeout.  Line 19 is an example of calling it for just the objects layer, line 20 for objects and the gm layer. Note: I've not tested this function, but it should work.
1636563126
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
DM Eddie said: You need to also install statusinfo api if you want this to work with statusmarkers I think.  And a few mainstay 5e conditions need to be added as they aren't in by default.   In case the "also" is referring to my post, Combat Master subsumed StatusInfo. If you install both, you will like have duplication of function and unintended results.
Very late response because recent work hours have been brutal but to clarify I did want it to effect all tokens on the map regardless of whether they are present in the turn order, and it looks like your code achieves that. I'll try both Keith's and Aaron's solutions with the statusinfo API, since Combat Master may also have some other goodies I don't know I want yet. Even if it doesn't, being able to have this function for special cases would be a good thing to have on hand. I didn't think to look for the tokens via graphics on a specified layer. I might have fallen victim to overcomplicating the solution and getting stuck. I'll test both and see what works.