Clase de motor
TextChatService
*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
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} |
Eventos
BubbleDisplayed(partOrCharacter: Instance,textChatMessage: TextChatMessage):RBXScriptSignal |
MessageReceived(textChatMessage: TextChatMessage):RBXScriptSignal |
SendingMessage(textChatMessage: TextChatMessage):RBXScriptSignal |
Llamadas
OnBubbleAdded(message: TextChatMessage,adornee: Instance):Tuple |
OnChatWindowAdded(message: TextChatMessage):Tuple |
OnIncomingMessage(message: TextChatMessage):Tuple |
Referencia API
Propiedades
ChatVersion
Métodos
CanUserChatAsync
CanUsersChatAsync
CanUsersDirectChatAsync
Devuelve
Muestras de código
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Verificar si hay participantes elegibles
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("No se pudo crear TextChannel. No hay suficientes usuarios elegibles.")
return nilDisplayBubble
GetChatGroupsAsync
Parámetros
players:Instances |
Devuelve
Muestras de código
TeletransportarJugadorAlMejorServidorDeChat
-- Script del Servidor
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- ID del lugar de destino
--[[
Estado de servidor a nivel de universo simulado.
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 TextChatService:GetChatGroupsAsync({ player })
end)
if not success or not chatGroups then
warn("No se pudieron recuperar los grupos de chat para el jugador:", player.UserId)
return
end
-- Recoger todos los IDs de grupos de chat a 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)Eventos
BubbleDisplayed
TextChatService.BubbleDisplayed(
Parámetros
MessageReceived
Parámetros
SendingMessage
Parámetros
Llamadas
OnBubbleAdded
Parámetros
Devuelve
OnChatWindowAdded
Parámetros
Devuelve
OnIncomingMessage
Parámetros
Devuelve