エンジンクラス
VoiceChatService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
プロパティ
方法
GetChatGroupsAsync(players: Instances):{any} |
IsVoiceEnabledForUserIdAsync(userId: User):boolean |
APIリファレンス
プロパティ
DefaultDistanceAttenuation
方法
GetChatGroupsAsync
パラメータ
players:Instances |
戻り値
コードサンプル
最適チャットサーバーへプレイヤーをテレポートする
-- サーバースクリプト
local VoiceChatService = game:GetService("VoiceChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- 目的地プレースID
--[[
スタブされたユニバース全体のサーバー状態。
実際には、このデータはMemoryStore
または別のバックエンドシステムを使用して保存および更新される可能性があります。
例の形:
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("プレイヤーのチャットグループを取得できませんでした:", player.UserId)
return
end
-- プレイヤーが資格のあるすべてのチャットグループIDを収集する
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
-- 互換性のあるユーザーが最も多いサーバーを選択する
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("プレイヤーに適したサーバーが見つかりませんでした:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("テレポートに失敗しました:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)