💬对话

在本教程中,你将学习对话的基础知识。你就可以在玩家和NPC之间创建对话。因此,对于讲故事来说,对话是基本工具。

要求

你必须已完成上一章“安装指南”内容

下载教程预设

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

/bq download BetonQuest/Quest-Tutorials main QuestPackages /Basics/Conversations/1-DirectoryStructure /tutorialQuest overwrite

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

"你的服务器文件存放位置/plugins/BetonQuest/QuestPackages/tutorialQuest"

1.将对话连接到NPC上

一般来说,对话发生在NPC和玩家之间。因此,我们需要在 package.yml 中创建npcs部分,以便插件知道 Citizens 的哪个 NPC 使用哪个对话。像下面这样:

package.yml
npcs:
  '1': "Jack"

这会将已经设置的Citizens ID(1)的 NPC 连接到已经设置标识符 (Jack) 的对话。请在编辑完成后保存文件。

如何查找 Citizens 的 ID ?

如果你未创建 NPC,请执行该指令:/npc create Jack

  1. 靠近你要选择的NPC

  2. 输入指令/npc select来选择最近的 NPC。

  3. 输入指令/npc id从 NPC 获取 ID。

2. 创建你的第一个对话

是时候与Jack进行第一次对话了!本节将会教你对话的基本结构。

让我们来看看对话是如何在插件的文件中定义的:

jack.yml
conversations:
  Jack: 
    quester: "Jack" 
    first: "firstGreeting" 
    NPC_options: 
      firstGreeting:
        text: "Hello and welcome to my town traveler! Nice to see you. Where are you from?"
        pointer: "whereYouFrom" 

    player_options: 
      whereYouFrom:
        text: "First I want to know who you are!"
  • 2Jack :这是对话的标识符。确保这与“package.yml”中的对话标识符一致。

  • 3quester:定义对话时显示的名字。

  • 4first:定义将NPC_option用作对话的开始。

  • 5NPC_options:此部分包含NPC所说的所有内容。

  • 8pointer:定义接下来显示player_option的内容。

  • 10player_options:此部分包含玩家所说的所有内容。

BetonQuest 对话是一个在玩家和 NPC 之间的循环回答。 NPC 要说的话被叫做NPC_options,而玩家的回答则被叫做player_options

一个对话总是以一个NPC_option开始。现在玩家必须通过player_option来回答NPC。

选项使用pointer参数来相互指向, 在NPC_option的通常情况下,选项参数将会包含一个player_option。 通常情况下,玩家会有很多答案可供选择。这是通过将多个player_option名字添加到NPC_option中。

在玩家做出回答之后,对话会展示NPC_option,也就是先前选择的player_option的指向。

无论什么时候,当player_optionNPC_option的指向没有其他选择时,对话就结束了。

3. 在游戏内测试对话

你可以很容易地检查你的任务是否在服务器上正常运行。打开"conversations" 文件夹中的"jack.yml" 文件。将上面的对话复制到文件里面并保存文件。

现在在聊天框内输入/bq reload并右键单击NPC。

4.多种选择的对话

让我们看看如何创建多个pointer,供玩家使用选项进行选择。

NPC_option可以同时指向多个玩家player_option选项。一旦一个pointer包含多个,玩家就可以选择。

第9-15、20-26行,为新增内容。

jack.yml
conversations:
  Jack:
    quester: "Jack"
    first: "firstGreeting"
    NPC_options:
      firstGreeting:
        text: "Hello and welcome to my town traveler! Nice to see you. Where are you from?"
        pointer: "whereYouFrom"
      whoAmI:
        text: "I am &6Jack&r. The mayor of this beautiful town. We have some big farms and good old taverns well worth checking out! So now where are you from?"
        pointer: "smallIsland,bigCity" 
      islandAnswer: 
        text: "That sounds familiar! I grew up in a small town with few people. So we already have something in common! Do you want something to eat?"
      cityAnswer: 
        text: "Oh I know! I think you're from Kayra, right? Nice city but to be honest I prefer country life... You look a bit hungry. Do you want something to eat?"

    player_options:
      whereYouFrom: 
        text: "First I want to know who you are!"
        pointer: "whoAmI" 
      smallIsland: 
        text: "From a small island located east."
        pointer: "islandAnswer" 
      bigCity:  
        text: "From a big city located west."
        pointer: "cityAnswer" 
  • 11pointerNPC_option有多个指向 。这允许玩家选择player_options。多个player_options的名称必须用逗号(,)分隔。

  • 21smallIslandwhoAmI指向npc_option

  • 23pointerislandAnswer指向 NPC_option。

  • 24bigCitywhoAmI指向 npc_option。

  • 26pointercityAnswer指向NPC_option

通过这些变化,市长询问玩家他来自哪里。玩家可以说他们来自 smallIsland 或 来自bigCity .这将在对话中创建两个不同的选择。

5. 加入对话路径

让我们再次连接这些路径来显示相同的结尾: 将相同的pointer添加到两个NPC_optionsyesPlease指向新的player_option

jack.yml
conversations:
  Jack:
    quester: "Jack"
    first: "firstGreeting"
    NPC_options:
      firstGreeting:
        text: "Hello and welcome to my town traveler! Nice to see you. Where are you from?"
        pointer: "whereYouFrom"
      whoAmI:
        text: "I am &6Jack&r. The mayor of this beautiful town. We have some big farms and good old taverns well worth checking out! So now where are you from?"
        pointer: "smallIsland,bigCity"
      islandAnswer:
        text: "That sounds familiar! I grew up in a small town with few people. So we already have something in common! Do you want something to eat?"
        pointer: "yesPlease" 
      cityAnswer:
        text: "Oh I know! I think you're from Kayra, right? Nice city but to be honest I prefer country life... You look a bit hungry. Do you want something to eat?"
        pointer: "yesPlease" 
      foodAnswer:
        text: "You're welcome! Take it... &7*gives food*"

    player_options:
      whereYouFrom:
        text: "First I want to know who you are!"
        pointer: "whoAmI"
      smallIsland:
        text: "From a small island located east."
        pointer: "islandAnswer"
      bigCity:
        text: "From a big city located west."
        pointer: "cityAnswer"
      yesPlease: 
        text: "Oh yes I'm starving! Thank you."
        pointer: "foodAnswer"

下图显示了对话的路径。由于该选项分配了两条路径pointers,因此玩家可以在whoAmI其中一条路径之间进行选择。

最后保存文件并执行命令/bq reload来测试游戏中的对话!然后右键单击“Jack”。使用向前W键和向后行走S键的键选择不同的选项。确认选项为跳跃键(默认情况下空格键)。

总结

您已经学习了如何创建简单的对话,玩家可以在其中选择不同的选项。在基础教程的下一部分,您将学习市长Jack如何使用事件为玩家提供食物!

最后更新于