My friend made an addon (back at may/june) and it basically was a command that changes your nametag (in chat, death message, above the name etc) but it is not working now... I fixed all errors from debug and it does not say that it has any error no more, but it doesn't appear in chat or death message, colors or even it saves upon rejoin... the only way I know it is changing my nametag is by renaming myself "dinnerbone" to get upside down...
Can someone tell me how could I fix this? Or make it works? Or say what is going on...
#player.nameTag
1 messages · Page 1 of 1 (latest)
The code:
import {
system,
world,
CommandPermissionLevel,
CustomCommandParamType,
Player
} from "@minecraft/server";
system.beforeEvents.startup.subscribe((ev) => {
ev.customCommandRegistry.registerCommand({
name: "nt:nametag",
description: "Change a player's nametag",
permissionLevel: CommandPermissionLevel.GameDirectors,
mandatoryParameters: [
{ type: CustomCommandParamType.String, name: "targetSelectorOrName" },
{ type: CustomCommandParamType.String, name: "newName" }
],
},
(origin, targetSelectorOrName, newName) => {
let sender = origin.sourceEntity;
const sendTo = (entity, msg) => {
if (entity && entity instanceof Player) {
entity.sendMessage(msg);
}
};
let target = null;
if (typeof targetSelectorOrName === "string" && targetSelectorOrName.startsWith("@")) {
if (targetSelectorOrName === "@p") {
target = [...world.getPlayers()][0] ?? null;
} else if (targetSelectorOrName === "@a") {
target = [...world.getPlayers()][0] ?? null;
} else {
target = null;
}
} else {
target = [...world.getPlayers()].find(p => p.name === targetSelectorOrName) ?? null;
}
if (!target) {
sendTo(sender, `§cPlayer '${targetSelectorOrName}' not found.`);
return { status: 1 };
}
sendTo(target, `§eYour name has been changed to §r${newName}§e.`);
if (sender && sender !== target) {
sendTo(sender, `§eYou changed §r${target.name}§e's name to §r${newName}§e.`);
}
system.run(() => {
target.nameTag = newName;
});
return { status: 0 };
});
});
I have a VERY stong feeling I did something wrong...
just use playerSelector instead of String wtf
i fixed it just because i was having an aneurysm while looking at that thing
import { world, system, CommandPermissionLevel, CustomCommandParamType, Player } from "@minecraft/server";
system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
customCommandRegistry.registerCommand({
name: "nt:nametag",
description: "Change players' nametag",
permissionLevel: CommandPermissionLevel.GameDirectors,
mandatoryParameters: [
{
name: "targets",
type: CustomCommandParamType.PlayerSelector
},
{
name: "nameTag",
type: CustomCommandParamType.String
}
]
}, (origin, args) => {
const source = origin.sourceEntity || origin.sourceBlock, [ targets, newNameTag ] = args;
for (const target of targets) system.run(() => target.nameTag = newNameTag)
})
})```
Sorry... I'm not any good with JS, and the main code was made by my friend xd
This solves the problem?
it should
np, didn't want to be mean btw, sorry
It is not showing up the command in game...
Oh no problem!
But does this code fixes the main issue that the nametag not showing on chat when you speak etc?
any logs?
I mean, the debugging bot said something about arg invalid "void"
that's not an issue, the chat uses the .name property of players, which is read-only
if you want to change it just cancel it with chatSend before event
oh i forgot to add a return, mb
import { world, system, CommandPermissionLevel, CustomCommandParamType, Player } from "@minecraft/server";
system.beforeEvents.startup.subscribe(({ customCommandRegistry }) => {
customCommandRegistry.registerCommand({
name: "nt:nametag",
description: "Change players' nametag",
permissionLevel: CommandPermissionLevel.GameDirectors,
mandatoryParameters: [
{
name: "targets",
type: CustomCommandParamType.PlayerSelector
},
{
name: "nameTag",
type: CustomCommandParamType.String
}
]
}, (origin, args) => {
const source = origin.sourceEntity || origin.sourceBlock, [ targets, newNameTag ] = args;
for (const target of targets) system.run(() => target.nameTag = newNameTag)
return { status: 0 };
})
})```
Ohh, it is something on newer versions? This script used to work back in 1.21.70 I think
Ty
i don't remember it working that way
Oh ok... I will learn about that ty
But how would the nametag reseting upon rejoining the world be fixed? Maybe storing the nametag on server and importing upon joining?
Idk the exact version, was late may/early june
We were able to change our names, add class and ranks, change the color etc
you want the nametag to reset back to the original name when a player leaves and rejoins?
No I want it to keep xd, but when I rejoin it seems to reset
save it in a dynamic property