#nickname change player

1 messages · Page 1 of 1 (latest)

trail flower
#

NPC dialogue

jaunty raptor
#

what exactly does this mean

trail flower
#

nickname change player

jaunty raptor
#

to change the name of the player

#

you have to do

trail flower
jaunty raptor
#
player.nameTag = "what ever you want"```
trail flower
#

via NPC

jaunty raptor
#

in the npc you can add a tag to the player

#

so it would be like

if (player.hasTag("changeName")) player.nameTag = "changed name"```
trail flower
jaunty raptor
#

send code u already have

trail flower
#

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);
    });

jaunty raptor
#
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

trail flower
#

I know

jaunty raptor
#

so if it already works whats the problem?

trail flower
#

I want to execute the script in the NPC dialogue