Description[edit | edit source]

Google Apps Script is a scripting language based on JavaScript that lets you manipulate Habitica and other G Suite products like Calendar, Docs, Sheets, Slides, and Forms. There's nothing to install — you use the code editor right in your browser, and your scripts run on Google's servers. All scripts can be scheduled to give a level of autonomy.

Usage[edit | edit source]

In order to use this feature, you need to have a Gmail account. It is recommended that you keep all scripts private, because you need to embed your Habitica User ID and API Token in the script.

Other than the Auto Cron script, no other scripts will cause you to cron. For example, if you cast a party buff after your Custom Day Start, you will still have to either run the Auto Cron or use Habitica website/apps to cron.

When scheduling the scripts, do not schedule them to run more than hourly. Be nice to Habitica servers! When setting up a script for the first time, it may be best to run the script manually by choosing Run => Run function => [Script to be scheduled] to check that it runs without errors before scheduling it.

Manually-Driven Scripts[edit | edit source]

Bulk Attack Quest Boss[edit | edit source]

by cTheDragons

This script is great for Warriors and Mages that will allow you to bulk attack the quest boss.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor
    • Replace the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with your own Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
    • Change the ntimes to how many times you wish to use a skill each run. Currently, this is set to 8.
    • Change the skillId to skill you wish to cast based what is described in the comments in options. Below it is currently set to Burst of Flames with skillId = "fireball"
    • Change the targetId to match one of your tasks. To find the task id:
      • Open the Data Display Tool
      • Go to the section for Task Overview.
      • Search for the task name you wish to target (if you are unsure which is best, check under Skills and Buffs for a recommendation based on the skill you are using).
      • Click toggle developer data to show the task id (it is a long string of numbers and letters like 6eb598a1-886a-4be6-a6c5-9e9fdc8f5b44 as per example below).
 function bulkAttackBoss() {
 
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
   var ntimes = 8
   var skillId = "fireball"
   var targetId = "6eb598a1-886a-4be6-a6c5-9e9fdc8f5b44"   
   
   /*
   Below is a list  of options of the party buff skills. Replace the value in skillId above for the skill you desire. Ensure you copy the quotes.
   See http://habitica.fandom.com/wiki/Skills for more information on skills.
   Options for skills:
     Warrior Brutal Smash: "smash" 
     Mage Burst of Flames: "fireball"
   */
   var url = "https://habitica.com/api/v3/user/class/cast/" + skillId + "?targetId=" + targetId 
   var sleepTime = 30000
   
   //set paramaters
   var paramsTemplate = {
     "method" : "post",
     "headers" : {
       "x-api-user" : habId, 
       "x-api-key" : habToken
     }
   }
   var params = paramsTemplate;
 
   for (var i = 0; i < ntimes; i++) { 
     UrlFetchApp.fetch(url, params)
     Utilities.sleep(sleepTime);// pause in the loop for 30000 milliseconds (30 seconds); this is to avoid the servers being overloaded
   }
 }
  • Save the script.
  • From the menu choose Run => Run function => bulkAttackBoss.

Bulk Buy Enchanted Armorie[edit | edit source]

by cTheDragons

This script will allow you to bulk buy from the armorie and allow you to view the results in the logs.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor
    • Replace the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
    • Change the ntimes to how many times you wish to buy from the armorie each run. Currently set to 5.
 function bulkBuyArmorie() {
 
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
   var ntimes = 5
 
   var url = "https://habitica.com/api/v3/user/buy-armoire" 
   var sleepTime = 30000
   var response
   
   //set paramaters
   var paramsTemplate = {
     "method" : "post",
     "headers" : {
       "x-api-user" : habId, 
       "x-api-key" : habToken
     }
   }
   var params = paramsTemplate;
 
   for (var i = 0; i < ntimes; i++) { 
     response = UrlFetchApp.fetch(url, params)
     var result = JSON.parse(response);
     Logger.log(result.message)
     if (result.data.armoire.type == 'food') {
       Logger.log("You gained " + result.data.armoire.dropText + ".")
     } else {
       Logger.log("You gained " + result.data.armoire.value + " " + result.data.armoire.type + ".")    
     }
     Utilities.sleep(sleepTime);// pause in the loop for 30000 milliseconds (30 seconds); this is to avoid the servers being overloaded
   }
 }
  • Save the script.
  • From the menu, choose Run => Run function => bulkBuyArmorie.
  • From the menu, choose View => Logs to view what you received.

