Chat

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務
未複製

聊天服務 負荷聊天系統 的 Lua 代碼負荷聊天系統。與 Class.StarterPlayerScripts 類似,預設對象如 StarterPlayerScripts 和 2>Class.ModuleScript|ModuleScripts2> 。

概要

屬性

  • 決定玩家的聊天訊息是否會在他們的遊戲虛擬人偶上顯示。

  • 無法存取安全性
    平行讀取

    切換是否在遊戲執行時自動載入預設聊天框架。

方法

屬性

BubbleChatEnabled

平行讀取

如果是,在聊天中輸入訊息會導致玩家的 Player.Character 上方的聊天泡泡。這個行為可以啟用直接在 Studio 中勾選此檢查盒,或使用 LocalScript :


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

這必須在客戶端執行,切換此值在伺服器端的 Script 將無效。

LoadDefaultChat

無法存取安全性
平行讀取

切換是否在遊戲執行時自動載入預設聊天框架。

方法

Chat

void

聊天功能發動此方法中指定的 Chat.Chatted 事件。

由預設情況下,每個玩家的 LocalScript 對象內有一個名為 PlayerScripts 的對話框,這會在聊天事件發生時發生對話框上方的對話框,這會導致對話框上方的 角色 會顯示。

注意: 由於對話框由本地指令碼控制,因此您不會能夠在此方法中創建的對話框,除非您正在執行 Play Solo 模式。

參數

partOrCharacter: Instance

一個在 泡泡聊天 對話框上顯示的部分或角色。

message: string

訊息字串正在聊天。

Entity.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

Class.Chat:RegisterChatCallback()|RegisterChatCallback 已註冊的聊天回撥式,並且在 Class.Chat:RegisterChatCallback()|RegisterChatCallback 的基礎上呼叫 ChatChat 回撥式。它將返回註冊的回撥式的結果,或發生錯誤,如果沒有回撥式被註冊。

此功能是由 Lua 聊天系統呼叫,以便聊天回撥可以註冊以變更某些功能的行為。除非您正在替換預設 Lua 聊天系統,否則您不需要呼叫此功能。您可以閱讀有關不同的回撥功能在 Chat:RegisterChatCallback()

參數

callbackType: Enum.ChatCallbackType

要召喚的回潮類型。

callbackArguments: Tuple

可以傳送到註冊的回報函數的參數。


返回

返回 ChatCallbackType 的函數所返回的值。

RegisterChatCallback

void

RegisterChatCallback 用於影響 Lua 聊天系統的行為,並且在一些聊天系統事件上註冊一個函數。第一個引數數決定了事件 (使用 Enum.ChatCallbackType 枚枚) 將被綁定

在創建聊天視窗時

僅限客戶端。 必須在客戶端建造聊天窗口之前召喚才能合併資料。 必須返回一個表的設定才能與聊天設定模組合併的資訊。

OnClientFormattingMessage

僅適用於客戶端。 在客戶端顯示訊息之前,呼叫此功能(無論是玩家聊天訊息、系統訊息或/me指令)。 此功能會與訊息對象呼叫,可能(或可能不)返回表被合併到 message.ExtraData 中。

OnClientSendingMessage

本次未召用。

在伺服器收到訊息

僅適用於伺服器。當伺服器收到來自喇叭的訊息時(注意喇叭可能不是一個 Player 聊天) 時,此回調會被呼叫。這個回調使用 Message 對象來變更訊息處理方式。 將此回調設置可能會導致伺服器無法正常運作。

  • message.ShouldDeliver 設置為 false 以取消向玩家發送訊息的交付(有助於實現聊天排除清單)
  • 在訊息-by-message 基礎上獲取/設置喇叭的顏色(message.ExtraData.NameColor,一個顏色3)

參數

callbackType: Enum.ChatCallbackType

注冊函數的回調 (這將決定函數的呼叫方式)。

callbackFunction: function

使用 聊天hat:ExecuteChatCallback 呼叫時間的函數。


返回

void

SetBubbleChatSettings

void

這個功能自訂遊戲中的泡泡聊天的各個設定。

在使用此功能之前,請確認泡泡聊天已啟用,設置 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,則會因帳號設定而未允許聊天。

參數

userId: number

返回

CanUsersChatAsync

暫停

兩個使用者無法通信,因為他們的帳戶設定不允許。

參數

userIdFrom: number
userIdTo: number

返回

FilterStringAsync

暫停

部分竊取警告 : 使用 LocalScript 從客戶端呼叫此功能是已棄用時的,並且將在未來停用。 文字過濾應從 Script 上的服務器上使用類似名稱的 0> Class.TextService:FilterStringAsync()0> 來進行。 這使用不同的參數和

不妥確過濾玩家生成的文字的遊戲可能會被禁止行動作。請確保遊戲正確過濾文字再發佈。

FilterStringAsync 過濾器使用過濾適合發送和接收玩家的字串。如果過濾器字符串是用於持續消訊息,例如商購物名稱、寫在牌子上等,則應該呼叫作為發送者和接收者的作者。

這個函數應該每次玩家可以在任何 上下文 中輸入自訂文字,最常見的使用 Class.Toolbar 。一些要過濾的文字範例:

  • 自訂聊天訊息
  • 自訂角色名稱
  • 在大亨風格遊戲中的商店名稱

參數

stringToFilter: string

原始字串要被過濾,與玩家正確輸入的字串相同。

playerFrom: Player

文字的作者。

playerTo: Player

提供的文字的目的地;如果文字持續(請參閱說明)。


返回

FilterStringForBroadcast

暫停

playerFrom 傳來的串補發信息,以便在沒有特定目標的情況下播放。過濾器訊息包含更多限制,比如 Chat:FilterStringAsync()

一些使用此方法的範例:

  • 訊息牆
  • 跨服務器吶喊
  • 使用者創建的標誌

LocalScripts 呼叫 FilterString 是已過時的,將在未來停用。 文字過濾應從服務器端 Scripts 使用 FilterStringAsync 執行。

注意: 不使用此過濾器功能的遊戲可能會被視為垃圾遊戲或其他玩家生成的文字。

參數

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