요약
속성
메서드
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)