Hasli4

Untitled

Nov 8th, 2026
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local ServerScriptService = game:GetService("ServerScriptService")
  3.  
  4. local tool = script.Parent
  5. local punchEvent = tool:WaitForChild("PunchEvent")
  6.  
  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. local KNOCKBACK = 22
  23. local UPWARD_KNOCKBACK = 4
  24.  
  25. local lastPunch = {}
  26.  
  27. -- Находим персонажа и его Humanoid
  28. local function findHumanoid(part)
  29. local current = part
  30.  
  31. while current and current ~= workspace do
  32. if current:IsA("Model") then
  33. local humanoid = current:FindFirstChildOfClass("Humanoid")
  34.  
  35. if humanoid then
  36. return current, humanoid
  37. end
  38. end
  39.  
  40. current = current.Parent
  41. end
  42.  
  43. return nil, nil
  44. end
  45.  
  46. -- Отбрасываем цель
  47. local function knockback(attackerRoot, targetRoot)
  48.  
  49. if not targetRoot or not targetRoot:IsA("BasePart") then
  50. return
  51. end
  52.  
  53. if targetRoot.Anchored then
  54. return
  55. end
  56.  
  57. local direction = targetRoot.Position - attackerRoot.Position
  58.  
  59. -- Убираем вертикальную составляющую
  60. direction = Vector3.new(direction.X, 0, direction.Z)
  61.  
  62. if direction.Magnitude < 0.001 then
  63. direction = attackerRoot.CFrame.LookVector
  64. direction = Vector3.new(direction.X, 0, direction.Z)
  65. end
  66.  
  67. if direction.Magnitude > 0 then
  68. direction = direction.Unit
  69.  
  70. local impulse = (
  71. direction * KNOCKBACK
  72. + Vector3.new(0, UPWARD_KNOCKBACK, 0)
  73. ) * targetRoot.AssemblyMass
  74.  
  75. targetRoot:ApplyImpulse(impulse)
  76. end
  77. end
  78.  
  79. -- Основная функция удара
  80. local function punch(player)
  81.  
  82. local character = player.Character
  83.  
  84. -- Проверяем, что оружие экипировано
  85. if not character or tool.Parent ~= character then
  86. return
  87. end
  88.  
  89. local attackerHumanoid = character:FindFirstChildOfClass("Humanoid")
  90. local attackerRoot = character:FindFirstChild("HumanoidRootPart")
  91.  
  92. if not attackerHumanoid or attackerHumanoid.Health <= 0 then
  93. return
  94. end
  95.  
  96. if not attackerRoot then
  97. return
  98. end
  99.  
  100. -- Проверяем перезарядку
  101. local now = os.clock()
  102.  
  103. if lastPunch[player] and now - lastPunch[player] < COOLDOWN then
  104. return
  105. end
  106.  
  107. lastPunch[player] = now
  108.  
  109. -- Исключаем самого атакующего из поиска
  110. local overlapParams = OverlapParams.new()
  111. overlapParams.FilterType = Enum.RaycastFilterType.Exclude
  112. overlapParams.FilterDescendantsInstances = {character}
  113. overlapParams.MaxParts = 100
  114.  
  115. -- Не допускаем повторного урона одной цели за удар
  116. local alreadyHit = {}
  117.  
  118. local finishTime = os.clock() + SWING_DURATION
  119.  
  120. repeat
  121.  
  122. -- Если оружие убрали, отменяем удар
  123. if tool.Parent ~= character then
  124. break
  125. end
  126.  
  127. -- Создаём невидимую область удара перед игроком
  128. local hitboxCFrame = attackerRoot.CFrame * HITBOX_OFFSET
  129.  
  130. local parts = workspace:GetPartBoundsInBox(
  131. hitboxCFrame,
  132. HITBOX_SIZE,
  133. overlapParams
  134. )
  135.  
  136. for _, part in ipairs(parts) do
  137.  
  138. local targetModel, targetHumanoid = findHumanoid(part)
  139.  
  140. if targetHumanoid
  141. and targetHumanoid ~= attackerHumanoid
  142. and targetHumanoid.Health > 0
  143. and not alreadyHit[targetHumanoid] then
  144.  
  145. alreadyHit[targetHumanoid] = true
  146.  
  147. -- Находим корневую часть цели
  148. local targetRoot =
  149. targetModel:FindFirstChild("HumanoidRootPart")
  150. or targetModel:FindFirstChild("Torso")
  151. or targetModel.PrimaryPart
  152.  
  153. -- Записываем убийцу для таблицы лидеров
  154. KillTagger.TagHumanoid(targetHumanoid, player)
  155.  
  156. -- Наносим урон
  157. targetHumanoid:TakeDamage(DAMAGE)
  158.  
  159. -- Отбрасываем цель
  160. knockback(attackerRoot, targetRoot)
  161.  
  162. print(player.Name .. " ударил " .. targetModel.Name)
  163.  
  164. end
  165. end
  166.  
  167. task.wait(CHECK_INTERVAL)
  168.  
  169. until os.clock() >= finishTime
  170. end
  171.  
  172. -- Получаем запрос на удар
  173. punchEvent.OnServerEvent:Connect(function(player)
  174. punch(player)
  175. end)
  176.  
  177. -- Очищаем данные после выхода игрока
  178. Players.PlayerRemoving:Connect(function(player)
  179. lastPunch[player] = nil
  180. end)
Advertisement
Add Comment
Please, Sign In to add comment