#script form

1 messages · Page 1 of 1 (latest)

frosty moss
#

How do I make the buttons in the list, for example, when the first button is pressed, the color of the name of the person pressing the button will change to red, and the second button to green?

swift portal
#
async function openColorForm(player) {
    const form = new ActionFormData
    form.title("Choose your name color!")
    form.button("Red","textures/blocks/wool_colored_red")
    form.button("Green","textures/blocks/wool_colored_lime")
    const {selection, canceled} = await form.show(player)
    if (canceled) return
    if (selection == 0) player.nameTag = `§c${player.name}`
    if (selection == 1) player.nameTag = `§a${player.name}`
    }```
frosty moss
#

Does the name appear in red for everyone?

#

I will try it

#

@swift portal

#

@swift portal The color of the name does not turn red

thick lynx
#

that dude was prob lazy..
Try this:

import * as Minecraft from "@minecraft/server";
import * as MinecraftUi from "@minecraft/server-ui";

function openColorForm(player) {
    const form = new MinecraftUi.ActionFormData();
    form.title("Choose your name color!");
    form.button("Red", "textures/blocks/wool_colored_red");
    form.button("Green", "textures/blocks/wool_colored_lime");

    form.show(player).then(async ({ selection, canceled }) => {
        if (!canceled) {
            switch (selection) {
                case 0:
                    player.nameTag = `§c${player.name}`;
                    break;
                case 1:
                    player.nameTag = `§a${player.name}`;
                    break;
            }
        }
    });
}
#

@frosty moss

#

Tell me if this still doesn't work.
(Provide me the full code next time)

swift portal
thick lynx
# swift portal how did u use it

your code isnt correct tho💀
U forgot () at defining the form,
forgot to use return while using if statements..
And the variables are globally defined which may cause issues later.

frosty moss
#

world.afterEvents.itemUse.subscribe(event => {
const player = event.source
    if (event.itemStack.typeId === "minecraft:stick") {
        form(player)
    };
});

function form(player){
const form = new ActionFormData()
.title("MENU_F5")
.body("MGCRAFT_F5")
.button("Red","textures/blocks/wool_colored_red") 
.button("Green","textures/blocks/wool_colored_lime") 
.button("3D", "textures/items/ender_eye")

.show(player).then(r =>{
    if (r.canceled) return;
    let response = r.selection;
    switch (response) {
        case 0:
            player.nameTag = `§c${player.name}`
            break;
        case 1:
            player.nameTag = `§a${player.name}`
            break;
        case 2:
            player.runCommandAsync("camera @s set minecraft:first_person")
            break;
    }
}).catch(e => {
    console.error(e, e.stack);
});
}```
frosty moss
#

@swift portal @thick lynx

swift portal
idle plover
lapis kettle
idle plover
swift portal
idle plover
#

Bro you don't even need to define it

#

You can also use new ActionFormData without const/let

#

@scarlet patio sorry for the ping what do you think? Is it true or false

swift portal
#

wait it is?

#

nvm

#

its not false

idle plover
#

You see I also didn't know that but I tested it (last week i think) I though you need to define it

frosty moss
#

So what is the solution

#

@idle plover @swift portal

swift portal
#

stop pinging

idle plover
frosty moss
#

In fact, I did not try this, but I thought it would work in chat as well

#

How do I make the color change also in chat?

#

@idle plover

rustic oar
# frosty moss How do I make the color change also in chat?
const getPlayerTags(player, tag, defaultTag) {
    const Tags = player.getTags().filter((tags) => tags.startsWith(`${tag}:`));
    const tAgss = Tags.map((tags) => tags.replace(`${tag}:`, ""));
    return tAgss.length > 0 ? tAgss : [defaultTag];
}
world.afterEvents.itemUse.subscribe(event => {
const { source: player, itemStack: item } = event;
    if (item.typeId === "minecraft:stick") {
        form(player)
    };
});

function form(player){
const form = new ActionFormData()
.title("MENU_F5")
.body("MGCRAFT_F5")
.button("Red","textures/blocks/wool_colored_red") 
.button("Green","textures/blocks/wool_colored_lime") 
.button("3D", "textures/items/ender_eye")
.show(player).then(r =>{
    if (r.canceled) return;
    switch (r.selection) {
        case 0:
            player.nameTag = `§c${player.name}`
            player.runCommandAsync(`tag ${player.name} add color:§c`)
            break;
        case 1:
            player.nameTag = `§a${player.name}`
            player.runCommandAsync(`tag ${player.name} add color:§a`)
            break;
        case 2:
            player.runCommandAsync("camera @s set minecraft:first_person")
            break;
    }
}).catch(e => {
    console.error(e, e.stack);
});

world.beforeEvents.chatSend.subscribe((i) => {
    let { message: msg, sender } = i;
    const name = sender.name;
    const color = getPlayerTags(sender, `color`,`§7`);
    /* you can add more if you want. */
    world.sendMessage(`<${color}${name}§r> ${msg}`);
});```
frosty moss
#

There's a mistake

#
const getPlayerTags(player, tag, defaultTag) {
    const Tags = player.getTags().filter((tags) => tags.startsWith(`${tag}:`));
    const tAgss = Tags.map((tags) => tags.replace(`${tag}:`, ""));
    return tAgss.length > 0 ? tAgss : [defaultTag];
}```
frosty moss
#

[Scripting][error]-Plugin [NIGHT VISION ADDON - 1.0.0] - [main.js] ran with error: [SyntaxError: missing initializer for const variable at main.js:24
]

#

@rustic oar

frosty moss
#

😂😂

#

No they're really good

#

Okay

swift portal
iron grotto
iron grotto
#
world.beforeEvents.chatSend.subscribe(data => {
    data.cancel = true
    dimension.runCommandAsync(`tellraw @a {"rawtext":[{"text":"<${data.sender.nameTag}> ${data.message}"}]}`)
}

This would be enough for you

#

Yuh but I just ripped it from mine witch was pree sendMessage

#

Tho I might aswell update it know

rustic oar
frosty moss
#

there is a problem

#

[Scripting][error]-Plugin [NIGHT VISION ADDON - 1.0.0] - [main.js] ran with error: [SyntaxError: unexpected token in expression: '' at main.js:60

#

@rustic oar

rustic oar
frosty moss
#

[Scripting][error]-Plugin [NIGHT VISION ADDON - 1.0.0] - [main.js] ran with error: [SyntaxError: unexpected token in expression: '' at main.js:62
]

#

@rustic oar

rustic oar
frosty moss
#

I will try it

frosty moss
#

See, when I write in chat, the message appears twice, once in color and the other time in color

#

@rustic oar