
World Code
Tags:
Command
Creator:
XxWarriorXxSHADOWXx
Code:
const MAX_CHARS = 90
let shopInitialized = false
let whisperTarget = {}
let mutedTagEnabled = {}
let lastMessageTick = {}
let currentTick = 0
const CHAT_COLOR = "#cef3ff"
const COOLDOWN_TICKS = 20
const msg = (p, t) => api.sendMessage(p, [{ str: t, style: { color: CHAT_COLOR } }])
const nameOf = id => api.getEntityName(id)
function initializeShop() {
if (shopInitialized) return
shopInitialized = true
api.configureShopCategory("Chat", {
autoSelectCategory: true,
customTitle: "Chat",
sortPriority: 10
})
api.createShopItem("Chat", "WhisperSend", {
image: "info-circle",
sortPriority: 0,
customTitle: "Whisper",
description: "Send a private message to whoever you have selected.",
userInput: { type: "text", placeholderText: "Type whisper message here" },
buyButtonText: "Send"
})
api.createShopItem("Chat", "WhisperSelect", {
image: "person",
sortPriority: 1,
customTitle: "Choose Player",
description: "Choose a player to whisper to.",
userInput: { type: "dropdown", dropdownOptions: [] },
buyButtonText: "Select"
})
api.createShopItem("Chat", "Tags", {
image: "volume-slash",
sortPriority: 2,
customTitle: "Tags",
description: "Toggles on and off the muted tag for any muted players.",
userInput: { type: "dropdown", dropdownOptions: ["No Tags", "Muted"] },
buyButtonText: "Apply"
})
api.createShopItem("Chat", "ChatMessage", {
image: "globe",
sortPriority: 3,
userInput: { type: "text", placeholderText: "Type message here" },
buyButtonText: "Send",
customTitle: "Chat",
description: "Type anything to chat! Mostly useful for muted people."
})
}
function updateDropdown(p) {
const names = api.getPlayerIds().filter(id => id !== p).map(nameOf)
api.updateShopItemForPlayer(p, "Chat", "WhisperSelect", {
userInput: { type: "dropdown", dropdownOptions: names }
})
}
function canSend(p) {
if (!lastMessageTick[p]) return true
if (currentTick - lastMessageTick[p] >= COOLDOWN_TICKS) return true
msg(p, "You must wait 1 second before sending a message.")
return false
}
function recordSend(p) {
lastMessageTick[p] = currentTick
}
function onPlayerJoin(p) {
initializeShop()
mutedTagEnabled[p] = false
lastMessageTick[p] = 0
api.getPlayerIds().forEach(updateDropdown)
}
function onPlayerLeave(p) {
delete mutedTagEnabled[p]
delete whisperTarget[p]
delete lastMessageTick[p]
const leavingName = nameOf(p)
api.getPlayerIds().forEach(id => {
if (whisperTarget[id] === leavingName) {
delete whisperTarget[id]
msg(id, "Whisper target cleared.")
}
updateDropdown(id)
})
}
function onPlayerBoughtShopItem(p, category, item, _, input) {
if (category !== "Chat") return
if (item === "ChatMessage") {
if (!canSend(p)) return
if (!input || input.length > MAX_CHARS)
return msg(p, "Message must be 90 characters or less.")
recordSend(p)
const tag = mutedTagEnabled[p] ? "[Muted] " : ""
api.broadcastMessage([
{ str: tag + nameOf(p) + ": ", style: { color: CHAT_COLOR } },
{ str: input }
])
}
if (item === "Tags") {
mutedTagEnabled[p] = input === "Muted"
msg(p, mutedTagEnabled[p] ? 'Enabled "Muted" tag.' : 'Disabled "Muted" tag.')
}
if (item === "WhisperSelect") {
whisperTarget[p] = input
msg(p, "Selected: " + input)
}
if (item === "WhisperSend") {
if (!canSend(p)) return
if (!input || input.length > MAX_CHARS)
return msg(p, "Message must be 90 characters or less.")
const targetName = whisperTarget[p]
if (!targetName) return msg(p, "Select somebody to whisper first.")
const targetId = api.getPlayerIds().find(id => nameOf(id) === targetName)
if (!targetId) return msg(p, "Player not found.")
recordSend(p)
api.sendMessage(targetId, [
{ str: "[Whisper] " + nameOf(p) + ": ", style: { color: CHAT_COLOR } },
{ str: input }
])
api.sendMessage(p, [
{ str: "[Whisper → " + targetName + "] ", style: { color: CHAT_COLOR } },
{ str: input }
])
}
}
function tick() {
currentTick++
}
Instructions:
For mute ppl