Time-Driven Scripts[edit | edit source]

Auto Cron[edit | edit source]

by cTheDragons

Run after your Custom Day Start, this script will cron you automatically. Please note, using this method will not allow you to use the Record Yesterday's Activities. Any dailies not ticked off at the time of cronning will be marked as missed.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor, replacing the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
 function scheduleCron() {
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
 
   paramsTemplate = {
     "method" : "post",
     "headers" : {
       "x-api-user" : habId, 
       "x-api-key" : habToken
     }
   }
   
   var params = paramsTemplate;
   UrlFetchApp.fetch("https://habitica.com/api/v3/cron", params)
 }
  • Under Edit, select Current project's triggers. Then add a trigger that runs scheduleCron Time-driven on a Day timer with the parameter of the same hour starting with your Custom Day Start. For example if your Custom Day Start is midnight set your trigger to Midnight to 1am.
  • Save and you're done!

If you have cron before the script has run, the script will not do anything. You can use this feature as a catch all in case you miss your regular time. For example if your Custom Day Start is set to midnight, you can set this script to run at 3am to 4am. This will allow you cron manually between midnight and 3am, and thus use the Record Yesterday's Activities feature if you have a late night. Otherwise this script will cron you automatically between 3am and 4am so your party quest damage occurs before you wake up.

Auto Accept Quests[edit | edit source]

by cTheDragons

(Note: An upgraded version of this script with an easy step by step setup guide with pictures can be found on this link)

Run hourly, this script will join a quest automatically if the invite is available in your party.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor, replacing the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
 function scheduleJoinQuest() {
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
 
   var paramsTemplate = {
     "method" : "get",
     "headers" : {
       "x-api-user" : habId, 
       "x-api-key" : habToken    
     }
   }  
   var response = UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party", paramsTemplate);
   var party = JSON.parse(response);
 
   if ((party.data.quest.key != undefined) && (party.data.quest.active != true) && (party.data.quest.members[habId] == undefined)){
   paramsTemplate = {
       "method" : "post",
       "headers" : {
         "x-api-user" : habId, 
         "x-api-key" : habToken       
       }     
     }
     var params = paramsTemplate;
  
     UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party/quests/accept", params)
   }
 }

OR more clear code below:

const scheduleJoinQuest = () => {
  const habId = '#HabiticaUserID#';
  const habToken = '#HabiticaAPIToken#';
  const partyAPI = 'https://habitica.com/api/v3/groups/party';
  const headers = {
    'x-api-user': habId,
    'x-api-key': habToken,
  };
  const response = UrlFetchApp.fetch(
    partyAPI,
    {
      method: 'get',
      headers
    }
  );
  const { data: { quest } } = JSON.parse(response);

  if (quest.key && !quest.active && !quest.members[habId]) {
    UrlFetchApp.fetch(
      `${partyAPI}/quests/accept`,
      {
        method: 'post',
        headers
      }
    );
  }
}
  • Under Edit, select Current project's triggers. Then add a trigger that runs scheduleJoinQuest Time-driven on a Hour timer with the parameter of Every hour.
  • Save and you're done!

Auto Force-Start Quests[edit | edit source]

Below are two alternative versions of a script that force-starts pending quests: one for parties where members who want to participate are expected to join the quest soon after the invite has been sent (practically ones where everyone uses the auto accept script) and one for parties where a longer time window is to be given for members to manually join quests.

NB: only party leader can force-start all quests in the party, so it is recommended that the script is run by the party leader. Another option is to have all people who send quest invites run their own script.

Installation instructions:

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below (choose one from the twoalternatives) into the editor, replacing the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
  • Under Edit, select Current project's triggers. Then add a trigger that runs forceStartQuest Time-driven, see suggested values for each script.
  • Save and you're done!

Version for Parties Mandating Auto Accept Script Use[edit | edit source]

by justuskraft

