Chat

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建
服务
未复制

聊天服务中的 聊天 房屋 Lua 代码负责运行 传统聊天系统。与 StarterPlayerScripts 类似,默认对象如 2>Class.Script|Scripts2> 和 5>Class.ModuleScript|ModuleScripts5> 。

概要

属性

  • 决定是否在玩家的聊天消息会在他们的虚拟形象戏头像上显示。

  • 无法获知安全性
    读取并联

    切换是否在游戏运行时自动加载默认聊天框架。

方法

属性

BubbleChatEnabled

读取并联

如果是这样,输入聊天中的消息会导致聊天泡泡弹出在玩家的 Player.Character 上。 此行为可以通过直接在 Studio 中单击此复选框来启用,或使用 LocalScript :


local ChatService = game:GetService("Chat")
ChatService.BubbleChatEnabled = true

这必须在客户端执行,在服务器端的 Script 将无效。

LoadDefaultChat

无法获知安全性
读取并联

切换是否在游戏运行时自动加载默认聊天框架。

方法

Chat

void

聊天功能使用 Chat.Chatted 事件发起指定在此方法中指定的参数。

默认情况下,每个玩家的 LocalScript 对象内有一个 PlayerScripts,这会导致聊天事件发生时弹出一个对话框,上方的 角色或角色 部分。

注意: 由于对话框由本地脚本控制,因此您不能在此方法运行的情况下查看任何由此方法创建的对话框,除非您正在运行 Solo Play 模式。

参数

partOrCharacter: Instance

一个是气泡聊天对话框应该出现上方的实例。

message: string

正在聊天的消息字符串。

一个 Enum.ChatColor 指定聊天消信息的颜色。

默认值:"Blue"

返回

void

代码示例

The below example would create a part in Workspace and cause it to exclaim "Blame John!"

Chat:Chat

local ChatService = game:GetService("Chat")
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace
ChatService:Chat(part, "Blame John!", "Red")

InvokeChatCallback

调用聊天回调将调用注册在 RegisterChatCallback 的函数,根据聊天回调类型枚和参数发送函数。它将返回注册的函数的结果或发生错误,如果没有注册任何函数。

此函数是由 Lua 聊天系统调用,以便聊天回调可以被注册来更改某些功能的行为。 除非您正在替换默认 Lua 聊天系统以您自拥有的,否则您不应该调用此函数。 您可以阅读有关不同的回调函数在 Chat:RegisterChatCallback()

参数

callbackType: Enum.ChatCallbackType

要调用的回调类型。

callbackArguments: Tuple

将发送到注册的回调函数的参数。


返回

返回给指定的聊天回调类型的函数注册的值。

RegisterChatCallback

void

注册聊天回调将某个聊天系统事件绑定到 Lua 聊天系统的某个特定函数来影响 Lua 聊天系统的行为。 第一个参数确定事件 (使用 Enum.ChatCallbackType 枚枚) 到第二参数,

在创建聊天窗口时

仅限客户端。在客户端构建聊天窗口之前,必须返回一个表的设置才能被合并到聊天设置模块的信息中。

客户端格式化消息

仅限客户端。在客户端显示消息之前,它会被调用(无论是玩家聊天消信息、系统消信息或/me命令)。此功能使用了消息对象,可能(或可能不会)返回表合并到 message.ExtraData

客户端发送消息

本次未调用。

正在接收消息

仅服务器。当服务器接到来自发言人的消息时,它会被触发(注意,发言人可能不是一个 Player 聊天)。 此回调使用 消息 对象。 函数可以对消息对象进行更改,以改变消息的处理方式。 返回此回调必须返回 消息 对象。 设置此回调可以允许服务器

  • message.ShouldDeliver 设置为 false 以取消向玩家发送消息的交付(有助于实现聊天排除列表)
  • 在消信息-by-message 基础上获取/设置扬声麦克风的名称颜色 (message.ExtraData.NameColor , 颜色3)

参数

callbackType: Enum.ChatCallbackType

注册函数的回调(这取决于函数的调用方式)。

callbackFunction: function

