Motor Sınıfı
VoiceChatService
*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
GetChatGroupsAsync(players: Instances):{any} |
IsVoiceEnabledForUserIdAsync(userId: User):boolean |
API Referansı
Özellikler
DefaultDistanceAttenuation
Yöntemler
GetChatGroupsAsync
Parametreler
players:Instances |
Dönüşler
Kod Örnekleri
En İyi Sohbet Sunucusuna Oyuncuyu Taşı
-- Sunucu Betiği
local VoiceChatService = game:GetService("VoiceChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- Hedef yer ID'si
--[[
Evrensel düzeyde sunucu durumu için yer tutucu.
Pratikte, bu veriler MemoryStore
veya başka bir arka uç sistemi kullanılarak depolanabilir ve güncellenebilir.
Örnek şekil:
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 VoiceChatService:GetChatGroupsAsync({ player })
end)
if not success or not chatGroups then
warn("Oyuncu için sohbet gruplarını alırken hata oluştu:", player.UserId)
return
end
-- Oyuncunun uygun olduğu tüm sohbet grup kimliklerini 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()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("Taşıma başarısız oldu:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Sohbet Gruplarını Asenkron Olarak Al
local VoiceChatService = game:GetService("VoiceChatService")
local Players = game:GetService("Players")
local players = Players:GetPlayers()
local success, chatGroups = pcall(function()
return VoiceChatService: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
endIsVoiceEnabledForUserIdAsync
Parametreler
Dönüşler
Kod Örnekleri
Kullanıcı Kimliği İçin Ses Aktif Mi Asenkron
local Players = game:GetService("Players")
local VoiceChatService = game:GetService("VoiceChatService")
local localPlayer = Players.LocalPlayer
local success, enabled = pcall(function()
return VoiceChatService:IsVoiceEnabledForUserIdAsync(localPlayer.UserId)
end)
if success and enabled then
print("Sesli sohbet etkin!")
end