Hasli4

Untitled

Nov 8th, 2026
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.17 KB | None | 0 0
  1.  
  2. local Players = game:GetService("Players")
  3. local ServerScriptService = game:GetService("ServerScriptService")
  4.  
  5. local tool = script.Parent
  6. local punchEvent = tool:WaitForChild("PunchEvent")
  7.  
  8. local KillTagger = require(
  9. ServerScriptService:WaitForChild("KillTagger")
  10. )
  11.  
  12. -- НАСТРОЙКИ
  13. local DAMAGE = 6
  14. local COOLDOWN = 0.65
  15.  
  16. local HITBOX_SIZE = Vector3.new(4.2, 4, 4.5)
  17. local HITBOX_OFFSET = CFrame.new(0, 0, -2.3)
  18.  
  19. local SWING_DURATION = 0.15
  20. local CHECK_INTERVAL = 0.04
  21.  
  22. -- Отбрасывание
  23. local KNOCKBACK = 38
  24. local UPWARD_KNOCKBACK = 22
  25.  
  26. -- Время падения
  27. local RAGDOLL_DURATION = 2
  28.  
  29. local lastPunch = {}
  30. local ragdollStates = {}
  31.  
  32. --------------------------------------------------
  33. -- RAGDOLL: ПАДЕНИЕ И ПОТЕРЯ УПРАВЛЕНИЯ
  34. --------------------------------------------------
  35.  
  36. local function startRagdoll(character, humanoid)
  37.  
  38. local state = ragdollStates[humanoid]
  39.  
  40. -- Если персонаж уже падает, продлеваем эффект
  41. if state then
  42. state.version += 1
  43. else
  44.  
  45. state = {
  46. version = 0,
  47. attachments = {},
  48. constraints = {},
  49. motors = {},
  50. animations = {},
  51.  
  52. oldRequiresNeck = humanoid.RequiresNeck,
  53. oldPlatformStand = humanoid.PlatformStand,
  54. oldAutoRotate = humanoid.AutoRotate,
  55. }
  56.  
  57. ragdollStates[humanoid] = state
  58.  
  59. local folder = Instance.new("Folder")
  60. folder.Name = "KnockbackRagdoll"
  61. folder.Parent = character
  62.  
  63. state.folder = folder
  64.  
  65. -- Отключаем смерть при временном отсоединении шеи
  66. humanoid.RequiresNeck = false
  67.  
  68. humanoid.AutoRotate = false
  69. humanoid.PlatformStand = true
  70.  
  71. -- Сервер управляет физикой персонажа
  72. local root = character:FindFirstChild("HumanoidRootPart")
  73.  
  74. if root then
  75. pcall(function()
  76. root:SetNetworkOwner(nil)
  77. end)
  78. end
  79.  
  80. -- Поддержка новых R15 AnimationConstraint
  81. for _, joint in ipairs(character:GetDescendants()) do
  82.  
  83. if joint:IsA("AnimationConstraint") then
  84.  
  85. local a0 = joint.Attachment0
  86. local a1 = joint.Attachment1
  87.  
  88. local part0 = a0 and a0.Parent
  89. local part1 = a1 and a1.Parent
  90.  
  91. -- Не отключаем соединение с HumanoidRootPart
  92. if part0 and part1
  93. and part0.Name ~= "HumanoidRootPart"
  94. and part1.Name ~= "HumanoidRootPart" then
  95.  
  96. table.insert(state.animations, {
  97. joint = joint,
  98. oldValue = joint.IsKinematic
  99. })
  100.  
  101. -- Включаем физическое поведение соединения
  102. joint.IsKinematic = false
  103. end
  104. end
  105. end
  106.  
  107. -- Поддержка старых R6 / R15 Motor6D
  108. for _, joint in ipairs(character:GetDescendants()) do
  109.  
  110. if joint:IsA("Motor6D")
  111. and joint.Part0
  112. and joint.Part1 then
  113.  
  114. if joint.Part0.Name ~= "HumanoidRootPart"
  115. and joint.Part1.Name ~= "HumanoidRootPart" then
  116.  
  117. local attachment0 = Instance.new("Attachment")
  118. attachment0.CFrame = joint.C0
  119. attachment0.Parent = joint.Part0
  120.  
  121. local attachment1 = Instance.new("Attachment")
  122. attachment1.CFrame = joint.C1
  123. attachment1.Parent = joint.Part1
  124.  
  125. local socket = Instance.new("BallSocketConstraint")
  126. socket.Attachment0 = attachment0
  127. socket.Attachment1 = attachment1
  128.  
  129. socket.LimitsEnabled = true
  130. socket.UpperAngle = 45
  131.  
  132. socket.TwistLimitsEnabled = true
  133. socket.TwistLowerAngle = -45
  134. socket.TwistUpperAngle = 45
  135.  
  136. socket.Parent = folder
  137.  
  138. table.insert(state.attachments, attachment0)
  139. table.insert(state.attachments, attachment1)
  140. table.insert(state.constraints, socket)
  141.  
  142. table.insert(state.motors, {
  143. joint = joint,
  144. oldValue = joint.Enabled
  145. })
  146.  
  147. joint.Enabled = false
  148. end
  149. end
  150. end
  151. end
  152.  
  153. -- Каждый новый удар продлевает падение
  154. local currentVersion = state.version
  155.  
  156. task.delay(RAGDOLL_DURATION, function()
  157.  
  158. if ragdollStates[humanoid] ~= state then
  159. return
  160. end
  161.  
  162. if state.version ~= currentVersion then
  163. return
  164. end
  165.  
  166. -- Удаляем физические соединения
  167. if state.folder and state.folder.Parent then
  168. state.folder:Destroy()
  169. end
  170.  
  171. for _, attachment in ipairs(state.attachments) do
  172. if attachment.Parent then
  173. attachment:Destroy()
  174. end
  175. end
  176.  
  177. -- Восстанавливаем старые Motor6D
  178. for _, data in ipairs(state.motors) do
  179. if data.joint.Parent then
  180. data.joint.Enabled = data.oldValue
  181. end
  182. end
  183.  
  184. -- Восстанавливаем AnimationConstraint
  185. for _, data in ipairs(state.animations) do
  186. if data.joint.Parent then
  187. data.joint.IsKinematic = data.oldValue
  188. end
  189. end
  190.  
  191. -- Возвращаем управление
  192. if humanoid.Parent and humanoid.Health > 0 then
  193.  
  194. humanoid.RequiresNeck = state.oldRequiresNeck
  195. humanoid.AutoRotate = state.oldAutoRotate
  196. humanoid.PlatformStand = state.oldPlatformStand
  197.  
  198. if not state.oldPlatformStand then
  199. humanoid:ChangeState(
  200. Enum.HumanoidStateType.GettingUp
  201. )
  202. end
  203.  
  204. local root = humanoid.Parent:FindFirstChild("HumanoidRootPart")
  205.  
  206. if root then
  207. pcall(function()
  208. root:SetNetworkOwnershipAuto()
  209. end)
  210. end
  211. end
  212.  
  213. ragdollStates[humanoid] = nil
  214. end)
  215. end
  216.  
  217. --------------------------------------------------
  218. -- ОТБРАСЫВАНИЕ
  219. --------------------------------------------------
  220.  
  221. local function knockback(attackerRoot, targetRoot, targetModel, targetHumanoid)
  222.  
  223. if not targetRoot or targetRoot.Anchored then
  224. return
  225. end
  226.  
  227. -- Сначала переводим персонажа в состояние падения
  228. startRagdoll(targetModel, targetHumanoid)
  229.  
  230. local direction = targetRoot.Position - attackerRoot.Position
  231.  
  232. direction = Vector3.new(direction.X, 0, direction.Z)
  233.  
  234. if direction.Magnitude < 0.001 then
  235. direction = attackerRoot.CFrame.LookVector
  236. direction = Vector3.new(direction.X, 0, direction.Z)
  237. end
  238.  
  239. direction = direction.Unit
  240.  
  241. -- Создаём физический импульс
  242. local velocity = (
  243. direction * KNOCKBACK
  244. + Vector3.new(0, UPWARD_KNOCKBACK, 0)
  245. )
  246.  
  247. local impulse = velocity * targetRoot.AssemblyMass
  248.  
  249. targetRoot:ApplyImpulse(impulse)
  250. end
  251.  
  252. --------------------------------------------------
  253. -- ПОИСК ПЕРСОНАЖЕЙ
  254. --------------------------------------------------
  255.  
  256. local function findHumanoid(part)
  257.  
  258. local current = part
  259.  
  260. while current and current ~= workspace do
  261.  
  262. if current:IsA("Model") then
  263.  
  264. local humanoid = current:FindFirstChildOfClass("Humanoid")
  265.  
  266. if humanoid then
  267. return current, humanoid
  268. end
  269. end
  270.  
  271. current = current.Parent
  272. end
  273.  
  274. return nil, nil
  275. end
  276.  
  277. --------------------------------------------------
  278. -- АТАКА
  279. --------------------------------------------------
  280.  
  281. local function punch(player)
  282.  
  283. local character = player.Character
  284.  
  285. if not character or tool.Parent ~= character then
  286. return
  287. end
  288.  
  289. local attackerHumanoid = character:FindFirstChildOfClass("Humanoid")
  290. local attackerRoot = character:FindFirstChild("HumanoidRootPart")
  291.  
  292. if not attackerHumanoid
  293. or attackerHumanoid.Health <= 0
  294. or not attackerRoot then
  295. return
  296. end
  297.  
  298. -- Перезарядка
  299. local now = os.clock()
  300.  
  301. if lastPunch[player] and now - lastPunch[player] < COOLDOWN then
  302. return
  303. end
  304.  
  305. lastPunch[player] = now
  306.  
  307. local overlapParams = OverlapParams.new()
  308.  
  309. overlapParams.FilterType = Enum.RaycastFilterType.Exclude
  310. overlapParams.FilterDescendantsInstances = {character}
  311. overlapParams.MaxParts = 100
  312.  
  313. local alreadyHit = {}
  314.  
  315. local finishTime = os.clock() + SWING_DURATION
  316.  
  317. repeat
  318.  
  319. if tool.Parent ~= character then
  320. break
  321. end
  322.  
  323. local hitboxCFrame = attackerRoot.CFrame * HITBOX_OFFSET
  324.  
  325. local parts = workspace:GetPartBoundsInBox(
  326. hitboxCFrame,
  327. HITBOX_SIZE,
  328. overlapParams
  329. )
  330.  
  331. for _, part in ipairs(parts) do
  332.  
  333. local targetModel, targetHumanoid = findHumanoid(part)
  334.  
  335. if targetHumanoid
  336. and targetHumanoid ~= attackerHumanoid
  337. and targetHumanoid.Health > 0
  338. and not alreadyHit[targetHumanoid] then
  339.  
  340. alreadyHit[targetHumanoid] = true
  341.  
  342. local targetRoot =
  343. targetModel:FindFirstChild("HumanoidRootPart")
  344. or targetModel:FindFirstChild("Torso")
  345. or targetModel.PrimaryPart
  346.  
  347. if targetRoot then
  348.  
  349. -- Регистрируем убийцу
  350. KillTagger.TagHumanoid(targetHumanoid, player)
  351.  
  352. -- Отбрасываем и роняем противника
  353. knockback(
  354. attackerRoot,
  355. targetRoot,
  356. targetModel,
  357. targetHumanoid
  358. )
  359.  
  360. -- Наносим урон
  361. targetHumanoid:TakeDamage(DAMAGE)
  362.  
  363. print(
  364. player.Name ..
  365. " ударил " ..
  366. targetModel.Name
  367. )
  368. end
  369. end
  370. end
  371.  
  372. task.wait(CHECK_INTERVAL)
  373.  
  374. until os.clock() >= finishTime
  375. end
  376.  
  377. --------------------------------------------------
  378. -- ПОЛУЧЕНИЕ ЗАПРОСА ОТ ИГРОКА
  379. --------------------------------------------------
  380.  
  381. punchEvent.OnServerEvent:Connect(function(player)
  382. punch(player)
  383. end)
  384.  
  385. Players.PlayerRemoving:Connect(function(player)
  386. lastPunch[player] = nil
  387. end)
  388.  
Advertisement
Add Comment
Please, Sign In to add comment