This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:teleportrequest` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:teleportrequest" || !(sourceEntity instanceof Player)) return;
const form = new MessageFormData();
form.title("Teleport Request");
form.body("Do you want to teleport to the arena?");
form.button1("Teleport");
form.button2("Cancel");
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) return;
if (response.selection === 0) {
sourceEntity.sendMessage("Teleporting to the arena.");
} else {
sourceEntity.sendMessage("Teleport canceled.");
}
});
});
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:confirmpurchase` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:confirmpurchase" || !(sourceEntity instanceof Player)) return;
const form = new MessageFormData();
form.title("Confirm Purchase");
form.body("Buy 1 diamond sword for 10 emeralds?");
form.button1("Confirm");
form.button2("Cancel");
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) return;
if (response.selection === 0) {
sourceEntity.sendMessage("Purchased a diamond sword.");
} else {
sourceEntity.sendMessage("Purchase canceled.");
}
});
});
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:resethighscore` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:resethighscore" || !(sourceEntity instanceof Player)) return;
const form = new MessageFormData();
form.title("Reset High Score");
form.body("Are you sure you want to reset your local high score?");
form.button1("Yes, Reset");
form.button2("No, Keep Score");
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) return;
if (response.selection === 0) {
sourceEntity.sendMessage("Reset high score.");
} else {
sourceEntity.sendMessage("Kept high score.");
}
});
});
Player to show this dialog to.
Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog.
This function can't be called in restricted-execution mode.
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:enablepvp` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:enablepvp" || !(sourceEntity instanceof Player)) return;
const form = new MessageFormData();
form.title("Enable PvP");
form.body("Would you like to enable PvP combat in this arena?");
form.button1("Enable");
form.button2("Disable");
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) {
sourceEntity.sendMessage("PvP prompt was canceled.");
return;
}
if (response.selection === 0) {
sourceEntity.sendMessage("PvP enabled.");
} else {
sourceEntity.sendMessage("PvP disabled.");
}
});
});
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { MessageFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:leaveparty` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:leaveparty" || !(sourceEntity instanceof Player)) return;
const form = new MessageFormData();
form.title("Leave Party");
form.body("Are you sure you want to leave your active party?");
form.button1("Leave");
form.button2("Stay");
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) return;
if (response.selection === 0) {
sourceEntity.sendMessage("You chose Leave.");
} else {
sourceEntity.sendMessage("You chose Stay.");
}
});
});
Builds a simple two-button modal dialog.
Example: showBasicMessageForm.ts
Example: showTranslatedMessageForm.ts
Example: randomTickWarning.js
Source