Hasli4

Untitled

Nov 15th, 2026
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.81 KB | None | 0 0
  1.  
  2. local Players = game:GetService("Players")
  3. local Debris = game:GetService("Debris")
  4. local Workspace = game:GetService("Workspace")
  5.  
  6. local tool = script.Parent
  7. local punchEvent = tool:WaitForChild("PunchEvent")
  8.  
  9. --------------------------------------------------
  10. -- НАСТРОЙКИ ОРУЖИЯ
  11. --------------------------------------------------
  12.  
  13. local DAMAGE = 6
  14.  
  15. local COOLDOWN = 0.65
  16.  
  17. -- Задержка попадания после начала анимации
  18. local HIT_DELAY = 0.15
  19.  
  20. -- Продолжительность проверки попадания
  21. local HIT_WINDOW = 0.10
  22.  
  23. -- Размер области удара
  24. local HITBOX_SIZE = Vector3.new(4.5, 4.5, 4.5)
  25.  
  26. -- Положение области перед игроком
  27. local HITBOX_OFFSET = CFrame.new(0, 0, -2.5)
  28.  
  29. -- Сила отбрасывания
  30. local PUSH_SPEED = 28
  31. local UPWARD_SPEED = 8
  32.  
  33. -- Длительность Ragdoll
  34. local RAGDOLL_DURATION = 2
  35.  
  36. local lastPunch = {}
  37.  
  38. -- Состояния упавших персонажей
  39. local ragdolls = setmetatable({}, {__mode = "k"})
  40.  
  41. --------------------------------------------------
  42. -- МЕТКА УБИЙЦЫ ДЛЯ ТАБЛИЦЫ ЛИДЕРОВ
  43. --------------------------------------------------
  44.  
  45. local function tagCreator(humanoid, player)
  46.  
  47. local oldTag = humanoid:FindFirstChild("creator")
  48.  
  49. if oldTag then
  50. oldTag:Destroy()
  51. end
  52.  
  53. local tag = Instance.new("ObjectValue")
  54.  
  55. tag.Name = "creator"
  56. tag.Value = player
  57. tag.Parent = humanoid
  58.  
  59. Debris:AddItem(tag, 5)
  60. end
  61.  
  62. --------------------------------------------------
  63. -- RAGDOLL
  64. --------------------------------------------------
  65.  
  66. local function startRagdoll(character, humanoid)
  67.  
  68. local state = ragdolls[humanoid]
  69.  
  70. -- Если персонаж уже падает,
  71. -- не создаём соединения повторно
  72. if not state then
  73.  
  74. state = {
  75. version = 0,
  76.  
  77. attachments = {},
  78. motors = {},
  79. animationConstraints = {},
  80.  
  81. oldAutoRotate = humanoid.AutoRotate,
  82. oldPlatformStand = humanoid.PlatformStand,
  83. oldRequiresNeck = humanoid.RequiresNeck,
  84. oldBreakJointsOnDeath = humanoid.BreakJointsOnDeath
  85. }
  86.  
  87. ragdolls[humanoid] = state
  88.  
  89. -- Папка для физических соединений
  90. local folder = Instance.new("Folder")
  91.  
  92. folder.Name = "RagdollConstraints"
  93. folder.Parent = character
  94.  
  95. state.folder = folder
  96.  
  97. -- Сохраняем шею от случайного отключения
  98. humanoid.RequiresNeck = false
  99.  
  100. -- Сохраняем соединения даже при смерти
  101. humanoid.BreakJointsOnDeath = false
  102.  
  103. -- Отключаем управление и поворот
  104. humanoid.AutoRotate = false
  105. humanoid.PlatformStand = true
  106.  
  107. humanoid:ChangeState(
  108. Enum.HumanoidStateType.PlatformStanding
  109. )
  110.  
  111. -- Передаём управление физикой серверу
  112. local root =
  113. character:FindFirstChild("HumanoidRootPart")
  114. or character:FindFirstChild("Torso")
  115. or character.PrimaryPart
  116.  
  117. if root and not root.Anchored then
  118. pcall(function()
  119. root:SetNetworkOwner(nil)
  120. end)
  121. end
  122.  
  123. -- Останавливаем текущие анимации,
  124. -- чтобы они не мешали падению
  125. local animator = humanoid:FindFirstChildOfClass("Animator")
  126.  
  127. if animator then
  128. for _, track in ipairs(animator:GetPlayingAnimationTracks()) do
  129. track:Stop(0.05)
  130. end
  131. end
  132.  
  133. --------------------------------------------------
  134. -- НОВЫЕ СОЕДИНЕНИЯ ANIMATIONCONSTRAINT
  135. --------------------------------------------------
  136.  
  137. for _, joint in ipairs(character:GetDescendants()) do
  138.  
  139. if joint:IsA("AnimationConstraint") then
  140.  
  141. local attachment0 = joint.Attachment0
  142. local attachment1 = joint.Attachment1
  143.  
  144. local part0 = attachment0 and attachment0.Parent
  145. local part1 = attachment1 and attachment1.Parent
  146.  
  147. if attachment0 and attachment1
  148. and part0 and part1
  149. and part0:IsA("BasePart")
  150. and part1:IsA("BasePart")
  151. and part0.Name ~= "HumanoidRootPart"
  152. and part1.Name ~= "HumanoidRootPart" then
  153.  
  154. table.insert(
  155. state.animationConstraints,
  156. {
  157. joint = joint,
  158. oldValue = joint.IsKinematic
  159. }
  160. )
  161.  
  162. -- Переводим соединение в физический режим
  163. joint.IsKinematic = false
  164. end
  165. end
  166. end
  167.  
  168. --------------------------------------------------
  169. -- СТАРЫЕ СОЕДИНЕНИЯ MOTOR6D
  170. --------------------------------------------------
  171.  
  172. for _, joint in ipairs(character:GetDescendants()) do
  173.  
  174. if joint:IsA("Motor6D")
  175. and joint.Part0
  176. and joint.Part1 then
  177.  
  178. -- Не отключаем соединение с корнем персонажа
  179. local connectedToRoot =
  180. joint.Part0.Name == "HumanoidRootPart"
  181. or joint.Part1.Name == "HumanoidRootPart"
  182.  
  183. if not connectedToRoot then
  184.  
  185. -- Создаём точки соединения
  186. local attachment0 = Instance.new("Attachment")
  187. attachment0.CFrame = joint.C0
  188. attachment0.Parent = joint.Part0
  189.  
  190. local attachment1 = Instance.new("Attachment")
  191. attachment1.CFrame = joint.C1
  192. attachment1.Parent = joint.Part1
  193.  
  194. -- Создаём физический сустав
  195. local socket = Instance.new("BallSocketConstraint")
  196.  
  197. socket.Attachment0 = attachment0
  198. socket.Attachment1 = attachment1
  199.  
  200. socket.LimitsEnabled = true
  201.  
  202. if joint.Name == "Neck" then
  203. socket.UpperAngle = 25
  204. else
  205. socket.UpperAngle = 50
  206. end
  207.  
  208. socket.TwistLimitsEnabled = true
  209. socket.TwistLowerAngle = -35
  210. socket.TwistUpperAngle = 35
  211.  
  212. socket.Parent = folder
  213.  
  214. table.insert(state.attachments, attachment0)
  215. table.insert(state.attachments, attachment1)
  216.  
  217. -- Запоминаем исходное состояние Motor6D
  218. table.insert(
  219. state.motors,
  220. {
  221. joint = joint,
  222. oldValue = joint.Enabled
  223. }
  224. )
  225.  
  226. -- Отключаем обычное движение сустава
  227. joint.Enabled = false
  228. end
  229. end
  230. end
  231.  
  232. -- Если персонаж погиб, оставляем его в ragdoll
  233. humanoid.Died:Connect(function()
  234.  
  235. if ragdolls[humanoid] == state then
  236. ragdolls[humanoid] = nil
  237. end
  238.  
  239. end)
  240. end
  241.  
  242. --------------------------------------------------
  243. -- ОБНОВЛЯЕМ ВРЕМЯ ПАДЕНИЯ
  244. --------------------------------------------------
  245.  
  246. state.version += 1
  247.  
  248. local currentVersion = state.version
  249.  
  250. task.delay(RAGDOLL_DURATION, function()
  251.  
  252. -- Проверяем, не продлён ли Ragdoll новым ударом
  253. if ragdolls[humanoid] ~= state then
  254. return
  255. end
  256.  
  257. if state.version ~= currentVersion then
  258. return
  259. end
  260.  
  261. -- Погибших персонажей не поднимаем
  262. if not humanoid.Parent or humanoid.Health <= 0 then
  263. ragdolls[humanoid] = nil
  264. return
  265. end
  266.  
  267. --------------------------------------------------
  268. -- ВОССТАНАВЛИВАЕМ СОЕДИНЕНИЯ
  269. --------------------------------------------------
  270.  
  271. if state.folder and state.folder.Parent then
  272. state.folder:Destroy()
  273. end
  274.  
  275. -- Удаляем временные Attachment
  276. for _, attachment in ipairs(state.attachments) do
  277.  
  278. if attachment.Parent then
  279. attachment:Destroy()
  280. end
  281.  
  282. end
  283.  
  284. -- Восстанавливаем Motor6D
  285. for _, data in ipairs(state.motors) do
  286.  
  287. if data.joint.Parent then
  288. data.joint.Enabled = data.oldValue
  289. end
  290.  
  291. end
  292.  
  293. -- Восстанавливаем AnimationConstraint
  294. for _, data in ipairs(state.animationConstraints) do
  295.  
  296. if data.joint.Parent then
  297. data.joint.IsKinematic = data.oldValue
  298. end
  299.  
  300. end
  301.  
  302. --------------------------------------------------
  303. -- ВОЗВРАЩАЕМ УПРАВЛЕНИЕ
  304. --------------------------------------------------
  305.  
  306. humanoid.RequiresNeck = state.oldRequiresNeck
  307. humanoid.BreakJointsOnDeath = state.oldBreakJointsOnDeath
  308. humanoid.AutoRotate = state.oldAutoRotate
  309. humanoid.PlatformStand = state.oldPlatformStand
  310.  
  311. if not state.oldPlatformStand then
  312. humanoid:ChangeState(
  313. Enum.HumanoidStateType.GettingUp
  314. )
  315. end
  316.  
  317. -- Возвращаем автоматическое управление физикой
  318. local root =
  319. humanoid.Parent:FindFirstChild("HumanoidRootPart")
  320. or humanoid.Parent:FindFirstChild("Torso")
  321.  
  322. if root and not root.Anchored then
  323. pcall(function()
  324. root:SetNetworkOwnershipAuto()
  325. end)
  326. end
  327.  
  328. ragdolls[humanoid] = nil
  329.  
  330. end)
  331. end
  332.  
  333. --------------------------------------------------
  334. -- ОТБРАСЫВАНИЕ ПРОТИВНИКА
  335. --------------------------------------------------
  336.  
  337. local function knockback(attackerRoot, targetRoot, targetModel, targetHumanoid)
  338.  
  339. if not targetRoot or targetRoot.Anchored then
  340. return
  341. end
  342.  
  343. -- Сначала переводим противника в Ragdoll
  344. startRagdoll(targetModel, targetHumanoid)
  345.  
  346. -- Определяем направление отбрасывания
  347. local direction = targetRoot.Position - attackerRoot.Position
  348.  
  349. -- Убираем вертикальное направление
  350. direction = Vector3.new(direction.X, 0, direction.Z)
  351.  
  352. if direction.Magnitude < 0.001 then
  353.  
  354. local look = attackerRoot.CFrame.LookVector
  355.  
  356. direction = Vector3.new(look.X, 0, look.Z)
  357.  
  358. end
  359.  
  360. if direction.Magnitude < 0.001 then
  361. return
  362. end
  363.  
  364. direction = direction.Unit
  365.  
  366. -- Создаём физический импульс
  367. local mass = targetRoot.AssemblyMass
  368.  
  369. if mass <= 0 or mass >= math.huge then
  370. return
  371. end
  372.  
  373. local impulse = (
  374. direction * PUSH_SPEED
  375. + Vector3.new(0, UPWARD_SPEED, 0)
  376. ) * mass
  377.  
  378. targetRoot:ApplyImpulse(impulse)
  379. end
  380.  
  381. --------------------------------------------------
  382. -- ПОИСК HUMANOID
  383. --------------------------------------------------
  384.  
  385. local function findHumanoid(part)
  386.  
  387. local current = part
  388.  
  389. while current and current ~= Workspace do
  390.  
  391. if current:IsA("Model") then
  392.  
  393. local humanoid =
  394. current:FindFirstChildOfClass("Humanoid")
  395.  
  396. if humanoid then
  397. return current, humanoid
  398. end
  399. end
  400.  
  401. current = current.Parent
  402. end
  403.  
  404. return nil, nil
  405. end
  406.  
  407. --------------------------------------------------
  408. -- ПОИСК И АТАКА ЦЕЛЕЙ
  409. --------------------------------------------------
  410.  
  411. local function performHit(player, character, attackerHumanoid, attackerRoot)
  412.  
  413. -- Исключаем самого атакующего
  414. local overlapParams = OverlapParams.new()
  415.  
  416. overlapParams.FilterType = Enum.RaycastFilterType.Exclude
  417. overlapParams.FilterDescendantsInstances = {character}
  418. overlapParams.MaxParts = 100
  419.  
  420. -- Одна цель не может получить повторный урон
  421. -- от одного и того же удара
  422. local alreadyHit = {}
  423.  
  424. local finishTime = os.clock() + HIT_WINDOW
  425.  
  426. repeat
  427.  
  428. if tool.Parent ~= character then
  429. break
  430. end
  431.  
  432. local hitboxCFrame =
  433. attackerRoot.CFrame * HITBOX_OFFSET
  434.  
  435. local parts = Workspace:GetPartBoundsInBox(
  436. hitboxCFrame,
  437. HITBOX_SIZE,
  438. overlapParams
  439. )
  440.  
  441. for _, part in ipairs(parts) do
  442.  
  443. local targetModel, targetHumanoid = findHumanoid(part)
  444.  
  445. if targetHumanoid
  446. and targetHumanoid ~= attackerHumanoid
  447. and targetHumanoid.Health > 0
  448. and not alreadyHit[targetHumanoid] then
  449.  
  450. -- Не бьём персонажей под защитой ForceField
  451. if not targetModel:FindFirstChildOfClass("ForceField") then
  452.  
  453. alreadyHit[targetHumanoid] = true
  454.  
  455. -- Ищем корневую часть противника
  456. local targetRoot =
  457. targetModel:FindFirstChild("HumanoidRootPart")
  458. or targetModel:FindFirstChild("Torso")
  459. or targetModel.PrimaryPart
  460.  
  461. -- Записываем убийцу
  462. tagCreator(targetHumanoid, player)
  463.  
  464. -- Удар и Ragdoll
  465. if targetRoot and not targetRoot.Anchored then
  466.  
  467. knockback(
  468. attackerRoot,
  469. targetRoot,
  470. targetModel,
  471. targetHumanoid
  472. )
  473.  
  474. end
  475.  
  476. -- Наносим урон
  477. targetHumanoid:TakeDamage(DAMAGE)
  478.  
  479. print(
  480. player.Name ..
  481. " ударил " ..
  482. targetModel.Name ..
  483. " | Урон: " ..
  484. DAMAGE
  485. )
  486. end
  487. end
  488. end
  489.  
  490. task.wait(0.04)
  491.  
  492. until os.clock() >= finishTime
  493.  
  494. end
  495.  
  496. --------------------------------------------------
  497. -- ПОЛУЧЕНИЕ ЗАПРОСА НА УДАР
  498. --------------------------------------------------
  499.  
  500. punchEvent.OnServerEvent:Connect(function(player)
  501.  
  502. local character = player.Character
  503.  
  504. -- Проверяем, что оружие действительно экипировано
  505. if not character or tool.Parent ~= character then
  506. return
  507. end
  508.  
  509. local humanoid = character:FindFirstChildOfClass("Humanoid")
  510.  
  511. local root = character:FindFirstChild("HumanoidRootPart")
  512.  
  513. if not humanoid or humanoid.Health <= 0 or not root then
  514. return
  515. end
  516.  
  517. -- Нельзя атаковать, пока сам игрок лежит
  518. if humanoid.PlatformStand then
  519. return
  520. end
  521.  
  522. -- Проверка перезарядки на сервере
  523. local now = os.clock()
  524.  
  525. if lastPunch[player]
  526. and now - lastPunch[player] < COOLDOWN then
  527. return
  528. end
  529.  
  530. lastPunch[player] = now
  531.  
  532. -- Ждём момент удара в анимации
  533. task.delay(HIT_DELAY, function()
  534.  
  535. -- Повторно проверяем состояние игрока
  536. if player.Character ~= character
  537. or tool.Parent ~= character
  538. or humanoid.Health <= 0 then
  539. return
  540. end
  541.  
  542. if not root.Parent then
  543. return
  544. end
  545.  
  546. performHit(
  547. player,
  548. character,
  549. humanoid,
  550. root
  551. )
  552.  
  553. end)
  554.  
  555. end)
  556.  
  557. --------------------------------------------------
  558. -- ОЧИСТКА
  559. --------------------------------------------------
  560.  
  561. Players.PlayerRemoving:Connect(function(player)
  562. lastPunch[player] = nil
  563. end)
  564.  
Advertisement
Add Comment
Please, Sign In to add comment