Classe motore
TextChatService
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
Metodi
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} |
Eventi
BubbleDisplayed(partOrCharacter: Instance,textChatMessage: TextChatMessage):RBXScriptSignal |
MessageReceived(textChatMessage: TextChatMessage):RBXScriptSignal |
SendingMessage(textChatMessage: TextChatMessage):RBXScriptSignal |
Richiami
OnBubbleAdded(message: TextChatMessage,adornee: Instance):Tuple |
OnChatWindowAdded(message: TextChatMessage):Tuple |
OnIncomingMessage(message: TextChatMessage):Tuple |
Riferimento API
Proprietà
ChatVersion
Metodi
CanUserChatAsync
CanUsersChatAsync
CanUsersDirectChatAsync
Restituzioni
Campioni di codice
CanUsersDirectChatAsync
local TextChatService = game:GetService("TextChatService")
local directChatParticipants = TextChatService:CanUsersDirectChatAsync(userId1, { userId2 })
-- Verifica i partecipanti idonei
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("Impossibile creare TextChannel. Non ci sono utenti idonei sufficienti.")
return nilDisplayBubble
GetChatGroupsAsync
Parametri
players:Instances |
Restituzioni
Campioni di codice
TeletrasportaGiocatoreAlMigliorServerChat
-- Script del server
local TextChatService = game:GetService("TextChatService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local TARGET_PLACE_ID = 1234567890 -- ID del posto di destinazione
--[[
Stato del server universale stub.
In pratica, questi dati potrebbero essere memorizzati e aggiornati utilizzando MemoryStore
o un altro sistema backend.
Forma esempio:
ActiveServers = {
{
serverId = "abc",
accessCode = "codice-server-riservato",
groupUserCounts = {
groupA = 12,
groupB = 5
}
},
{
serverId = "def",
accessCode = "codice-server-riservato",
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("Impossibile recuperare i gruppi chat per il giocatore:", player.UserId)
return
end
-- Raccogli tutti gli ID dei gruppi chat ai quali il giocatore è idoneo
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
-- Scegli il server con il numero maggiore di utenti compatibili
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("Nessun server adatto trovato per il giocatore:", player.UserId)
return
end
local ok, err = pcall(function()
TeleportService:TeleportToPrivateServer(
TARGET_PLACE_ID,
bestServer.accessCode,
{ player }
)
end)
if not ok then
warn("Teleport fallito:", err)
end
end
Players.PlayerAdded:Connect(teleportPlayerToBestServer)Eventi
BubbleDisplayed
TextChatService.BubbleDisplayed(
Parametri
MessageReceived
Parametri
SendingMessage
Parametri
Richiami
OnBubbleAdded
Parametri
Restituzioni
OnChatWindowAdded
Parametri
Restituzioni
OnIncomingMessage
Parametri
Restituzioni