#script form
1 messages · Page 1 of 1 (latest)
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}`
}```
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
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)
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.
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);
});
}```
This is what I used
@swift portal @thick lynx
its form.button not .button
does not change anything is the same
Yes IS SAME
?
thats just false
No its not test it out
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
You see I also didn't know that but I tested it (last week i think) I though you need to define it
stop pinging
idk what you mean its working fine
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
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}`);
});```
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];
}```
Error in this
[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
so it has been working?
You good now?
Your gonna have to make it so intercepts chat like a chat command but instead out putting to chat
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
I'm sorry, I put const there by mistake, not function
function 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];
}```
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
[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
I will try it
See, when I write in chat, the message appears twice, once in color and the other time in color
@rustic oar