This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:serverrules` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:serverrules" || !(sourceEntity instanceof Player)) return;
const form = new ActionFormData();
form.title("Server Rules");
form.body("Be respectful, do not grief buildings, and have fun playing.");
form.button("I Agree");
form.show(sourceEntity).then((response) => {
if (response.canceled) {
sourceEntity.sendMessage("You closed the rules dialog.");
return;
}
sourceEntity.sendMessage("You agreed to the rules.");
});
});
OptionaliconPath: stringThis function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:warpmenu` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:warpmenu" || !(sourceEntity instanceof Player)) return;
const destinations = ["Spawn", "Market"];
const form = new ActionFormData();
form.title("Warp Menu");
form.body("Choose a destination to visit:");
form.button(destinations[0], "textures/items/compass");
form.button(destinations[1], "textures/items/emerald");
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) return;
const destination = destinations[response.selection];
sourceEntity.sendMessage(`Warping to ${destination}.`);
});
});
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:gameoptionsmenu` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:gameoptionsmenu" || !(sourceEntity instanceof Player)) return;
const form = new ActionFormData();
form.title("Game Options");
form.button("Resume Game");
form.divider();
form.button("Leave Server");
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) return;
if (response.selection === 0) {
sourceEntity.sendMessage("Resuming the game.");
} else {
sourceEntity.sendMessage("Leaving the server.");
}
});
});
Text to display.
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:minigamedirectory` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:minigamedirectory" || !(sourceEntity instanceof Player)) return;
const minigames = ["Parkour Challenge", "PVP Arena"];
const form = new ActionFormData();
form.title("Server Directory");
form.header("Minigames");
form.button(minigames[0]);
form.button(minigames[1]);
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) return;
const minigame = minigames[response.selection];
sourceEntity.sendMessage(`You selected ${minigame}.`);
});
});
Text to display.
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:servernotice` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:servernotice" || !(sourceEntity instanceof Player)) return;
const form = new ActionFormData();
form.title("Server Notice");
form.label("Daily server maintenance occurs every midnight UTC.");
form.button("Understood");
form.show(sourceEntity).then((response) => {
if (response.canceled) return;
sourceEntity.sendMessage("You acknowledged the server notice.");
});
});
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 { ActionFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:weathervote` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:weathervote" || !(sourceEntity instanceof Player)) return;
const weatherChoices = ["Clear Skies", "Rain Storm"];
const form = new ActionFormData();
form.title("Weather Vote");
form.button(weatherChoices[0]);
form.button(weatherChoices[1]);
form.show(sourceEntity).then((response) => {
if (response.canceled || response.selection === undefined) {
sourceEntity.sendMessage("Vote canceled.");
return;
}
const choice = weatherChoices[response.selection];
sourceEntity.sendMessage(`You voted for ${choice}.`);
});
});
This function can't be called in early-execution mode.
import { Player, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
// Run `/scriptevent example:dailyrewards` in chat to open the form.
system.afterEvents.scriptEventReceive.subscribe(({ id, sourceEntity }) => {
if (id !== "example:dailyrewards" || !(sourceEntity instanceof Player)) return;
const form = new ActionFormData();
form.title("Daily Rewards");
form.button("Claim Reward");
form.show(sourceEntity).then((response) => {
if (response.canceled) return;
sourceEntity.sendMessage("Claimed daily reward.");
});
});
Builds a simple player form with buttons that let the player take action.
Example: showActionForm.ts
Example: showFavoriteMonth.ts
Example: minigames.js
Source