Habitica Wiki
注册
Habitica Wiki
(翻译标题)
标签源代码编辑
(翻译标题+修正链接)
标签源代码编辑 移动版编辑 移动版网页编辑
第482行: 第482行:
 
* Now add a trigger. Under ''Edit'', select ''Current project's triggers''. Then add a trigger that make the script run on your preferred schedule.
 
* 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 ==
 
 
[[Streamlined Event-Driven (Webhook) Script Template|Streamlined scripts]] allow the user to [[Event-Driven (Webhook) Scripts Setup Guide|set up event-driven scripts]] with fewer number of steps and without going back and forth between different tools.
 
[[Streamlined Event-Driven (Webhook) Script Template|Streamlined scripts]] allow the user to [[Event-Driven (Webhook) Scripts Setup Guide|set up event-driven scripts]] with fewer number of steps and without going back and forth between different tools.
   
第498行: 第498行:
   
 
'''''初次安装说明'''''
 
'''''初次安装说明'''''
* 参考[[简易图文安装步骤]]
+
* 参考[[事件驱动(Webhook)脚本安装指南#第1部分:安装外部脚本|简易图文安装步骤]]
   
 
'''''代码'''''
 
'''''代码'''''

2021年7月28日 (三) 00:22的版本

本文由Ayakuroi翻译。


说明

Google Apps Script是基于JavaScript的脚本,让你可以操作Habitica和其他G Suite产品如日历,文档,工作表,幻灯片和表格。无需安装任何内容 — 你可以在浏览器中直接使用代码编辑器,脚本会Google的服务器上运行。所有脚本可以安排一定程度的独立性。

使用方式

你需要一个Gmail帐户以使用此功能。因为需要使用Habitica的用户ID和API令牌,因此建议将所有脚本保持私有。

除了Auto Cron 脚本外没有其他脚本会让你cron.。如果你在你的自定义每日起始时间之后施放队伍增益技能,你还是必须执行Auto Cron 或者使用Habitica 网页版/应用来cron.。

当你排程脚本时,不要让脚本运行频率超过每小时 。 对Habitica的服务器好一点! 当第一次设定脚本时,最好通过手动选择Run => Run function => [Script to be scheduled] 以在排程前检查它是否运行无误。

手动运行脚本

批次攻击副本Boss

by cTheDragons

此脚本适合战士和法师,让你能批量攻击副本Boss。

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码片段粘贴到编辑器中
    • Replace the spaces marked #HabiticaUserID#和#HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These 可以在API found under the API tab in your Habitica settings.
    • 将ntimes更改为您希望每次运行使用的技能次数。 当前设置为8。
    • 更改skillId成你想要施放的技能based what is describe in the comments in options. Below it currently set to Burst of Flames with skillId = "fireball"
    • 更改targetId以匹配你的任务。 查找任务ID的方式:
      • 开启数据展示工具
      • Go to section for Task Overview.
      • 寻找你想作为目标的任务名(如果你不确定哪个最好, check under 技能 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
   }
 }
  • 储存脚本
  • From the menu choose Run => Run function => bulkAttackBoss.

批量购买魔法衣橱道具

by cTheDragons

此脚本允许你从魔法衣橱批量购买并可以在记录中查看。

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码片段粘贴到编辑器中
    • 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. 当前设置为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
   }
 }
  • 储存脚本
  • 从菜单选择Run => Run function => bulkBuyArmorie.
  • 从菜单选择View => Logs to view what you received.

时间驱动脚本

自动Cron

by cTheDragons

在你的自定义每日起始时间之后运行,此脚本会自动执行cron。请注意使用此方法你将无法使用Record Yesterday's Activities. Any dailies not ticked off at the time of cronning will be marked as missed.

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码贴到编辑器中,并将标注 #HabiticaUserID# 和 #HabiticaAPIToken# 的空格替换为Habitica用户ID和API令牌(保留引号)。这些可以在Habitica设置的"API"标签下找到。
 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.
  • 保存后就完成了!

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.

自动接受副本

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)

每小时运行,若队伍中有副本邀请此脚本会自动参加副本。

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码贴到编辑器中,并将标注 #HabiticaUserID# 和 #HabiticaAPIToken# 的空格替换为Habitica用户ID和API令牌(保留引号)。这些可以在Habitica设置的"API"标签下找到。
 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)
   }
 }

