RegisterChatChannel
Adds a chat channel that only some players see or may write into.
A channel is a room of the chat with a name, a label and a colour: Trade, Staff, a guild’s. A line a player types on it
goes to the players who see the channel, and the game shows it with the channel’s label. options is a table, and
every key of it is optional:
| key | what it is |
|---|---|
label |
what a chat shows for the channel, 32 characters at most ("Trade"); the name when left out |
color |
0xRRGGBBAA: the channel’s tab, and the colour of its lines that have none of their own (white) |
visible |
who sees the channel and its lines: "all" (the default), "admin" (admins), "party" (players who are in a party: a member’s line goes to their party alone), or a function(pid) that answers true for each player who sees it |
can_send |
who may type into it: true (everyone who sees it - the default), false (nobody: only the mode writes there), "admin", or a function(pid) that answers true for the players who may |
A player who cannot see a channel cannot write into it either. A line on a channel that does not exist, or one the
player may not write into, is refused with a notice (“There is no such chat channel.” / “You cannot write in that
channel.”) and never reaches OnPlayerText.
The name is 1 to 32 letters, digits and _ (capitals are lowered); the default channel, "", is always there and is
not registered. At most 64 channels; registering a name again replaces the channel. Each player’s chat is told the
channels they can see when they join and whenever a channel changes, they become or stop being an admin, or they join or
leave a party. A function is asked when that list is made and for every line - for a player who joins, after
OnPlayerConnect, so it may read what the mode set up there; when its answer changes for any other reason, call
RefreshChatChannels. A function that fails answers false and is logged and counted like any callback.
A reload of the mode empties the channels: register them in OnGameModeInit.
The answer is true, or false and the reason: "a channel name is 1-32 of a-z, 0-9 and _", "the label is over 32 characters", "too many channels (64 at most)", "visible is all, admin, party or a function" or "can_send is true, false, admin or a function".
Syntax
Section titled “Syntax”RegisterChatChannel(name [, options])| Parameter | Type | |
|---|---|---|
name |
string | the channel’s name - 1 to 32 of a-z 0-9 _ |
options |
table | { label, color, visible, can_send } - every key optional (optional) |
Returns
Section titled “Returns”true, or false, reason - the reason as a person reads it
Example
Section titled “Example”local moderators = {} -- pid -> true, kept by the mode
function OnGameModeInit() RegisterChatChannel("trade", { label = "Trade", color = 0xE0C060FF })
-- only the admins see it and write in it RegisterChatChannel("staff", { label = "Staff", color = 0xFF9090FF, visible = "admin", can_send = "admin" })
-- the moderators see it too, and only they write RegisterChatChannel("mods", { label = "Mods", visible = function(pid) return IsPlayerAdmin(pid) or moderators[pid] == true end, can_send = function(pid) return moderators[pid] == true end, })end
function makeModerator(pid) moderators[pid] = true RefreshChatChannels(pid) -- the rule changed: their chat looks againendSee also
Section titled “See also”UnregisterChatChannel · RefreshChatChannels · SendChatMessage · OnPlayerText · IsPlayerAdmin · the Chat and commands group of the index