This script force-starts a pending quest after 1 to 2 hours. It is best used in combination with the auto accept quest script. That way everyone who wants to participate in the quest can do so by enabling auto accept quest, and if some people don't want to take part the quest owner doesn't have to start the quest manually after said time. The Time-driven trigger for this script should be set to a Hour timer with the parameter of Every hour.

function forceStartQuest() {   
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
   var scriptProperties = PropertiesService.getScriptProperties();
   var paramsTemplate = {
       "method": "get",
       "headers": {
           "x-api-user": habId,
           "x-api-key": habToken
       }
   }
   var response = UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party", paramsTemplate);
   var party = JSON.parse(response);
   if (scriptProperties.getProperty('PENDING_QUEST') == 'true') {
       scriptProperties.setProperty('PENDING_QUEST', 'false');
       paramsTemplate = {
           "method": "post",
           "headers": {
               "x-api-user": habId,
               "x-api-key": habToken
           }
       }
       var params = paramsTemplate;
       UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party/quests/force-start", params);
   } else if ((party.data.quest.key != undefined) && (party.data.quest.active != true)) {
       scriptProperties.setProperty('PENDING_QUEST', 'true');
   } else {
       scriptProperties.setProperty('PENDING_QUEST', 'false');
   }
}


Version Starting the Quest After a Specified Time[edit | edit source]

by Antonbury

This script can be configured to wait for a number of hours before starting the quest, making it possible to automatically start quests in parties where all members do not use the auto accept script. This script is based on the no-delay version of the script, which has been created by justuskraft.

To set the delay between the invite being noticed by the script and the quest being started, edit the value of time_to_join_hours. For example to give party members 5 hours to join the quest, the fourth line of the script should be

var time_to_join_hours = 5

The part on the original line after // is a comment and does not affect the script, it can be left there or removed.

Setting the parameters for the Time-driven trigger for this script is a bit more free than for the script above, as script running interval does not singularly dictate the quest starting delay. Long intervals do increase the time from invite being sent out to the script noticin it though, and thus a relatively short interval can be handy especially if the time frame for joining the quests is reasonably short, for example Minute timer with the value of Every 15 minutes has worked well.

// Edit the three lines below to match your needs
var habId = "#HabiticaUserID#"; // Your Habitica ID: found under settings -> API -> user ID
var habToken = "#HabiticaAPIToken#"; // Your Habitica API token: found under settings -> API -> Show API Token
var time_to_join_hours = 5 // How many hours should the quest invite at least be out before force starting


// Do not edit anything below (unless you know what you are doing)

var time_to_join_ms = time_to_join_hours*60*60*1000;
var api_headers = {
  "x-client": "f687a6c7-860a-4c7c-8a07-9d0dcbb7c831-QuestForceStarter",
  "x-api-user": habId,
  "x-api-key": habToken
}

function forceStartQuest() {
  var scriptProperties = PropertiesService.getScriptProperties();
    var params = {
        "method": "get",
        "headers": api_headers,
      }

  var response = UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party", {"method": "get", "headers": api_headers});
  var party = JSON.parse(response);
  var current_time = new Date();
  
  if ((party.data.quest.key == undefined) || (party.data.quest.active == true)) { // either there's no invite out, or the quest has already begun
    scriptProperties.setProperty('PENDING_QUEST', 'false');
    return;
  }
  
  if (scriptProperties.getProperty('PENDING_QUEST') == 'true') { // there's an active invite we have seen before
    var invite_time = current_time - Date.parse(scriptProperties.getProperty('INVITE_TIMESTAMP')); // how long the invite is known to have been out (in ms)
    if (invite_time > time_to_join_ms) {
      UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party/quests/force-start", {"method": "post", "headers": api_headers});
      scriptProperties.setProperty('PENDING_QUEST', 'false');
    }
  } else if ((party.data.quest.key != undefined) && (party.data.quest.active != true)) { // there's an active invite we haven't seen before
    scriptProperties.setProperty('PENDING_QUEST', 'true');
    scriptProperties.setProperty('INVITE_TIMESTAMP', current_time);
  }
}

Version Starting the Quest Based on Number of Participants[edit | edit source]

by Antonbury

