
Hey there, I'm planning a groundhog day style adventure and I thought it would be nice to save a token state were I can return to as soon as the loop starts over. If this already exists please tell me but I didn't found such a script :) The script is really simple: !groundhog save : saves the state of all tokens on the current players page (the one with the ribbon) I accidentally saved multiple times the wrong state so I'm using this macro now: !groundhog ?{Save and overwrite?|yes,save| } !groundhog morning : resets all saved tokens to the save state with the position, status & health I've also added a 1d3 (or 1) health reduction for each iteration but it is commented right now. As I'm planning to run the adventure 2-3 month from now I still have time to add more features and optimize it. Right now I'm planning: config menu attribute save selection health reduction configuration multiple save states (right now only one is kept) state cleanup If you guys have any suggestions please tell me as I cant talk to my players about it... obviously :D groundhog.js on ( 'chat:message' , function ( msg ) { if ( msg . type == "api" && msg . content . startsWith ( "!groundhog" )) { if (! state . Groundhog ) { state . Groundhog = { tokens : [] }; } if ( playerIsGM ( msg . playerid )) { let args = msg . content . replace ( / + (?= ) / g , '' ). split ( " " ); option = args [ 1 ] let currentPageID = Campaign (). get ( 'playerpageid' ), currentPage = getObj ( 'page' , currentPageID ); let object_tokens = findObjs ({ _pageid : currentPageID , _type : "graphic" }); if ( option == "save" ) { state . Groundhog . tokens = []; _ . each ( object_tokens , function ( token ) { let keys = [ "_id" , "_pageid" , "left" , "top" , "rotation" , "layer" , "bar1_value" , "bar2_value" , "statusmarkers" , "currentSide" ] var token_state = {} keys . forEach ( function ( item ) { token_state [ item ] = token . get ( item ); }); state . Groundhog . tokens . push ( token_state ); }); } if ( option == "morning" ) { _ . each ( object_tokens , function ( token ) { function isSaved ( o ) { return o . _id === token . get ( "_id" ); }; saved = state . Groundhog . tokens . find ( isSaved ); if ( saved ) { let savedCopy = Object . assign ({}, saved ); // decreasing health by 1 or 1d3 for each iteration // // savedCopy.bar1_value--; // savedCopy.bar1_value = savedCopy.bar1_value - randomInteger(3) // Object.assign(saved, savedCopy); token . set ( savedCopy ); } }); } } } });