Chat Menus

The chat menu system allow you to quickly create a menus that the player can navigate around using Minecraft chat.

Chat GUI

Title

- run drustcraft.chat_gui.title def:<title-string>

Chat Paginate

- run drustcraft.chat_paginate def:<title>|<pageno>|<itemlist>|<cmd-list>|<cmd-info>|[show-numbers]

Creating a Chat Menu

To create a chat menu, run the task:

- run drustcraft.chat_menu.create def:<your_task>|<your_id>

This will in turn, setup the chat menu system and run the task defined in <your_task> passing <your_id> in definition [1]

Your task should then perform whatever tasks it needs to do, adding menu items to the chat menu using the drustcraft.chat_menu.add task and finally running drustcraft.chat_menu.render

Closing a Chat Menu

If your code is finished with the chat menu, it can be closed early by calling the task drustcraft.chat_menu.close

Adding a menu item

Your chat menu is going to need items to display to the player in order for them to perform tasks. This can be done by calling the drustcraft.chat_menu.add task with a single definition of either an text element or a map with options.

Simple text item

To add a simple text item, that is not selectable, you can call drustcraft.chat_menu.add with a definiton of the text.

- run drustcraft.chat_menu.add 'def:My simple menu item text'

It is not recommended to use the narrate command inside of chat menus as chat menus uses the viewable amount of chat lines for its pagenation rendering.

Player selectable item

To add a player selectable item, pass a map with the following keys to drustcraft.chat_menu.add

Key

Contents

title

The title to display to the player

task

The task to call if the user selects this menu item

id

The data to pass to task in definition [1]

key

[Optional] The key the user is to press to select this item. If this is not specified the next available number is used

- run drustcraft.chat_menu.add 'def:<map[title/My menu item|task/mytask|id/myid]>'

When the player selects a menu item, the corresponding task is called with the corresponding id passed as definition [1]. These tasks can then create sub chat menus by simply calling drustcraft.chat_menu.add and drustcraft.chat_menu.render.

If the task does not call drustcraft.chat_menu.render or drustcraft.chat_menu.back the chat menu system will be closed.

Adding a menu header

Adding a menu header is recommended as it helps the user differentiate what was the previous chat data and what is the current menu.

- run drustcraft.chat_menu.header 'def:My fancy header'

A header is required to be set for each menu as they are not carried across to any submenus.

Asking a Question

Your script can also ask questions to the player in order to set values, then return to the chat menu system, by running the task drustcraft.chat_menu.ask and passing a list definition that contains:

  1. The question to ask the player

  2. The task to call when the player answers the question

  3. The id to pass to the task

The passed task is called when the player presses enter in the chat windo with the following definitions:

  1. The id passed to drustcraft.chat_menu.ask

  2. The text the player entered

The task can then either response to the player using the Denizens narrate command, or create a new sub chat menu followed by drustcraft.chat_menu.render to continue with the previous chat menu.

Moving back a menu

If you have a menu item that is to run a few tasks but does not require to ask the player a question, nor display a new sub menu, it can jump back to the previous menu by calling the drustcraft.chat_menu.back task.

Rendering the menu

Once you are ready to display the menu, call the drustcraft.chat_menu.render task.

This will generate your chat menu, create any required pagenation and handle all user input.

Example Menu

start_menu:
type: task
script:
- run drustcraft.chat_menus.create def:my_menu|start
‚Äč
my_menu:
type: task
script:
- choose <[1]||start>:
- case start:
- drustcraft.chat_menu.header 'def:This is my header'
- drustcraft.chat_menu.add 'def:<map[title/Option 1|id/option1|task/my_menu]>'
- drustcraft.chat_menu.add 'def:<map[title/Option 2|id/option2|task/my_menu]>'
- drustcraft.chat_menu.add 'def:<map[title/Option 3|id/option3|task/my_menu]>'
- drustcraft.chat_menu.add 'def:<map[title/Option 4|id/option4|task/my_menu]>'
- drustcraft.chat_menu.add 'def:<map[title/Option 5|id/option5|task/my_menu]>'
- drustcraft.chat_menu.add 'def:<map[title/Option 6|id/option6|task/my_menu]>'
- drustcraft.chat_menu.add 'def:<map[title/Option 7|id/option7|task/my_menu]>'
- drustcraft.chat_menu.add 'def:<map[title/Option 8|id/option8|task/my_menu]>'
- drustcraft.chat_menu.render
- case option1:
- drustcraft.chat_menu.addN