This version of the script starts the quest when a certain number of party members have accepted the invite. That way if the party for example has known inactive members, the quest can be started automatically as soon as all active members have accepted the invite: just set the required_participants to the number of active members in your party.

If you are not the party leader you can still force-start quests for which you sent the invite out yourself. In that case, set own_quests_only to true.

This script should be run with a time-driven trigger similar to the one for the time-based starting script. I recommend Minute timer with Every 15 minutes or some other short-ish interval.

// Edit the four lines below to match your needs
var habId = "#HabiticaUserID#"; // Your Habitica ID: found under settings -> API -> user ID
var habToken = "#HabiticaAPIToken#"; // Your Habitica API token: found under settings -> API -> Show API Token
var required_participants = 10 // How many people should have accepted the quest invite before force starting
var own_quests_only = false; // Change the 'false' here to 'true' if you only want to auto-start your own quests


// Do not edit anything below (unless you know what you are doing)
var api_headers = {
  "x-client": "f687a6c7-860a-4c7c-8a07-9d0dcbb7c831-QuestForceStarter_participants",
  "x-api-user": habId,
  "x-api-key": habToken
}

function forceStartQuest() {

  var params = {
    "method": "get",
    "headers": api_headers,
  }
  var response = UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party", params);
  var party = JSON.parse(response);


  if (own_quests_only && party.data.quest.leader != habId) {
    return;
  }

  if ((party.data.quest.key != undefined) && (party.data.quest.active != true)) {
    if (Object.values(party.data.quest.members).filter(Boolean).length >= required_participants) {
      var params = {
        "method": "post",
        "headers": api_headers,
      }
      UrlFetchApp.fetch("https://habitica.com/api/v3/groups/party/quests/force-start", params);
    }
  }
}

Auto Cast Party Buff Skills[edit | edit source]

by cTheDragons

Run at specific times, this script will buff your party n number of times with your desired party buff. This script is deliberately designed not to check if you have enough mana first so it will error if it does not meet the buffing criteria.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor
    • Replace the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
    • Change the ntimes to the number of buffs you wish to do each run. Currently set to 3.
    • Change the skillId to skill you wish to cast based what is describe in the comments in options. Below it currently set to Earthquake with skillId = "earth"
 function schedulePartyBuff() {
 
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
   var ntimes = 3
   var skillId = "earth"
   /*
   Below is a list  of options of the party buff skills. Replace the value in skillId above for the skill you desire. Ensure you copy the quotes.
   See http://habitica.fandom.com/wiki/Skills for more information on skills.
   Options for skills:
     Warrior Valorous Presence (STR): "valorousPresence" 
     Warrior Intimidating Gaze (CON): "intimidate" 
     Rogue Tools of Trade (PER): "toolsOfTrade"
     Healer Protective Aura (CON): "protectAura"
     Healer Blessing (HP): "healAll"
     Mage Ethereal Surge (mana): "mpheal"
     Mage EarthQuake (INT): "earth"
   */
   var url = "https://habitica.com/api/v3/user/class/cast/" + skillId 
   var sleepTime = 30000
   
   //set paramaters
   var paramsTemplate = {
     "method" : "post",
     "headers" : {
       "x-api-user" : habId, 
       "x-api-key" : habToken
     }
   }
   var params = paramsTemplate;
   
   for (var i = 0; i < ntimes; i++) { 
     UrlFetchApp.fetch(url, params)
     Utilities.sleep(sleepTime);// pause in the loop for 30000 milliseconds (30 seconds); this is to avoid the servers being overloaded
   }
 }
  • Under Edit, select Current project's triggers. Then add a trigger that runs schedulePartyBuff Time-driven on a Day Timer with the parameter of which time is best.
  • Click notifications, change the second parameter from daily to immediate (this will alert you if you failed to cast the number of party buffs).
  • Save and you're done!

If you wish this to run immediately instead of waiting on a trigger, from the edit window of the project, menu choose Run => Run function => schedulePartyBuff.


Auto Schedule To-Do's with Google Calendar[edit | edit source]

by Snickersnacker