使用 聊天hat:ExecuteChatCallback 调用时调用的函数。


返回

void

SetBubbleChatSettings

void

此功能自定义了游戏中的泡泡聊天设置。

在使用它之前,请确保 Bubble Chat 已通过设置 Chat.BubbleChatEnabled 启用。

设置参数是一个包含键为您想要编辑设置的名称,值为您想要更改这些设置的内容的表。请注意,您不需要包含其中的所有键,只需将其中的一些值提出即可使其保留其默认值。

此函数仅在客户端,尝试在服务器上调用将触发错误。

参数

settings: Variant

一个设置表。


返回

void

代码示例

When run from a LocalScript, this snippet will make all the chat bubbles appear with bigger text under a different font and a light blue background. Note that all the other settings will keep their default value.

Customize visual aspects

local ChatService = game:GetService("Chat")
ChatService:SetBubbleChatSettings({
BackgroundColor3 = Color3.fromRGB(180, 210, 228),
TextSize = 20,
Font = Enum.Font.Cartoon,
})

If you want to reset the bubble chat to its default look, you can call this function with an empty table, because any setting you omit from the argument will result in it returning to its default value:

Restore default settings

local ChatService = game:GetService("Chat")
ChatService:SetBubbleChatSettings({})

CanUserChatAsync

暂停

如果玩家没有指定的 Player.UserId,将返回 false 因为他们的帐户设置。

参数

userId: number

返回

CanUsersChatAsync

暂停

如果两个用户无法通信,因为他们的帐户设置不允许它,会返回 false。

参数

userIdFrom: number
userIdTo: number

返回

FilterStringAsync

暂停

部分退化警告 : 使用客户端使用 LocalScript 调用此函数是有弃用的,将在未来禁用。 文本过滤应从服务器上使用 Script 上的同名的 0> Class.TextService:FilterStringAsync() 进行,使用不同的参数和返回类输入。

不能正确过滤玩家生成的文本的游戏可能会受到审核动作。请确保在发布游戏之前,游戏正确过滤了文本。

FilterStringAsync 过滤器使用适合发送和接收玩家的过滤器。如果使用过滤器串,例如购物店名称、写在牌子上等,那么函数应该调用作为发送方和接收方的作者。

这个函数应该用 每次玩家可以在任何上下文中输入自定义文本,通常使用一个 Class.Toolbar 。一些要过滤的文本示例:

  • 自定义聊天消息
  • 自定义角色名称
  • 在大亨式游戏中商店的名称

参数

stringToFilter: string

原始文本将被过滤,与玩家正确输入的内容。

playerFrom: Player

文本的作者。

playerTo: Player

受件人员所指定的文本;如果文本是持久的,请使用作者(请参阅描述)。


返回

FilterStringForBroadcast

暂停

playerFrom 发送的串文本对特定目标无法播放,因此需要使用 Chat:FilterStringAsync() 来过滤它们。

一些示例,这方法可以用来:

  • 消息墙
  • 跨服务器喊声
  • 用户创建的标志

使用 FilterString 从 LocalScripts 调用是已过期的,将在未来中禁用。 文本过滤应从服务器端 Scripts 使用 FilterScriptAsync 进行。

注意: 不使用此过滤器功能为自定义聊天或其他用户生成的文本可能会被禁止操动作。

参数

stringToFilter: string

正在过滤消息字符串。

playerFrom: Player

发送消信息的玩家的实例。


返回

已过滤的消息字符串。

代码示例

The following example shows a simple way to use the FilterStringForBroadcast function. The example uses the message variable as the stringToFilter argument and the local player as the playerFrom argument.

The example then prints the result of the filtering function, FilteredString.

Chat:FilterStringForBroadcast

local Players = game:GetService("Players")
local Chat = game:GetService("Chat")
local playerFrom = Players.LocalPlayer
local message = "Hello world!"
-- Filter the string and store the result in the 'FilteredString' variable
local filteredString = Chat:FilterStringForBroadcast(message, playerFrom)
print(filteredString)

活动

Chatted

Chat:Chat() 被调用时触发。

参数

part: Instance
message: string