PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Lua Chat System — Server API — ChatSpeaker

Lua Chat System — Server API — ChatSpeaker

Oct 31 2018, 12:10 AM PST 10 min

< Return to Lua Chat System

A ChatSpeaker is the representation of one entity that may speak in a ChatChannel. Each Player connected to the game automatically has an associated ChatSpeaker. Additional ChatSpeakers may be constructed for non-players (such as announcers or hint messages) using ChatService:AddSpeaker().

Properties

Name

  • Type: string Name
  • Description: The name of the speaker, used in referencing this speaker while calling many other functions.

Methods

JoinChannel

  • Parameters: string channelName
  • Description: Adds the speaker to the channel with the given channelName
  • Returns: void

LeaveChannel

  • Parameters: string channelName
  • Description: Removes the speaker from the channel with the given channelName
  • Returns: void

GetChannelList

  • Parameters: None
  • Description: Returns a list of the names of all the channels the speaker is in.
  • Returns: array<string>

IsInChannel

  • Parameters: string channelName
  • Description: Returns whether the speaker is in the channel with the given channelName.
  • Returns: bool

SayMessage

  • Parameters: string message, string channelName, dictionary<string, Variant> extraData
  • Description: Causes the speaker to say message and return the ChatMessage object created in doing so.
  • Returns: ChatMessage

SendMessage

  • Parameters: string message, string channel, string fromSpeaker
  • Description: Sends a message to the ChatSpeaker with the given fromSpeaker name. If no such speaker is in the channel, this method creates a warning and the speaker will not see the message.
  • Returns: void

SendSystemMessage

  • Parameters: string message, string channelName
  • Description: Sends a system message to the ChatChannel with the given channelName. If the speaker is not in the channel, then this message will create a warning and other speakers in the channel will not see the message.
  • Returns: void

GetPlayer

  • Parameters: None
  • Description: Returns the Player object associated with the speaker. If the speaker is not for a player (a bot) then this returns nil.
  • Returns: Player or nil

SetExtraData

  • Parameters: string key, Variant data
  • Description: Sets some extra data for the speaker under a specific key. Whenever the speaker sends a ChatMessage this extra data is attached to the message if none is explicitly provided with the message. For example, this allows the speaker’s chat color to be set.
  • Returns: void

GetExtraData

  • Parameters: string key
  • Description: Returns the extra data associated with the given key, set using SetExtraData.
  • Returns: Variant

Events

SaidMessage

ReceivedMessage

ReceivedSystemMessage

ChannelJoined

  • Parameters: string channelName, string channelWelcomeMessage
  • Description: Fired when the speaker joins the ChatChannel with the given channelName.

ChannelLeft

  • Parameters: string channelName
  • Description: Fired when the speaker leaves a ChatChannel with the given channelName.

Muted

  • Parameters: string channelName, string reason = nil, int duration = 0
  • Description: Fired when the speaker is muted on the ChatChannel with the given channelName for the given duration (if provided). There may or may not be a reason provided.

Unmuted

  • Parameters: string channelName
  • Description: Fired when the speaker is unmuted on the ChatChannel with the given channelName.

ExtraDataUpdated

  • Parameters: string key, Variant data
  • Description: Fired when the default value of a key in the speaker’s extra data is updated using SetExtraData.

MainChannelSet

  • Parameters: string channelName
  • Description: Fired when the speakers main channel is changed to the ChatChannel with the given channelName.