Clase de motor
VoiceChatService
*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.
Resumen
Propiedades
Métodos
GetChatGroupsAsync(players: Instances):{any} |
IsVoiceEnabledForUserIdAsync(userId: User):boolean |
Referencia API
Propiedades
DefaultDistanceAttenuation
Métodos
GetChatGroupsAsync
Parámetros
players:Instances |
Devuelve
Muestras de código
TeletransportarJugadorAlMejorServidorDeChat
-- Script del Servidor
local VoiceChatService = game:GetService("VoiceChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- ID del lugar de destino
--[[
Estado del servidor a nivel de universo con stub.
En la práctica, estos datos podrían almacenarse y actualizarse utilizando MemoryStore
u otro sistema backend.
Ejemplo de forma:
ActiveServers = {
{
serverId = "abc",
accessCode = "código-de-servidor-reservado",
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
accessCode = "código-de-servidor-reservado",
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("Error al recuperar grupos de chat para el jugador:", player.UserId)
return
end
-- Recopilar todos los IDs de grupos de chat para los que el jugador es elegible
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
-- Elegir el servidor con el mayor número de usuarios compatibles
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("No se encontró un servidor adecuado para el jugador:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("El teletransporte falló:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)