#.nick desnt work can someone help how do i give someone a tag if i start a command in chat
1 messages · Page 1 of 1 (latest)
Formatting JSON, JS
Please format your code as code-blocks! This makes the text monospaced, and has support for syntax highlighting.
The format looks like this:
for JSON
```json
{
"example": 123
}
```
for JavaScript
```js
console.log("hello world", 123)
```
The character used here is the backtick (U+0060 ` GRAVE ACCENT). This symbol is usually at the top left of your keyboard, occupying the tilde key (~). On mobile, it will be on the second or third page of symbols.
@lofty nebula it's
entity.addTag('nick:....')
entity.removeTag('foo')
yes ok i changed some stuff and used entity. its works bute its now spamming chat 2 time if send something
so what do i do now?
world.events.beforeChat.subscribe((eventData) => {
const cmd = (eventData.message || "").trim();
if (cmd.startsWith(".nick ")) {
const newNick = cmd.split(" ")[1];
const oldNick = eventData.sender.name;
handleNickChange(eventData.sender, oldNick, newNick);
eventData.cancel = true;
} else {
chatrank(eventData);
}
});
function chatrank(data) {
const allRanks = {
0: '',
1: '',
2: '',
3: '',
4: '',
10: '',
20: '',
30: '',
40: '',
50: '',
60: ''
};
const rankScore = world.scoreboard.getObjective('Rank').getScore(data.sender.scoreboard);
const rank = allRanks[rankScore];
const nicks = getNicks(data.sender);
const defaultNick = data.sender.name;
const nickname = nicks.length > 0 ? nicks[0] : defaultNick;
let text = `§》§l${rank} §7${nickname}: §f${data.message}`;
world.sendMessage(text);
data.cancel = true;
}
function handleNickChange(entity, oldNick, newNick) {
entity.getTags().forEach((tag) => {
if (tag.startsWith("nick:")) {
entity.removeTag(tag);
}
});
entity.addTag(`nick:${newNick}`);
entity.sendMessage(`§》§l§aYour nick has been set to ${newNick}`);
}
function getNicks(sender) {
const nick_prefix = "nick:";
const default_nick = `${sender.name}`;
const nicks = sender.getTags().map((tag) => {
if (!tag.startsWith(nick_prefix)) return null;
return tag.substring(nick_prefix.length);
}).filter((tag) => tag);
return nicks.length == 0 ? [default_nick] : nicks;
}
export { chatrank };```
.nick does work now thx but have other
2 problems now first its spamming chat 2 times if i send message and second i cant cancle the message if do .nick name