Ir para o conteúdo principal
Version: latest - a1.172.0 ⚖️

💬 Chat

Configure, send and intercept chat messages

🗿Static ClassClient & Server🧑‍💻API Source

🎒 Examples​

(Chat.BroadcastMessage) Sends a message to everyone
Chat.BroadcastMessage("Welcome to the server!")
(Chat.Submit) Forwards a message from a custom chat interface
Events.SubscribeRemote("MyChatSubmit", function(player, message)
if (not Chat.Submit(player, message)) then
Chat.SendMessage(player, "Your message was not sent")
end
end)

Colors in Chat​

It is also possible to send colored messages in the Chat! For that, just circumvent a piece of text with a style tag: \<TAG>my awesome text</>.

Server/Index.lua
Chat.BroadcastMessage("Hello with <cyan>Cyan</> text message!")

All supported text styles/tags:

\<cyan> \<green> \<blue> \<purple> \<marengo> \<yellow> \<orange> \<red> \<grey> \<bold> \<italic>

note

It is NOT possible to combine two or more styles together (e.g. \<bold> + \<red>).

🗿 Static Functions​

AddMessageAdds a chat message which will display local only
BroadcastMessageSends a chat message to all Players
ClearClears all messages
SendMessageSends a chat message to a Player only
SetConfigurationConfigures the Chat visuals and position
SetVisibilitySets if the Chat is visible or not
Submit: booleanSubmits a chat message as if the Player had typed it in the chat
Subscribe: functionSubscribes to an Event
UnsubscribeUnsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback

AddMessageModerate​

Adds a chat message which will display local only

Chat.AddMessage(message)
Parameters
NameTypeDescrição
messagestringThe message, supports the same rich text tags as the chat

BroadcastMessageModerate​

Sends a chat message to all Players

Chat.BroadcastMessage(message)
Parameters
NameTypeDescrição
messagestringThe message to send to all Players
Examples (1)
Sends a message to everyone
Chat.BroadcastMessage("Welcome to the server!")

ClearModerate​

Clears all messages

Chat.Clear()

SendMessageOptimal​

Sends a chat message to a Player only

Chat.SendMessage(player, message)
Parameters
NameTypeDescrição
playerPlayerThe player to receive the message
messagestringThe message

SetConfigurationModerate​

Configures the Chat visuals and position

Chat.SetConfiguration(screen_location?, size?, anchors_min?, anchors_max?, alignment?, justify?, show_scrollbar?)
Parameters
NameTypeDescrição
screen_location?Vector2DScreen location, or the left and top offsets when the anchors are stretched Default Vector2D(-25, 0)
size?Vector2DSize, or the right and bottom offsets when the anchors are stretched Default Vector2D(600, 250)
anchors_min?Vector2DMin anchor, from (0, 0) top-left to (1, 1) bottom-right Default Vector2D(1, 0.5)
anchors_max?Vector2DMax anchor, from (0, 0) top-left to (1, 1) bottom-right Default Vector2D(1, 0.5)
alignment?Vector2DPivot of the chat, (0.5, 0.5) is the center Default Vector2D(1, 0.5)
justify?booleanWhether the text is justified Default true
show_scrollbar?booleanWhether to show the scrollbar Default true

SetVisibilityOptimal​

Sets if the Chat is visible or not

Chat.SetVisibility(is_visible)
Parameters
NameTypeDescrição
is_visiblebooleanWhether the Chat is visible or not

SubmitModerate​

Submits a chat message as if the Player had typed it in the chat

It also triggers the PlayerSubmit event

local ret = Chat.Submit(player, message)
Parameters
NameTypeDescrição
playerPlayerThe player who is sending the message
messagestringThe message
Returns
TypeDescrição
booleanfalse if a PlayerSubmit handler cancelled the message, true if it was broadcast
Examples (1)
Forwards a message from a custom chat interface
Events.SubscribeRemote("MyChatSubmit", function(player, message)
if (not Chat.Submit(player, message)) then
Chat.SendMessage(player, "Your message was not sent")
end
end)

SubscribeOptimal​

Subscribes to an Event

local ret = Chat.Subscribe(event_name, callback)
Parameters
NameTypeDescrição
event_namestringEvent to subscribe to
callbackfunctionCallback to run on the event occurring
Returns
TypeDescrição
functionThe function callback

UnsubscribeOptimal​

Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback

Chat.Unsubscribe(event_name, callback?)
Parameters
NameTypeDescrição
event_namestringEvent to unsubscribe to
callback?functionOptional callback to specifically unsubscribe to Default nil

🚀 Events​

ChatEntryCalled when a new Chat Message is received, this is also triggered when new messages are sent programatically
CloseWhen player closes the Chat
OpenWhen player opens the Chat
PlayerSubmitCalled when a player submits a message in the chat

ChatEntry​

Called when a new Chat Message is received, this is also triggered when new messages are sent programatically

This is useful for creating your own Chat interface while still use the built-in system

Chat.Subscribe("ChatEntry", function(message, player)
-- ChatEntry was called
end)
Arguments
NameTypeDescrição
messagestringThe message
playerPlayer or nilThe player who sent the message or nil if this was called on client side or was sent through code

Close​

When player closes the Chat

Chat.Subscribe("Close", function()
-- Close was called
end)

Open​

When player opens the Chat

Chat.Subscribe("Open", function()
-- Open was called
end)

PlayerSubmit​

Called when a player submits a message in the chat

Chat.Subscribe("PlayerSubmit", function(message, player)
-- PlayerSubmit was called
return true
end)
Arguments
NameTypeDescrição
messagestringThe message sent by the player
playerPlayerThe player who sent the message - on client it will always be the localplayer
Returns
TypeDescrição
booleanReturn false to prevent the message from being sent