Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local TextService = game:GetService("TextService")
- --------------------------------------------------
- -- RemoteEvents
- --------------------------------------------------
- local submitPlayerName = ReplicatedStorage:WaitForChild("SubmitPlayerName")
- local showDialogResponse = ReplicatedStorage:WaitForChild("ShowDialogResponse")
- --------------------------------------------------
- -- Имена игроков
- --
- -- UserId -> имя персонажа
- --------------------------------------------------
- local playerNames = {}
- --------------------------------------------------
- -- Проверка запуска
- --------------------------------------------------
- print("[DIALOG SERVER] DialogServer запустился")
- print("[DIALOG SERVER] SubmitPlayerName найден")
- print("[DIALOG SERVER] ShowDialogResponse найден")
- --------------------------------------------------
- -- Получение имени
- --------------------------------------------------
- submitPlayerName.OnServerEvent:Connect(function(player, rawName)
- print("========================================")
- print("[DIALOG SERVER] Получено имя от игрока:")
- print("[DIALOG SERVER] Игрок:", player.Name)
- print("[DIALOG SERVER] UserId:", player.UserId)
- print("[DIALOG SERVER] Имя:", rawName)
- print("========================================")
- --------------------------------------------------
- -- Проверяем тип
- --------------------------------------------------
- if typeof(rawName) ~= "string" then
- warn("[DIALOG SERVER] Имя не является строкой")
- return
- end
- --------------------------------------------------
- -- Убираем пробелы
- --------------------------------------------------
- rawName = rawName:match("^%s*(.-)%s*")
- --------------------------------------------------
- -- Проверяем пустоту
- --------------------------------------------------
- if rawName == "" then
- warn("[DIALOG SERVER] Игрок отправил пустое имя")
- return
- end
- --------------------------------------------------
- -- Ограничиваем длину
- --------------------------------------------------
- local length = utf8.len(rawName)
- if not length then
- warn("[DIALOG SERVER] Некорректный UTF-8 текст")
- return
- end
- if length > 20 then
- local cutPosition = utf8.offset(rawName, 21)
- if cutPosition then
- rawName = string.sub(rawName, 1, cutPosition - 1)
- end
- end
- --------------------------------------------------
- -- Фильтрация имени
- --------------------------------------------------
- print("[DIALOG SERVER] Фильтруем имя...")
- local success, filterResult = pcall(function()
- return TextService:FilterStringAsync(
- rawName,
- player.UserId
- )
- end)
- if not success then
- warn(
- "[DIALOG SERVER] Ошибка FilterStringAsync:",
- filterResult
- )
- return
- end
- --------------------------------------------------
- -- Получаем фильтрованный текст
- --------------------------------------------------
- local successFiltered, filteredName = pcall(function()
- return filterResult:GetNonChatStringForUserAsync(
- player.UserId
- )
- end)
- if not successFiltered then
- warn(
- "[DIALOG SERVER] Ошибка получения filteredName:",
- filteredName
- )
- return
- end
- if typeof(filteredName) ~= "string" then
- warn("[DIALOG SERVER] filteredName не строка")
- return
- end
- --------------------------------------------------
- -- Сохраняем имя
- --------------------------------------------------
- playerNames[player.UserId] = filteredName
- print(
- "[DIALOG SERVER] Имя сохранено:",
- playerNames[player.UserId]
- )
- --------------------------------------------------
- -- Создаём реплику NPC
- --------------------------------------------------
- local response =
- "Понятно, " .. filteredName .. "."
- print(
- "[DIALOG SERVER] Отправляем игроку:",
- response
- )
- --------------------------------------------------
- -- Отправляем только этому игроку
- --------------------------------------------------
- showDialogResponse:FireClient(
- player,
- response
- )
- print("[DIALOG SERVER] Ответ отправлен")
- end)
- --------------------------------------------------
- -- Удаляем данные игрока
- --------------------------------------------------
- Players.PlayerRemoving:Connect(function(player)
- playerNames[player.UserId] = nil
- print(
- "[DIALOG SERVER] Игрок вышел:",
- player.Name
- )
- end)
Advertisement
Add Comment
Please, Sign In to add comment