Chat and translated texts
Sending messages
The server can write to everyone or to one player, with an optional sender name:
const { Chat } = kcds.core; Chat.sendToAll('The tournament starts at noon.', { author: 'Herald' }); Chat.sendToPlayer(player, 'Only you can read this.');
What happens to what players type
A line starting with / is a command. Nobody else sees it, and your script receives it as
playerCommand(player, command, args).
Any other line is first sent to all players by the built-in relay, and then playerChat(player, text) fires. For local chat, radio or roleplay channels, switch the relay off and deliver the lines
yourself:
const { Chat, Events } = kcds.core; const { Player } = kcds.players; Chat.setChatRelay(false); Events.on('playerChat', (speaker, text) => { for (const listener of Player.inRadius(speaker.position, 30)) { Chat.sendToPlayer(listener, text, { author: speaker.nickname }); } });
Chat in a client script
Inside a player's game:
kcds.core.Chat.send(text)writes as that player.kcds.core.Chat.open()andkcds.core.Chat.close()open and close the chat window.kcds.core.Chat.setUIVisible(visible)shows or hides it.
Translated texts
Locales holds texts by key and language. It covers KCDS's own short messages, such as the notice a
pickpocket's victim gets, a carry limit or a chest in use, and you can add keys for your own content.
Giving an existing key your own text replaces KCDS's wording.
For each player, the text is chosen in this order:
- your text in the player's game language (
player.language) - your English text
- the built-in default
Placeholders such as {name} are filled from the values you pass.
const { Chat, Events, Locales } = kcds.core; Locales.set('english', { 'myshop.welcome': 'Welcome, {name}!' }); Locales.set('czech', { 'myshop.welcome': 'Vítej, {name}!' }); Events.on('playerReady', (player) => { const line = Locales.text(player, 'myshop.welcome', { name: player.nickname }); Chat.sendToPlayer(player, line); });