buttonpushertv

FVTT Macro - Reset Token

Jun 20th, 2021
749
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This will reset a token to it's defaults & remove all conditions
  2.  
  3. let macroA = game.macros.getName("Remove Conditions");
  4.  
  5. for ( let token of canvas.tokens.controlled ){
  6.    console.log("############# Starting to process a token.");
  7.  
  8.    let showingName = token.actor.data.name;
  9.  
  10.    remove();
  11.  
  12.    console.log("############# Conditions should now be removed.");
  13.  
  14.    // This sets the token's maxHP to the value stored in FVTT for that token
  15.    let maxHP = token.actor.data.data.attributes.hp.max;
  16.    token.actor.update({"data.attributes.hp.value": maxHP});
  17.  
  18.    console.log("############# Creating chat message.");
  19.  
  20. let messageContent = `${showingName} has been reset to ${maxHP} hit points. And all conditions have been removed.`;
  21.     ChatMessage.create({user : game.user._id, content : messageContent, whisper : ChatMessage.getWhisperRecipients("GM") // Whispering this is important so you don't show everyone maxHP!
  22.     });
  23.   console.log("############# Reached the end of processing a token.");
  24. }
  25.  
  26. // This async function removes all existing conditions & overlays
  27. async function remove() {
  28.    await macroA.execute();
  29. }
RAW Paste Data