Klasa silnika
TextChatService
*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
ChatVersion
Metody
CanUserChatAsync
CanUsersChatAsync
CanUsersDirectChatAsync
Zwroty
Przykłady kodu
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Sprawdź, czy są uprawnieni 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 stworzyć TextChannel. Za mało uprawnionych użytkowników.")
return nilDisplayBubble
GetChatGroupsAsync
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
--[[
Szkielety uniwersalnego stanu serwera.
W praktyce, te dane mogą być przechowywane i aktualizowane przy użyciu MemoryStore
lub innego systemu zaplecza.
Przykładowy kształt:
ActiveServers = {
{
serverId = "abc",
accessCode = "reserved-server-code",
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
accessCode = "reserved-server-code",
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 jest uprawniony
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()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("Teleportacja nie powiodła się:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Zdarzenia
BubbleDisplayed
TextChatService.BubbleDisplayed(
Parametry
MessageReceived
Parametry
SendingMessage
Parametry
Wywołania zwrotne
OnBubbleAdded
Parametry
Zwroty
OnChatWindowAdded
Parametry
Zwroty
OnIncomingMessage
Parametry
Zwroty