The script will create specific to-dos in your calendar on a specified date. Effectively giving a to-do a "start date".

  • Create a new calendar in your personal Google Calendar name HabiticaReminders.
  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor, replacing the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
 function scheduleToDos() {
   var habId = "#HabiticaUserID#";
   var habToken = "#HabiticaAPIToken#";
 
   var now = new Date();
   var events = CalendarApp.getCalendarsByName("HabiticaReminders")[0].getEventsForDay(now);
 
   var paramsTemplate = {
     "method" : "post",
     "headers" : {
       "x-api-user" : habId, 
       "x-api-key" : habToken
     }
   }
 
   for (i = 0; i < events.length; i++) {
     var params = paramsTemplate;
     params["payload"] = {
       "text" : events[i].getTitle(), 
       "type" : "todo",
       "priority" : "1.5"
     }
 
     UrlFetchApp.fetch("https://habitica.com/api/v3/tasks/user", params)
   } 
 }
  • Under Edit, select Current project's triggers. Then add a trigger that runs scheduleToDos Time-driven on a Day timer. Suggested time is after your cron, early in the morning like 3-4am.
  • Save and you're done!

At the daily time, the script will harvest all the events in a Google Calendar called HabiticaReminders scheduled for that day. It will then add them to Habitica as medium priority to-do's. To schedule a future task, simply select the correct day in Google Calendar and add an event with the to-do text as a title. Make sure you add it to HabiticaReminders and not your default calendar. Suggestion is to hide the calendar the rest of the time, so it doesn't clutter the calendar interface.

Note: The default timezone for Google Scripts is America/Los_Angeles (Pacific time). If your calendar is in a different timezone, this will not be taken into account. The easiest way to address this is to add an app manifest and change the timezone to one of the valid values that corresponds to the timezone of your calendar.

Auto Bulk Remove Habitica Emails[edit | edit source]

by cTheDragons

The script will remove all emails from your Gmail box from x days that are from Habitca (default below is 14). For this to work, ensure the gmail account you are running the script from is the email linked to your Habitica Account.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor
    • Adjust daysAgo on how many days you wish to keep in your Inbox for.
    • Adjust onlyInbox, if you want to search all your email (archive too) for Habitica based emails.
    • Remove any items in removeSubject Array that you do not wish to archive.
 function removeHabiticaMessages() {
   var daysAgo = 14
   var onlyInbox = true
   var removeSubject = ['You Received a Private Message!', 'Your Quest Has Started!', 'Help % battle the', 'Help % Complete the','You Won a Challenge on Habitica!', 'has gifted you some gems!', 'Fight Monsters (and Bad Habits)!', 'Removed from Party', 'Wants You to Join a Guild!', 'Removed from Guild']
   // This is the items in list - Received a PM, Quest Start, Request to Fight a Boss Quest, Request to Complete Collection Quest, Won a Challenge, Received Gems, Invited to Party, Remove From Party,  Invited to Guild, Remove From Guild
  
   var now = new Date();
   var removalDate_Raw = new Date(now.getTime()-daysAgo*(24*3600*1000))
   var removalDate = Utilities.formatDate(removalDate_Raw, 'GMT', 'yyyy/MM/dd') 
 
   for (var i = 0; i < removeSubject.length; i++) {
     var criteria = 'subject:' + removeSubject[i] + ' from:messengers@habitica.com before:' + removalDate;
     if (onlyInbox) criteria += ' in:Inbox'
     var conversations = GmailApp.search(criteria);
   
     for (var idx = 0; idx < conversations.length; idx = idx + 1) {    
       var thread = conversations[idx];
       thread.moveToTrash()
     }
   }
 }
  • Under Edit, select Current project's triggers. Then add a trigger that runs removeHabiticaMessages Time-driven on a Day timer. Suggested time is after your cron, early in the morning like 3-4am.
  • Save and you're done!

At the daily time, the script will review all your emails, and remove them as specified from Habitica.

Auto Change Pet and Mount Randomly[edit | edit source]

by Ieahleen

