Text Chat Service
*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
Chat Version
Yöntemler
Can User Chat Async
Can Users Chat Async
Can Users Direct Chat Async
Dönüşler
Kod Örnekleri
KullanıcılarDoğrudanSohbetEdebilirMi
local TextChatService = game:GetService("TextChatService")
-- İki kullanıcının UserId'lerini değiştirin
local userId1 = 1
local userId2 = 2
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 nilDisplay Bubble
Get Chat Groups Async
Parametreler
players:Instances |
Dönüşler
Kod Örnekleri
En İyi Sohbet Sunucusuna Oyunçuyu Taşı
-- Sunucu Scripti
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.
Pratikte, bu veriler MemoryStore
veya başka bir arka uç sistemi kullanılarak saklanabilir ve güncellenebilir.
Örnek yapı:
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("Oyuncu için sohbet grupları alınamadı:", player.UserId)
return
end
-- Oyuncunun uygun olduğu tüm sohbet grup ID'lerini topla
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 uyumlu kullanıcı sayısına sahip sunucuyu seç
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()
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ReservedServerId = bestServer.privateServerId
TeleportService:TeleportAsync(
TARGET_PLACE_ID,
{ player },
teleportOptions
)
end)
if not ok then
warn("Taşınma başarısız oldu:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Sohbet Gruplarını Asenkron Olarak Al
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("Sohbet gruplarını almakta başarısız oldu")
return
end
for _, group in ipairs(chatGroups) do
-- Her grup sohbet grubu ID dizelerini içerir.
-- Eşleşen grup ID'sine sahip oyuncular birbirleriyle sohbet edebilir.
for _, groupId in ipairs(group) do
print("Sohbet grup ID'si:", groupId)
end
endOlaylar
Bubble Displayed
Text Chat Service. Bubble Displayed(
Parametreler
Message Received
Parametreler
Sending Message
Parametreler
Geri Aramalar
On Bubble Added
Parametreler
Dönüşler
On Chat Window Added
Parametreler
Dönüşler
On Incoming Message
Parametreler
Dönüşler