Habitica Wiki
Habitica Wiki



Summary[]

This script allows a user to buy in bulk from the Enchanted Armoire and to view the results in the script's logs. This version allows you to "install" to run the script automatically at the repetitions and interval you choose.

Code[]

You can find the code here: Google Apps Script

Installation[]

Create the script[]

  1. Click here to go to the Bulk Buy Enchanted Armoire script.
    • If you're not already signed into your Google account, you'll be asked to sign in.
  2. Go to the "Overview," the top tab on the left side (a circle with an ā€œiā€ inside)
  3. Click the "Copy" icon on the far right (two papers)
  4. Rename your new script, removing ā€œCopy ofā€
  5. Save the script (disk icon)

Personalize the script[]

  1. Open your API Settings. Highlight and copy your User ID (it looks something like this: 377a4d3d-c55c-48b8-9bf8-59b97480daf8). In the Reschedule Tasks script, paste your User ID between the quotations where it says const USER_ID = "".
    • It should now look something like this: const USER_ID = "377a4d3d-c55c-48b8-9bf8-59b97480daf8".
  2. On the same page where you copied your User ID, click the "Show API Token" button, and copy your API Token. In the Google script, paste your API Token between the quotations where it says const API_TOKEN = "".
    • It should now look something like this: const API_TOKEN = "377a4d3d-c55c-48b8-9bf8-59b97480daf8".
  3. Enter your desired repetions (how many times you want to purchase each time this script runs).
  4. Enter your desired frequency (the the number of hours between purchases, e.g. "purchase every 2 hours")
  5. Save the script (disk icon)

Run the Install function[]

  1. Ensure that the install function is listed in the drop down menu to the right of ā€œdebugā€
  2. Click ā€œrun,ā€ to the left of ā€œdebugā€
    • You should see "Execution completed" in the Execution Log.

You may need to authorize the script[]

The first time you run a function or deploy the script, it will ask you to grant permission on your Google account. When you see this pop-up:

  1. Click "Review permissions" then select your Google account
  2. Click "Advanced," a small blue link at the bottom
  3. Click "Go to [name of script] (unsafe)"
  4. Click "Allow" at the bottom

Modify / Uninstall[]

  • To change the trigger frequency, simply change the Frequency variable and then run the install function
  • To modify the number of purchases, change the Repetitions variable and save the script
  • To remove the trigger, simply run the uninstall function

Contact[]

Please message @benniefolyfe for questions, suggestions, or troubleshooting. I'm happy to help!

Gratitude[]

Thanks to cTheDragons for laying the foundation for this script!

Legacy Code[]

Below is cTheDragons' original code to purchase from the armoire:

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,
      "x-client": habId + "-Bulk Buy Enchanted Armoire"
    }
  }
  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
  }
}