Text Chat Service
*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.
Podsumowanie
Właściwości
Metody
CanUserChatAsync(userId: User):boolean |
CanUsersChatAsync(userIdFrom: User,userIdTo: User):boolean |
CanUsersDirectChatAsync(requesterUserId: User,userIds: {any}):{any} |
DisplayBubble(partOrCharacter: Instance,message: string):() |
GetChatGroupsAsync(players: Instances):{any} |
Zdarzenia
BubbleDisplayed(partOrCharacter: Instance,textChatMessage: TextChatMessage):RBXScriptSignal |
MessageReceived(textChatMessage: TextChatMessage):RBXScriptSignal |
SendingMessage(textChatMessage: TextChatMessage):RBXScriptSignal |
Wywołania zwrotne
OnBubbleAdded(message: TextChatMessage,adornee: Instance):Tuple |
OnChatWindowAdded(message: TextChatMessage):Tuple |
OnIncomingMessage(message: TextChatMessage):Tuple |
Materiały referencyjne dotyczące interfejsów API
Właściwości
Chat Version
Metody
Can User Chat Async
Can Users Chat Async
Can Users Direct Chat Async
Zwroty
Przykłady kodu
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
-- Zastąp identyfikatorami użytkowników dwóch użytkowników
local userId1 = 1
local userId2 = 2
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Sprawdź, czy są kwalifikujący się uczestnicy
if #directChatParticipants > 0 then
local directChannel = Instance.new("TextChannel")
directChannel.Parent = TextChatService
for _, participant in directChatParticipants do
directChannel:AddUserAsync(participant)
end
return directChannel
end
warn("Nie można utworzyć TextChannel. Nie wystarczająca liczba kwalifikujących się użytkowników.")
return nilDisplay Bubble
Get Chat Groups Async
Parametry
players:Instances |
Zwroty
Przykłady kodu
TeleportujGraczaDoNajlepszegoSerweraCzatu
-- Skrypt serwera
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- ID miejsca docelowego
--[[
Zdefiniowany stan serwera w całym uniwersum.
W praktyce te dane mogą być przechowywane i aktualizowane za pomocą MemoryStore
lub innego systemu zaplecza.
Przykładowy kształt:
ActiveServers = {
{
serverId = "abc",
privateServerId = game.PrivateServerId,
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
privateServerId = game.PrivateServerId,
groupUserCounts = {
groupB = 8
}
}
}
]]
local ActiveServers = {}
local function teleportPlayerToBestServer(player)
local success, chatGroups = pcall(function()
return TextChatService:GetChatGroupsAsync({ player })
end)
if not success or not chatGroups then
warn("Nie udało się pobrać grup czatu dla gracza:", player.UserId)
return
end
-- Zbieranie wszystkich identyfikatorów grup czatu, do których gracz ma prawo
local playerGroupIds = {}
for _, group in ipairs(chatGroups) do
for _, groupId in ipairs(group) do
playerGroupIds[groupId] = true
end
end
local bestServer = nil
local bestUserCount = 0
-- Wybierz serwer z największą liczbą kompatybilnych użytkowników
for _, server in ipairs(ActiveServers) do
local compatibleUserCount = 0
for groupId, userCount in pairs(server.groupUserCounts) do
if playerGroupIds[groupId] then
compatibleUserCount += userCount
end
end
if compatibleUserCount > bestUserCount then
bestUserCount = compatibleUserCount
bestServer = server
end
end
if not bestServer then
warn("Nie znaleziono odpowiedniego serwera dla gracza:", player.UserId)
return
end
local ok, err = pcall(function()
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ReservedServerId = bestServer.privateServerId
TeleportService:TeleportAsync(
TARGET_PLACE_ID,
{ player },
teleportOptions
)
end)
if not ok then
warn("Teleportacja nie powiodła się:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Pobierz grupy czatu asynchronicznie
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local players = Players:GetPlayers()
local success, chatGroups = pcall(function()
return TextChatService:GetChatGroupsAsync(players)
end)
if not success then
warn("Nie udało się pobrać grup czatu")
return
end
for _, group in ipairs(chatGroups) do
-- Każda grupa zawiera identyfikatory grup czatu.
-- Gracze, którzy mają pasujący identyfikator grupy, mogą ze sobą czatować.
for _, groupId in ipairs(group) do
print("Identyfikator grupy czatu:", groupId)
end
endZdarzenia
Bubble Displayed
Text Chat Service. Bubble Displayed(
Parametry
Message Received
Parametry
Sending Message
Parametry
Wywołania zwrotne
On Bubble Added
Parametry
Zwroty
On Chat Window Added
Parametry
Zwroty
On Incoming Message
Parametry
Zwroty