Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ServerScriptService = game:GetService("ServerScriptService")
- local tool = script.Parent
- local punchEvent = tool:WaitForChild("PunchEvent")
- -- Подключаем систему определения убийцы
- local KillTagger = require(
- ServerScriptService:WaitForChild("KillTagger")
- )
- -- НАСТРОЙКИ ОРУЖИЯ
- local DAMAGE = 6
- local COOLDOWN = 0.65
- local HITBOX_SIZE = Vector3.new(4.2, 4, 4.5)
- local HITBOX_OFFSET = CFrame.new(0, 0, -2.3)
- local SWING_DURATION = 0.15
- local CHECK_INTERVAL = 0.04
- local KNOCKBACK = 22
- local UPWARD_KNOCKBACK = 4
- local lastPunch = {}
- -- Находим персонажа и его Humanoid
- local function findHumanoid(part)
- local current = part
- while current and current ~= workspace do
- if current:IsA("Model") then
- local humanoid = current:FindFirstChildOfClass("Humanoid")
- if humanoid then
- return current, humanoid
- end
- end
- current = current.Parent
- end
- return nil, nil
- end
- -- Отбрасываем цель
- local function knockback(attackerRoot, targetRoot)
- if not targetRoot or not targetRoot:IsA("BasePart") then
- return
- end
- if targetRoot.Anchored then
- return
- end
- local direction = targetRoot.Position - attackerRoot.Position
- -- Убираем вертикальную составляющую
- direction = Vector3.new(direction.X, 0, direction.Z)
- if direction.Magnitude < 0.001 then
- direction = attackerRoot.CFrame.LookVector
- direction = Vector3.new(direction.X, 0, direction.Z)
- end
- if direction.Magnitude > 0 then
- direction = direction.Unit
- local impulse = (
- direction * KNOCKBACK
- + Vector3.new(0, UPWARD_KNOCKBACK, 0)
- ) * targetRoot.AssemblyMass
- targetRoot:ApplyImpulse(impulse)
- end
- end
- -- Основная функция удара
- local function punch(player)
- local character = player.Character
- -- Проверяем, что оружие экипировано
- if not character or tool.Parent ~= character then
- return
- end
- local attackerHumanoid = character:FindFirstChildOfClass("Humanoid")
- local attackerRoot = character:FindFirstChild("HumanoidRootPart")
- if not attackerHumanoid or attackerHumanoid.Health <= 0 then
- return
- end
- if not attackerRoot then
- return
- end
- -- Проверяем перезарядку
- local now = os.clock()
- if lastPunch[player] and now - lastPunch[player] < COOLDOWN then
- return
- end
- lastPunch[player] = now
- -- Исключаем самого атакующего из поиска
- local overlapParams = OverlapParams.new()
- overlapParams.FilterType = Enum.RaycastFilterType.Exclude
- overlapParams.FilterDescendantsInstances = {character}
- overlapParams.MaxParts = 100
- -- Не допускаем повторного урона одной цели за удар
- local alreadyHit = {}
- local finishTime = os.clock() + SWING_DURATION
- repeat
- -- Если оружие убрали, отменяем удар
- if tool.Parent ~= character then
- break
- end
- -- Создаём невидимую область удара перед игроком
- local hitboxCFrame = attackerRoot.CFrame * HITBOX_OFFSET
- local parts = workspace:GetPartBoundsInBox(
- hitboxCFrame,
- HITBOX_SIZE,
- overlapParams
- )
- for _, part in ipairs(parts) do
- local targetModel, targetHumanoid = findHumanoid(part)
- if targetHumanoid
- and targetHumanoid ~= attackerHumanoid
- and targetHumanoid.Health > 0
- and not alreadyHit[targetHumanoid] then
- alreadyHit[targetHumanoid] = true
- -- Находим корневую часть цели
- local targetRoot =
- targetModel:FindFirstChild("HumanoidRootPart")
- or targetModel:FindFirstChild("Torso")
- or targetModel.PrimaryPart
- -- Записываем убийцу для таблицы лидеров
- KillTagger.TagHumanoid(targetHumanoid, player)
- -- Наносим урон
- targetHumanoid:TakeDamage(DAMAGE)
- -- Отбрасываем цель
- knockback(attackerRoot, targetRoot)
- print(player.Name .. " ударил " .. targetModel.Name)
- end
- end
- task.wait(CHECK_INTERVAL)
- until os.clock() >= finishTime
- end
- -- Получаем запрос на удар
- punchEvent.OnServerEvent:Connect(function(player)
- punch(player)
- end)
- -- Очищаем данные после выхода игрока
- Players.PlayerRemoving:Connect(function(player)
- lastPunch[player] = nil
- end)
Advertisement
Add Comment
Please, Sign In to add comment