Hasli4

Untitled

Aug 31st, 2026
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local TextService = game:GetService("TextService")
  4.  
  5.  
  6. --------------------------------------------------
  7. -- RemoteEvents
  8. --------------------------------------------------
  9.  
  10. local submitPlayerName = ReplicatedStorage:WaitForChild("SubmitPlayerName")
  11. local showDialogResponse = ReplicatedStorage:WaitForChild("ShowDialogResponse")
  12.  
  13.  
  14. --------------------------------------------------
  15. -- Имена игроков
  16. --
  17. -- UserId -> имя персонажа
  18. --------------------------------------------------
  19.  
  20. local playerNames = {}
  21.  
  22.  
  23. --------------------------------------------------
  24. -- Проверка запуска
  25. --------------------------------------------------
  26.  
  27. print("[DIALOG SERVER] DialogServer запустился")
  28. print("[DIALOG SERVER] SubmitPlayerName найден")
  29. print("[DIALOG SERVER] ShowDialogResponse найден")
  30.  
  31.  
  32. --------------------------------------------------
  33. -- Получение имени
  34. --------------------------------------------------
  35.  
  36. submitPlayerName.OnServerEvent:Connect(function(player, rawName)
  37.  
  38. print("========================================")
  39. print("[DIALOG SERVER] Получено имя от игрока:")
  40. print("[DIALOG SERVER] Игрок:", player.Name)
  41. print("[DIALOG SERVER] UserId:", player.UserId)
  42. print("[DIALOG SERVER] Имя:", rawName)
  43. print("========================================")
  44.  
  45.  
  46. --------------------------------------------------
  47. -- Проверяем тип
  48. --------------------------------------------------
  49.  
  50. if typeof(rawName) ~= "string" then
  51.  
  52. warn("[DIALOG SERVER] Имя не является строкой")
  53.  
  54. return
  55. end
  56.  
  57.  
  58. --------------------------------------------------
  59. -- Убираем пробелы
  60. --------------------------------------------------
  61.  
  62. rawName = rawName:match("^%s*(.-)%s*")
  63.  
  64.  
  65. --------------------------------------------------
  66. -- Проверяем пустоту
  67. --------------------------------------------------
  68.  
  69. if rawName == "" then
  70.  
  71. warn("[DIALOG SERVER] Игрок отправил пустое имя")
  72.  
  73. return
  74. end
  75.  
  76.  
  77. --------------------------------------------------
  78. -- Ограничиваем длину
  79. --------------------------------------------------
  80.  
  81. local length = utf8.len(rawName)
  82.  
  83. if not length then
  84.  
  85. warn("[DIALOG SERVER] Некорректный UTF-8 текст")
  86.  
  87. return
  88. end
  89.  
  90.  
  91. if length > 20 then
  92.  
  93. local cutPosition = utf8.offset(rawName, 21)
  94.  
  95. if cutPosition then
  96. rawName = string.sub(rawName, 1, cutPosition - 1)
  97. end
  98.  
  99. end
  100.  
  101.  
  102. --------------------------------------------------
  103. -- Фильтрация имени
  104. --------------------------------------------------
  105.  
  106. print("[DIALOG SERVER] Фильтруем имя...")
  107.  
  108.  
  109. local success, filterResult = pcall(function()
  110.  
  111. return TextService:FilterStringAsync(
  112. rawName,
  113. player.UserId
  114. )
  115.  
  116. end)
  117.  
  118.  
  119. if not success then
  120.  
  121. warn(
  122. "[DIALOG SERVER] Ошибка FilterStringAsync:",
  123. filterResult
  124. )
  125.  
  126. return
  127. end
  128.  
  129.  
  130. --------------------------------------------------
  131. -- Получаем фильтрованный текст
  132. --------------------------------------------------
  133.  
  134. local successFiltered, filteredName = pcall(function()
  135.  
  136. return filterResult:GetNonChatStringForUserAsync(
  137. player.UserId
  138. )
  139.  
  140. end)
  141.  
  142.  
  143. if not successFiltered then
  144.  
  145. warn(
  146. "[DIALOG SERVER] Ошибка получения filteredName:",
  147. filteredName
  148. )
  149.  
  150. return
  151. end
  152.  
  153.  
  154. if typeof(filteredName) ~= "string" then
  155.  
  156. warn("[DIALOG SERVER] filteredName не строка")
  157.  
  158. return
  159. end
  160.  
  161.  
  162. --------------------------------------------------
  163. -- Сохраняем имя
  164. --------------------------------------------------
  165.  
  166. playerNames[player.UserId] = filteredName
  167.  
  168.  
  169. print(
  170. "[DIALOG SERVER] Имя сохранено:",
  171. playerNames[player.UserId]
  172. )
  173.  
  174.  
  175. --------------------------------------------------
  176. -- Создаём реплику NPC
  177. --------------------------------------------------
  178.  
  179. local response =
  180. "Понятно, " .. filteredName .. "."
  181.  
  182.  
  183. print(
  184. "[DIALOG SERVER] Отправляем игроку:",
  185. response
  186. )
  187.  
  188.  
  189. --------------------------------------------------
  190. -- Отправляем только этому игроку
  191. --------------------------------------------------
  192.  
  193. showDialogResponse:FireClient(
  194. player,
  195. response
  196. )
  197.  
  198.  
  199. print("[DIALOG SERVER] Ответ отправлен")
  200.  
  201. end)
  202.  
  203.  
  204. --------------------------------------------------
  205. -- Удаляем данные игрока
  206. --------------------------------------------------
  207.  
  208. Players.PlayerRemoving:Connect(function(player)
  209.  
  210. playerNames[player.UserId] = nil
  211.  
  212. print(
  213. "[DIALOG SERVER] Игрок вышел:",
  214. player.Name
  215. )
  216.  
  217. end)
Advertisement
Add Comment
Please, Sign In to add comment