# 目标

在上一节教程中，你已经学习了如何创建和使用事件。本节教程是关于目标的。目标是你可以分配给玩家的任务。例如破坏方块或钓鱼。可能性几乎是无穷无尽的！您将在本节教程中了解这些内容。

{% hint style="danger" %}
要求

你必须已完成上一章“[安装指南](https://miao-3.gitbook.io/betonquest-zhong-wen-wiki/jiao-cheng/ru-men)”内容

你必须已完成上一节“[对话](https://miao-3.gitbook.io/betonquest-zhong-wen-wiki/jiao-cheng/ru-men/ji-chu-jiao-cheng/dui-hua)”内容

你必须已完成上一节“[事件](https://miao-3.gitbook.io/betonquest-zhong-wen-wiki/jiao-cheng/ru-men/ji-chu-jiao-cheng/shi-jian)”内容
{% endhint %}

## 下载教程预设

<img src="https://twemoji.maxcdn.com/v/latest/svg/26a0.svg" alt="⚠" data-size="line"> <mark style="color:red;">**如果您已经使用了上一个教程步骤的配置，请不要执行此操作。**</mark> <img src="https://twemoji.maxcdn.com/v/latest/svg/26a0.svg" alt="⚠" data-size="line">

在聊天框中输入以下命令下载本节教程的预设内容：

```
/bq download BetonQuest/Quest-Tutorials main QuestPackages /Basics/Objectives/1-DirectoryStructure /tutorialQuest
```

您现在可以在此位置找到本教程所需的所有文件：

&#x20;"*你的服务器文件存放位置/plugins/BetonQuest/QuestPackages/tutorialQuest*"

## 1.为第一个目标创建文件结构 <a href="#id-1-creating-the-folder-structure-for-your-first-objective" id="id-1-creating-the-folder-structure-for-your-first-objective"></a>

&#x5728;*“tutorialQuest”*&#x6587;件夹内，新建一个名&#x4E3A;*“objectives.yml”*&#x7684;文件；并在“Conversations”文件夹内，新建一个"*blacksmith.yml*"文件。你可能会问为什么我们将新文件添加到“Conversations”对话文件夹。这是因为城市之旅目前以虚无告终。我们将添加一个铁匠NPC，玩家可以与NPC交谈。

以下是你现在的文件结构：

* &#x20;:file\_folder:tutorialQuest
  * &#x20;:open\_file\_folder:package.yml
  * &#x20;:open\_file\_folder:events.yml
  * &#x20;:open\_file\_folder:objectives.yml
  * &#x20;:file\_folder:conversations
    * &#x20;:open\_file\_folder:jack.yml
    * &#x20;:open\_file\_folder:blacksmith.yml

现在，我们的文件结构已准备就绪，可以开始编写目标和新的对话了！

## 2. 定义你的第一个目标并完成事件 <a href="#id-2-defining-your-first-objective-and-finishing-event" id="id-2-defining-your-first-objective-and-finishing-event"></a>

打开新创建的文件“*objectives.yml*”并添加以下内容：

{% code title="objectives.yml" lineNumbers="true" %}

```
objectives: 
  fishingObj: "fish cod 10 notify hookLocation:100;50;100;world range:20 events:caughtAllFish"
```

{% endcode %}

{% hint style="warning" %}
所有目标都必须&#x5728;**`objectives.yml`**&#x6587;件中定义。
{% endhint %}

让我们来拆解分析一下：

* `fishingObj`是目标的名称。你可以随意起名。但是，建议以它的作用命名它。这会让你更方便地编写任务
  * 目标结构
    * `fish`：指令中的第一个值始终是**目标类型**。
    * `cod`：这是目标的一**个选项**。它定义了`fish`所需要的的物品。
    * `10`：这是另一**个选项**。它定义了鱼的数量。
    * `notify`：这是大多数目标的常规设置。当玩家完成目标时，它会启用通知。
    * `hookLocation:100;50;100;world`：**此选项**定义鱼竿的位置必须位于何处。只有在这个特定区域捕捞的鱼才会被目标计算在内。
    * `range:20`：如果使用`hookLocation`，则还必须定义范围**选项**。这是鱼竿位置坐标周围的范围，其中钓出的东西仍然被计算在内。
    * `events:caughtAllFish`：这不是鱼目标的选择，而是目标的一个常规设置。目标完成后（在指定的钓鱼位置捕获 10 条鳕鱼后），将触发定义的事件。

之后，我们将`caughtAllFish`事件添加到“*events.yml*”中，如下所示：

{% code title="events.yml" lineNumbers="true" %}

```
events:
  # 其他事件不在这里显示
  tpBlacksmith: "teleport 50;70;50;world"
  caughtAllFish: "notify You caught enough fish!\nReturn to the blacksmith! io:Title sound:firework_rocket"
```

{% endcode %}

它让玩家知道他们成功完成了目标。

## 3. 在物品部分中创建物品 <a href="#id-3-creating-the-item-in-the-items-section" id="id-3-creating-the-item-in-the-items-section"></a>

像我们在[上一教程](https://miao-3.gitbook.io/betonquest-zhong-wen-wiki/jiao-cheng/ru-men/shi-jian#3-creating-the-item-in-the-items-section)中学到的那样，我们必须在物品部分中定义，因为BetonQuest不知道是什么。要将该物品添加到列表中，让我们重新打开“*package.yml*”文件。

{% code title="package.yml" lineNumbers="true" %}

```
npcs:
  '1': "Jack"

items:
  steak: "COOKED_BEEF"
  cod: "COD" 
```

{% endcode %}

* 第**6**行 `cod`：将BetonQuest配置中的物品`cod`连接到Minecraft中的物品。

现在，`cod`是一个已被定义的物品，可以在整个任务中使用。

现在，是一个已定义的物品，可以在整个任务中使用。

## 4. 测试你的第一个游戏目标 <a href="#id-4-testing-your-first-objective-ingame" id="id-4-testing-your-first-objective-ingame"></a>

{% hint style="warning" %}
每次测试一些内容时，保存所有文件是非常重要的！保存后在服务器上输入：`/bq reload`
{% endhint %}

目标必须在开始观察玩家的行动之前启动。执行此操作的最简单方法是运行命令：

在服务器上输入`/bq objective YOUR_NAME add tutorialQuest.fishingObj`此命令将开始玩家的目标。如果你想检查目标是否正确完成，请转到目标所定义的位置并钓10条鳕鱼。捕获10条鳕鱼后，你应该会收到通知。

{% tabs %}
{% tab title="命令拆解分析" %}

| 命令部分                          | 意义                                                             |
| ----------------------------- | -------------------------------------------------------------- |
| `/bq objective`               | 告诉BetonQuest应该执行一些事件。                                          |
| `NAME`                        | 玩家名。                                                           |
| `add`/`complete`/`del`/`list` | 使用这些参数可以添加、完成、或列出目标。list参数不需要任何进一步的参数，并列出所选玩家的所有目标。            |
| `tutorialQuest`               | 任务包的名称。这是必需的，因为您可以在不同的包中具有相同名称的目标。                             |
| `fishingObj`                  | 要执行的目标的名称。不要忘记用一个点将其与package分开。`tutorialQuest`**`.`**`fishObj` |
| {% endtab %}                  |                                                                |
| {% endtabs %}                 |                                                                |

你还可以使用`/bq objective NAME` 命令来列出玩家的所有目标。

如果要手动完成玩家的目标，你需要输入`/bq objective YOUR_NAME complete tutorialQuest.fishObj` 。发送此命令后，你还应该会收到有关完成此目标的通知。

## 5. 使用事件开始设定目标 <a href="#id-5-using-events-to-start-objectives" id="id-5-using-events-to-start-objectives"></a>

目标不仅可以使用命令启动/停止，还可以使用事件启动/停止。让我们添加一个事件来启动钓鱼目标：

{% code title="events.yml" lineNumbers="true" %}

```
events:
  # 其他事件不在这里显示
  tpBlacksmith: "teleport 50;70;50;world"
  caughtAllFish: "notify You caught enough fish!\nReturn to the blacksmith! io:Title sound:firework_rocket"
  startFishingObj: "objective start fishingObj" 
```

{% endcode %}

* 第**5**行 `startFishingObj`：启动执行`fishingObj`事件的玩家的目标。

## 6. 将目标整合到对话中 <a href="#id-6-integrating-objectives-into-conversations" id="id-6-integrating-objectives-into-conversations"></a>

如标题所示，我们可以从对话中运行事件。现在，我们可以使用新事件从对话中启动目标。

让我们在对话文件夹中为新创建的文件“*blacksmith.yml*”添加一些对话：

{% code title="blacksmith.yml" lineNumbers="true" %}

```
conversations:
  Blacksmith:
    quester: Blacksmith
    first: firstGreeting
    NPC_options:
      firstGreeting:
        text: Welcome %player% in Valencia! The mayor already told me that you are new to our town.
        pointer: thatsRight
      newArmorForNewCitizens:
        text: So every new citizens in our town will get a new armour from me but you have to do something for me in order to get this really nice upgrade!
        pointer: whatToDo
      collectFish:
        text: You will have to fish 10 fresh cod for me and bring them to me. After that I will give you the nice new armour! Is that a deal?
        pointer: accept,deny 
      maybeLater:
        text: No problem! You can comeback later aswell. Bye!
      goodLuck:
        text: Good luck and I will see you later!
    player_options:
      thatsRight:
        text: Yeah thats true. Thank you!
        pointer: newArmorForNewCitizens
      whatToDo:
        text: What can I do for you?
        pointer: collectFish
      accept:
        text: Sure! I could use a new armour.
        event: startFishingObj 
        pointer: goodLuck
      deny:
        text: I dont have time right now.
        pointer: maybeLater
```

{% endcode %}

* 第14行 `pointer`：玩家可以选择接受或拒绝。
* 第28行 `event`：这是开始你目标任务的事件，去捕捞10条新鲜的鳕鱼。

现在，将对话连接到一个新的NPC，该NPC放置在城市游览结束的地方。你应该已经知道如何将对话框连接到“packag&#x65;*.yml*”中的npc。如果你不会，[请查看之前的教程](https://miao-3.gitbook.io/betonquest-zhong-wen-wiki/jiao-cheng/ru-men/dui-hua#1.-jiang-dui-hua-lian-jie-dao-npc-shang)！

{% hint style="warning" %}
每次测试一些内容时，保存所有文件都非常重要！保存后在服务器上输入：`/bq reload`
{% endhint %}

<details>

<summary>这个示例不起作用吗？</summary>

通过运行以下命令获取正确的配置。\
\&#xNAN;*这将覆盖您对示例所做的任何更改（包括 NPC ID）。*\
[基础教程](https://miao-3.gitbook.io/betonquest-zhong-wen-wiki/jiao-cheng/ru-men/dui-hua#1.-jiang-dui-hua-lian-jie-dao-npc-shang)中介绍了将 NPC 链接到对话。<img src="https://twemoji.maxcdn.com/v/latest/svg/26a0.svg" alt="⚠" data-size="line">

```
/bq download BetonQuest/Quest-Tutorials main QuestPackages /Basics/Objectives/2-FullExample /tutorialQuest
```

</details>

## 总结 <a href="#summary" id="summary"></a>

您已经了解了什么是目标以及如何创建目标。现在，你可以给玩家一个目标，让他们拥有更高级的任务！可以在目标列表中找到更多[目标](https://docs.betonquest.org/2.0.0-DEV/Documentation/Objectives-List/)。在下一教程中，您将学习**条件**的工作原理以及如何使用它们使铁匠对完成的目标做出反应。
