跳至正文
版本:latest - a1.147.x ⚖️

💬 聊天

配置、发送和拦截聊天消息。

🗿Static Class
This is a Static Class. Access it's methods directly with .. It's not possible to spawn new instances.
💂Authority
This static class can be accessed on both 🟧 Client and 🟦 Server side.
🧑‍💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

🎒 示例

(Chat.BroadcastMessage) Sends a message to everyone
Chat.BroadcastMessage("Welcome to the server!")

聊天中的颜色

你也可以在聊天中发送带颜色的消息! 为此,只需在一段文本两端加上样式标签即可:\<TAG>我超棒的文本</>

Server/Index.lua
Chat.BroadcastMessage("你好,我发了一条<cyan>青色</>文本消息!")

所有支持的文本样式/标签:

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

备注

不可将两个或多个样式组合在一起使用(例如 \<bold> + \<red>)。

🗿 静态函数

ReturnsNameDescription
AddMessage添加一条仅在本地显示的聊天消息
BroadcastMessage向所有玩家发送一条聊天消息
Clear清除所有消息
SendMessage仅向指定玩家发送一条聊天消息
SetConfiguration配置聊天的外观和位置
SetVisibility设置聊天是否可见

AddMessage

添加一条仅在本地显示的聊天消息
Chat.AddMessage(message)

Parameters

TypeParameterDefaultDescription
stringmessage Required parameter No description provided

BroadcastMessage

向所有玩家发送一条聊天消息
Chat.BroadcastMessage(message)

Parameters

TypeParameterDefaultDescription
stringmessage Required parameter 要发送给所有玩家的消息
Chat.BroadcastMessage Examples
Sends a message to everyone
Chat.BroadcastMessage("Welcome to the server!")

Clear

清除所有消息
Chat.Clear()

SendMessage

仅向指定玩家发送一条聊天消息
Chat.SendMessage(player, message)

Parameters

TypeParameterDefaultDescription
Playerplayer Required parameter 接收消息的玩家
stringmessage Required parameter 消息

SetConfiguration

配置聊天的外观和位置
Chat.SetConfiguration(screen_location?, size?, anchors_min?, anchors_max?, alignment?, justify?, show_scrollbar?)

Parameters

TypeParameterDefaultDescription
Vector2Dscreen_location?Vector2D(-25, 0)No description provided
Vector2Dsize?Vector2D(600, 250)No description provided
Vector2Danchors_min?Vector2D(1, 0.5)No description provided
Vector2Danchors_max?Vector2D(1, 0.5)No description provided
Vector2Dalignment?Vector2D(1, 0.5)No description provided
booleanjustify?trueNo description provided
booleanshow_scrollbar?trueNo description provided

SetVisibility

设置聊天是否可见
Chat.SetVisibility(is_visible)

Parameters

TypeParameterDefaultDescription
booleanis_visible Required parameter No description provided

🚀 事件

NameDescription
ChatEntry当收到新的聊天消息时调用,通过代码编写发送的新消息也会触发此事件
Close当玩家关闭聊天框时调用
Open当玩家打开聊天框时调用
PlayerSubmit当玩家在聊天框中提交消息时调用

ChatEntry

当收到新的聊天消息时调用,通过代码编写发送的新消息也会触发此事件

这对于创建自定义聊天界面同时仍旧使用内置系统非常有用
Chat.Subscribe("ChatEntry", function(message, player)
-- ChatEntry was called
end)

Arguments

TypeArgumentDescription
stringmessage消息
Player or nilplayer发送消息的玩家。如果该事件在客户端触发或通过代码发送,则为 nil

Close

当玩家关闭聊天框时调用
Chat.Subscribe("Close", function()
-- Close was called
end)

Open

当玩家打开聊天框时调用
Chat.Subscribe("Open", function()
-- Open was called
end)

PlayerSubmit

当玩家在聊天框中提交消息时调用

返回 false 以阻止该消息被发送
Chat.Subscribe("PlayerSubmit", function(message, player)
-- PlayerSubmit was called
return true
end)

Arguments

TypeArgumentDescription
stringmessage玩家发送的消息
Playerplayer发送消息的玩家 - 在客户端上它将始终是本地玩家