或以下更清楚的代码:

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.
  • 保存后就完成了!

自动强制开始副本

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.

安装说明:

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 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.
  • 保存后就完成了!

Version for Parties Mandating 自动接受 Script Use

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 for Parties Not Using 自动接受 Script

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

const 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
const habId = "#HabiticaUserID#"; // Your Habitica ID: found under settings -> API -> user ID
const habToken = "#HabiticaAPIToken#"; // Your Habitica API token: found under settings -> API -> Show API Token
const 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)

const time_to_join_ms = time_to_join_hours*60*60*1000;
const 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);
  }
}

自动施放队伍增益技能

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.

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码片段粘贴到编辑器中
    • 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).
  • 保存后就完成了!

If you wish this to run immediately instead of waiting on a trigger, from the edit window of the project, 从菜单选择Run => Run function => schedulePartyBuff.


Auto Schedule To-Do's with Google Calendar

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.
  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码贴到编辑器中,并将标注 #HabiticaUserID# 和 #HabiticaAPIToken# 的空格替换为Habitica用户ID和API令牌(保留引号)。这些可以在Habitica设置的"API"标签下找到。
 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. 建议时间为你的cron之后,如凌晨3-4am。
  • 保存后就完成了!

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.

Auto Bulk Remove Habitica Emails

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.

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码片段粘贴到编辑器中
    • 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.
  • 保存后就完成了!

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

Auto Change Pet and Mount Randomly

by Ieahleen

This script will change your pet and mount randomly - the chance is equal for all your pets and mounts so it can happen that instead of changing to a new pet/mount it will select the one currently equipped and so unequip it. 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 four lines below the "randomly change the pet/mount" you are not interested to.

  • 前往script.google.com。如果这是你的第一个脚本,会自动创建一个新的Google脚本并打开编辑器。否则请点击现有项目旁边的铅笔图标以编辑,或创建新项目。
  • 将下面的代码贴到编辑器中,并将标注 #HabiticaUserID# 和 #HabiticaAPIToken# 的空格替换为Habitica用户ID和API令牌(保留引号)。这些可以在Habitica设置的"API"标签下找到。
 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;
   /* randomly change the mount */
   var mounts = Object.keys(items.mounts).filter(m => items.mounts[m]);
   var randomMount = mounts[Math.floor(Math.random() * mounts.length)];
   paramsTemplate.method = "post";
   UrlFetchApp.fetch("https://habitica.com/api/v3/user/equip/mount/" + randomMount, paramsTemplate)
   /* randomly change the pet */
   var pets = Object.keys(items.pets).filter(p => items.pets[p]);
   var randomPet = pets[Math.floor(Math.random() * pets.length)];
   paramsTemplate.method = "post";
   UrlFetchApp.fetch("https://habitica.com/api/v3/user/equip/pet/" + randomPet, paramsTemplate)
 }
  • If you are interested only to the change of the pet remove the four lines below "randomly change the mount", if you are interested only to the change of the mount remove the four lines 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 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

by @EugeneG

功能

  • 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)

初次安装说明

代码

可选设定

  • ENABLE_NOTIFICATION can be set to 0 to disable notifications

使用提示

Known Issues

更新说明

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

协作者与致谢

Change Equipment

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:

更快速的自动参加副本及副本结束自动通知

by @EugeneG

功能

  • 在收到副本邀请后几秒内自动接受
  • 通过私信接收副本结束通知(to have priority in setting up the next quest)
  • 上述功能都可停用
  • Rate limit checking (延迟后自动重试)
  • 自动创建每小时的自动接受副本作为Habitica的webhook启动脚本失败的备案

初次安装说明

  • 参考简易图文安装步骤

代码

可选设定

  • 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

更新说明

YouTube step by step instructions

协作者与致谢

  • @steelblade for initial webhook tips and debugging help

战士 Subclasses

by @EugeneG

功能

  • Gives 战士 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)

初次安装说明

代码

可选设定

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

更新说明

协作者与致谢

战士、法师、医者、盗贼 Subclasses

by @EugeneG

功能

  • 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.
    • 战士 → 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)

初次安装说明

  • 参考简易图文安装步骤

代码

可选设定

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

更新说明

协作者与致谢


Traditional Event-Driven Scripts

Sample traditional scripts can be found here.

故障排除

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