#nickname change player
1 messages · Page 1 of 1 (latest)
what exactly does this mean
nickname change player
Yes
player.nameTag = "what ever you want"```
via NPC
in the npc you can add a tag to the player
so it would be like
if (player.hasTag("changeName")) player.nameTag = "changed name"```
send code u already have
import {world, player} from "@minecraft/server"
import { ModalFormData } from "@minecraft/server-ui";
/**
-
Displays a modal form to set a nickname for the player.
-
If the player is busy, recalls the form until the player interacts with it or cancels.
-
@param {Player} player - The player to display the form to.
/
function displayNicknameForm(player) {
/*- Represents the data structure of the nickname form.
- @type {ModalFormData}
*/
let form = new ModalFormData();
form.title("Write a nickname");
form.textField("nickname", "", player.nameTag);
form.show(player).then((response) => {
const { canceled, formValues, cancelationReason } = response;
if (response && canceled && cancelationReason === "UserBusy") {
// If the player is busy, recall the form
displayNicknameForm(player);
return;
}
if (canceled) return;
const [nickname] = formValues;
player.sendMessage("Nickname set to " + nickname);
player.nameTag = nickname;
});
}
/**
-
Event handler for the playerSpawn event.
-
@param {object} data - The data object containing information about the event.
*/
world.afterEvents.playerSpawn.subscribe(async (data) => {
let { initialSpawn, player } = data;
if (!initialSpawn) return;system.runTimeout(() => {
// Call the function to display the nickname form
displayNicknameForm(player);
}, 60);
});
import {world, player} from "@minecraft/server"
import { ModalFormData } from "@minecraft/server-ui";
/
Displays a modal form to set a nickname for the player.
If the player is busy, recalls the form until the player interacts with it or cancels.
@param {Player} player - The player to display the form to.
*/
function displayNicknameForm(player) {
/
Represents the data structure of the nickname form.
@type {ModalFormData}*/
let form = new ModalFormData();
form.title("Write a nickname");
form.textField("nickname", "", player.nameTag);
form.show(player).then((response) => {
const { canceled, formValues, cancelationReason } = response;
if (response && canceled && cancelationReason === "UserBusy") {
// If the player is busy, recall the form
displayNicknameForm(player);
return;
}
if (canceled) return;
const [nickname] = formValues;
player.sendMessage("Nickname set to " + nickname);
player.nameTag = nickname;
});
}
/**
Event handler for the playerSpawn event.
@param {object} data - The data object containing information about the event.
*/
world.afterEvents.playerSpawn.subscribe(async (data) => {
let { initialSpawn, player } = data;
if (!initialSpawn) return;
system.runTimeout(() => {
// Call the function to display the nickname form
displayNicknameForm(player);
}, 60);
});```
it should work
and thats not npc form
its modal form
i mean ur code should work already
I know
so if it already works whats the problem?
I want to execute the script in the NPC dialogue