Text Chat Service
*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
Chat Version
Métodos
Can User Chat Async
Can Users Chat Async
Can Users Direct Chat Async
Devuelve
Muestras de código
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
-- Reemplace con los UserIds de los dos usuarios
local userId1 = 1
local userId2 = 2
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Verifique 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 el TextChannel. No hay suficientes usuarios elegibles.")
return nilDisplay Bubble
Get Chat Groups Async
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 del servidor a nivel de universo simulado.
En la práctica, estos datos podrían almacenarse y actualizarse utilizando MemoryStore
u otro sistema de backend.
Ejemplo de forma:
ActiveServers = {
{
serverId = "abc",
privateServerId = game.PrivateServerId,
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
privateServerId = game.PrivateServerId,
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("Error al recuperar grupos de chat para el jugador:", player.UserId)
return
end
-- Recopilar 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()
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ReservedServerId = bestServer.privateServerId
TeleportService:TeleportAsync(
TARGET_PLACE_ID,
{ player },
teleportOptions
)
end)
if not ok then
warn("El teletransporte falló:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Obtener Grupos de Chat Asíncronos
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local players = Players:GetPlayers()
local success, chatGroups = pcall(function()
return TextChatService:GetChatGroupsAsync(players)
end)
if not success then
warn("Error al recuperar los grupos de chat")
return
end
for _, group in ipairs(chatGroups) do
-- Cada grupo contiene cadenas de ID de grupo de chat.
-- Los jugadores que comparten un ID de grupo coincidente pueden chatear entre sí.
for _, groupId in ipairs(group) do
print("ID del grupo de chat:", groupId)
end
endEventos
Bubble Displayed
Text Chat Service. Bubble Displayed(
Parámetros
Message Received
Parámetros
Sending Message
Parámetros
Llamadas
On Bubble Added
Parámetros
Devuelve
On Chat Window Added
Parámetros
Devuelve
On Incoming Message
Parámetros
Devuelve