This script will change your pet and mount randomly. It will not do anything (skip) if you have only 1 or 0 pet / mount. You just need to set your own User ID and API Token in the first in place of `#HabiticaUserID#` and `#HabiticaAPIToken#`, and then set the trigger with the interval you prefer. (I set it to daily change, during the night, so the morning gives me a new surprise). If you want to change only the pet or only the mount, remove the block of code below the appropriate "randomly change the pet/mount" comment.

  • Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
  • Paste the code snippet below into the editor, replacing the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
 function randomlyChangePetAndMount() {
   var habId = "#HabiticaUserID#";  // add here your User ID
   var habToken = "#HabiticaAPIToken#";  // add here your API Token
   var paramsTemplate = {
     "headers": {
       "x-api-user": habId,
       "x-api-key": habToken
     }
   }

   /* get the pets and mounts owned */
   paramsTemplate.method = "get";
   var response = UrlFetchApp.fetch("https://habitica.com/api/v3/user" + "?userFields=" + "items", paramsTemplate)
   var parsed = JSON.parse(response);
   var items = parsed.data.items;
   var pets = Object.keys(items.pets).filter(p => items.pets[p]);
   var mounts = Object.keys(items.mounts).filter(m => items.mounts[m]);

   /* randomly change the pet */
   if (pets.length > 1) {
     // remove current pet from list of new pet candidates
     if (pets.includes(items.currentPet)) {
       var currentPetIndex = pets.indexOf(items.currentPet);
       pets.splice(currentPetIndex, 1);
     }
     var randomPet = pets[Math.floor(Math.random() * pets.length)];
     paramsTemplate.method = "post";
     UrlFetchApp.fetch("https://habitica.com/api/v3/user/equip/pet/" + randomPet, paramsTemplate)
   }

   /* randomly change the mount */
   if (mounts.length > 1) {
     // remove current mount from list of new mount candidates
     if (mounts.includes(items.currentMount)) {
       var currentMountIndex = mounts.indexOf(items.currentMount);
       mounts.splice(currentMountIndex, 1);
     }
     var randomMount = mounts[Math.floor(Math.random() * mounts.length)];
     paramsTemplate.method = "post";
     UrlFetchApp.fetch("https://habitica.com/api/v3/user/equip/mount/" + randomMount, paramsTemplate)
   }
 }
  • If you are interested only to the change of the pet remove the block of code below "randomly change the mount", if you are interested only to the change of the mount remove the block of code below "randomly change the pet.
  • Now add a trigger. Under Edit, select Current project's triggers. Then add a trigger that make the script run on your preferred schedule.

Streamlined Event-Driven Scripts[edit | edit source]

Streamlined scripts allow the user to set up event-driven scripts with fewer number of steps and without going back and forth between different tools.

Change Costume, Background, Pet, and Mount[edit | edit source]

by @EugeneG

Features

  • Creates buttons on the user’s Rewards column to save (remember) the current appearance
    • Includes costume, background, pet and mount
  • Creates buttons to load (wear) a remembered appearance
    • Up to five by default. The user can manually add Rewards buttons for more.
  • Notifies the user via private message when an appearance has been saved or completely loaded
    • Notifications can be disabled
  • Rate limit checking (sends "retry after X seconds" message)

First-Time Setup Instructions

Code

Optional Customizations

  • ENABLE_NOTIFICATION can be set to 0 to disable notifications

Usage Tips

Known Issues

Update Instructions

  • If you already had an earlier version of the script set up previously and want to update to a newer version, simply do Part 2. Update External Script
  • No need to do Part 1 and Part 3
  • Note that on the first time you load a costume after updating, it might take a bit longer than usual to take effect (around 15 seconds). On the second time and onwards this delay will no longer be present.

Credits and Acknowledgments


Change Equipment[edit | edit source]

by @maybexx, based on the Change Costume, Background, Pet, and Mount script by @EugeneG

Features

  • Creates buttons on the user’s Rewards column to save (remember) the current equipment set
    • Does not affect costume/background/pet/mount
  • Creates buttons to load (wear) a remembered equipment set
    • Four equipment sets by default (STR, CON, INT, PER). The user can manually add Rewards buttons for more.
  • Notifies the user via private message when an equipment set has been saved or completely loaded
    • Notifications can be disabled
  • Rate limit checking (sends "retry after X seconds" message)

First-Time Setup Instructions

Code

Optional Customizations

  • ENABLE_NOTIFICATION can be set to 0 to disable notifications

