Motor Sınıfı
TextChatService
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Özet
Özellikler
Yöntemler
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} |
Olaylar
BubbleDisplayed(partOrCharacter: Instance,textChatMessage: TextChatMessage):RBXScriptSignal |
MessageReceived(textChatMessage: TextChatMessage):RBXScriptSignal |
SendingMessage(textChatMessage: TextChatMessage):RBXScriptSignal |
Geri Aramalar
OnBubbleAdded(message: TextChatMessage,adornee: Instance):Tuple |
OnChatWindowAdded(message: TextChatMessage):Tuple |
OnIncomingMessage(message: TextChatMessage):Tuple |
API Referansı
Özellikler
ChatVersion
Yöntemler
CanUserChatAsync
CanUsersChatAsync
CanUsersDirectChatAsync
Dönüşler
Kod Örnekleri
KullanıcılarDoğrudanSohbetEdebilirMi
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Uygun katılımcıları kontrol et
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("TextChannel oluşturulamadı. Yeterli uygun kullanıcı yok.")
return nilDisplayBubble
GetChatGroupsAsync
Parametreler
players:Instances |
Dönüşler
Kod Örnekleri
En İyi Sohbet Sunucusuna Oyunçuyu Taşı
-- Sunucu Betiği
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- Hedef yer ID'si
--[[
Evren genelinde sunucu durumu için stub.
Pratikte, bu veri MemoryStore
veya başka bir arka uç sistemi kullanılarak depolanabilir ve güncellenebilir.
Örnek şekli:
ActiveServers = {
{
serverId = "abc",
accessCode = "rezervli-sunucu-kodu",
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
accessCode = "rezervli-sunucu-kodu",
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("Oyuncu için sohbet grupları alınamadı:", player.UserId)
return
end
-- Oyuncunun uygun olduğu tüm sohbet grup ID'lerini toplayın
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
-- En yüksek sayıda uyumlu kullanıcıya sahip sunucuyu seçin
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("Oyuncu için uygun sunucu bulunamadı:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("Taşınma başarısız oldu:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Olaylar
BubbleDisplayed
TextChatService.BubbleDisplayed(
Parametreler
MessageReceived
Parametreler
SendingMessage
Parametreler
Geri Aramalar
OnBubbleAdded
Parametreler
Dönüşler
OnChatWindowAdded
Parametreler
Dönüşler
OnIncomingMessage
Parametreler
Dönüşler