Usage Tips

Known Issues

Update Instructions

  • If you already had an earlier version of the script set up previously and want to update to a newer version, simply do Part 2. Update External Script
  • No need to do Part 1 and Part 3
  • Note that on the first time you load an equipment set after updating, it might take a bit longer than usual to take effect (around 15 seconds). On the second time and onwards this delay will no longer be present.

Credits and Acknowledgments

  • @EugeneG for the original Change Costume, Background, Pet, and Mount script, plus all other credits and acknowledgements of that script:

Faster Auto Accept Quests and Auto Notify on Quest End[edit | edit source]

by @EugeneG

Features

  • Auto accepts quest invites within a few seconds of receiving the quest
  • Notifies via private message when a quest has just finished (to have priority in setting up the next quest)
  • Either of the features above can be disabled
  • Rate limit checking (auto-retries after delay)
  • Auto creation of hourly trigger for auto accepting quests as backup on the rare times Habitica's webhook fails to trigger the script

First-Time Setup Instructions

Code

Optional Customizations

  • ENABLE_AUTO_ACCEPT_QUESTS can be set to 0 to disable auto accepting quests
  • ENABLE_QUEST_COMPLETED_NOTIFICATION can be set to 0 to disable auto notify on quest end

Update Instructions

YouTube step by step instructions

Credits and Acknowledgments

  • @steelblade for initial webhook tips and debugging help

Warrior Subclasses[edit | edit source]

by @EugeneG

Features

  • Gives Warriors who have reached level 60 the option to choose one of these four subclasses:
    1. Berserker “The one who rushes into the battle, regardless of the dangers ahead.”
      Pay 5-10 Health* to gain up to 20 Mana.
    2. Defender “The valiant protector of righteousness.”
      Use the Defender's versions of Valorous Presence or Intimidating Gaze for 50% chance to triple-cast the skill (2nd & 3rd free). Max of 8 times per day.
    3. Gladiator “Are you not entertained?!”
      Pay 5-10 Health* to gain up to 100 Gold.
    4. Blademaster “The expert, training night and day to gain new techniques.”
      Pay 5-10 Health* for a chance to instantly level up (% = 480/level. i.e. 8% at level 60).
      * Cost goes down to 5 Health at 250 CON (equipment and buffs included). Max of 50 Health used per day.
  • Rate limit checking (sends "retry after X seconds" message)

First-Time Setup Instructions

Code

Optional Customizations

  • NOTIFICATION_CHANCE can be changed to adjust the chance of notifications (max 0.25)

Update Instructions

Credits and Acknowledgments

Warrior, Mage, Healer, Rogue Subclasses[edit | edit source]

by @EugeneG

Features

  • Gives Habiticans who have reached level 60 the option to choose one of the subclasses available to their class. Four of the 16 subclasses available are listed below:
    • Rogue → Ninja “The power of inner strength.”
      Pay 5-10 Health* to gain up to 20 Mana
    • Mage → Sage “Knowledge is power.”
      Use the Sage's versions of Ethereal Surge or Earthquake for 50% chance to triple-cast the skill (2nd & 3rd free). Max of 8 times per day.
    • Healer → Traveling Doctor “Just tell me where it hurts.”
      Pay 10 Mana** to gain up to 100 Gold.
    • Warrior → Blademaster “The expert, training night and day to gain new techniques.”
      Pay 5-10 Health* for a chance to instantly level up (percentage = 480/level. i.e. 8% at level 60).
      * Cost goes down to 5 Health at 250 CON (equipment and buffs included). Max of 50 Health used per day.
      ** Max of 100 Mana used per day.
  • Rate limit checking (sends "retry after X seconds" message)

First-Time Setup Instructions

Code

Optional Customizations

  • NOTIFICATION_CHANCE can be changed to adjust the chance of notifications (max 0.25)

Update Instructions

Credits and Acknowledgments


Traditional Event-Driven Scripts[edit | edit source]

Sample traditional scripts can be found here.

Troubleshooting[edit | edit source]

If you have any questions or concerns regarding unexpected behavior encountered while setting up or using scripts, please go to the scripts troubleshooting page.

Community content is available under CC-BY-SA unless otherwise noted.