Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local plr = game.Players.LocalPlayer
- local char = plr.Character
- local remote = game.ReplicatedStorage.Remotes.Combat.CombatEvent
- local attributeRemote = game.ReplicatedStorage.Remotes.Misc.AttributeRemote
- local standRemote = game.ReplicatedStorage.Remotes.Stands.StandRemote
- local standAttributeRemote = game.ReplicatedStorage.Remotes.Stands.StandAttributeRemote
- local punchModule = require(game.ReplicatedStorage.Modules.PunchModule)
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local stand
- local triggered = false
- local debounce = false
- local standParamsTriggered = false
- local isHeld = false
- local isBlockHeld = false
- local visualize = true
- local combo = 1
- local comboResetTime = 2 + 0.7 -- 0.7 because of the cooldowns and stuff
- local combatRayLength = 7
- local blockTrack: AnimationTrack = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Combat.Block)
- local standParams = RaycastParams.new()
- standParams.IgnoreWater = true
- standParams.FilterType = Enum.RaycastFilterType.Exclude
- standParams.FilterDescendantsInstances = char:GetDescendants()
- local function TickNew()
- return DateTime.now().UnixTimestampMillis / 1000
- end
- local lastHit = TickNew()
- --[[local function Punch(punchType: string, standCast: Part)
- local sfx = game:GetService("SoundService").Combat.Swing:Clone()
- sfx.Parent = char
- sfx:Destroy()
- local raycastResults
- if not standCast then
- raycastResults = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * combatRayLength, raycastParams)
- else
- raycastResults = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * combatRayLength, standParams)
- end
- local distance = combatRayLength
- if visualize then
- local visualizer = Instance.new("Part")
- visualizer.Anchored = true
- visualizer.Transparency = 0.3
- visualizer.Parent = workspace
- visualizer.CanCollide = false
- visualizer.CanQuery = false
- visualizer.Size = Vector3.new(0.1, 0.1, distance)
- visualizer.CFrame = CFrame.new(char.HumanoidRootPart.Position, char.HumanoidRootPart.Position + char.HumanoidRootPart.CFrame.LookVector * 6) * CFrame.new(0, 0, -distance/2)
- game.Debris:AddItem(visualizer, 2)
- end
- if raycastResults then
- local name = raycastResults.Instance.Name
- local hitDirection = "None"
- print(raycastResults.Instance.Name)
- print(raycastResults.Instance.Parent.Name)
- if raycastResults.Instance.Parent:FindFirstChild("HumanoidRootPart") then
- local lookArea = (char.HumanoidRootPart.Position - raycastResults.Instance.Position).Unit
- local dotProduct = lookArea:Dot(raycastResults.Instance.Parent.HumanoidRootPart.CFrame.LookVector)
- if dotProduct >= 0 then
- -- FRONT
- hitDirection = "Front"
- else
- -- BACK
- hitDirection = "Back"
- end
- remote:FireServer(raycastResults.Instance, punchType, hitDirection, combo)
- end
- end
- end]]
- RunService.Heartbeat:Connect(function()
- if char:GetAttribute("StandSummoned") == true then
- if not triggered then
- triggered = true
- if char:FindFirstChild("Stand", true) then
- stand = char:FindFirstChild("Stand", true).Parent
- end
- end
- if not standParamsTriggered then
- repeat
- if not stand then
- stand = char:FindFirstChild("Stand", true).Parent
- end
- task.wait(0.1)
- until stand and stand:FindFirstChild("Humanoid")
- standParamsTriggered = true
- standParams.FilterDescendantsInstances = { char:GetDescendants(), stand:GetDescendants() }
- end
- if isBlockHeld then
- if char:GetAttribute("State") ~= "Default" then return end
- if char:GetAttribute("State") == "Default" then
- attributeRemote:FireServer("Parry", true)
- task.delay(0.1, function()
- attributeRemote:FireServer("Parry", false)
- end)
- end
- attributeRemote:FireServer("State", "Blocking")
- if stand:GetAttribute("StandState") ~= "Blocking" then
- standRemote:FireServer("move", "InFront")
- standAttributeRemote:FireServer("StandState", "Blocking")
- end
- else
- if char:GetAttribute("State") == "Blocking" then
- attributeRemote:FireServer("State", "Default")
- end
- if stand and stand:GetAttribute("StandState") == "Blocking" then
- standRemote:FireServer("move", "Behind")
- standAttributeRemote:FireServer("StandState", "Idle")
- end
- end
- if isHeld then
- if debounce then return end
- if char:GetAttribute("State") ~= "Default" then return end
- debounce = true
- if combo ~= 1 and TickNew() - lastHit >= comboResetTime then
- combo = 1
- end
- attributeRemote:FireServer("State", "Attacking")
- if stand:GetAttribute("StandState") ~= "Attacking" then
- standAttributeRemote:FireServer("StandState", "Attacking")
- standRemote:FireServer("move", "InFront")
- end
- repeat
- if not stand then
- stand = char:FindFirstChild("Stand", true).Parent
- end
- task.wait(0.1)
- until stand and stand:FindFirstChild("Humanoid")
- if combo < 4 then
- local track = stand:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.Combat["M" .. combo])
- track:Play()
- lastHit = TickNew()
- task.wait(0.2)
- punchModule.Punch(char, combatRayLength, true, "Normal", stand, combo)
- combo += 1
- elseif combo >= 4 then
- local track = stand:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.Combat.M4)
- track:Play()
- lastHit = TickNew()
- task.wait(0.2)
- punchModule.Punch(char, combatRayLength, true, "Heavy", stand, combo)
- combo = 1
- task.wait(0.8)
- end
- task.wait(0.5)
- debounce = false
- if stand:GetAttribute("StandState") == "Attacking" then
- if stand:GetAttribute("StandState") == "Barraging" then return end
- standRemote:FireServer("move", "Behind")
- standAttributeRemote:FireServer("StandState", "Idle")
- end
- if plr.Character:GetAttribute("State") ~= "Stunned" then
- attributeRemote:FireServer("State", "Default")
- end
- end
- return
- else
- triggered = false
- end
- if isBlockHeld then
- if char:GetAttribute("State") ~= "Default" then return end
- if char:GetAttribute("State") == "Default" then
- attributeRemote:FireServer("Parry", true)
- task.delay(0.1, function()
- attributeRemote:FireServer("Parry", false)
- end)
- end
- attributeRemote:FireServer("State", "Blocking")
- if not blockTrack.IsPlaying then
- blockTrack:Play()
- end
- else
- if char:GetAttribute("State") == "Blocking" then
- attributeRemote:FireServer("State", "Default")
- end
- if blockTrack.IsPlaying then
- blockTrack:Stop()
- end
- end
- if isHeld then
- if debounce then return end
- if char:GetAttribute("State") ~= "Default" then return end
- debounce = true
- if combo ~= 1 and TickNew() - lastHit >= comboResetTime then
- combo = 1
- end
- attributeRemote:FireServer("State", "Attacking")
- if combo < 4 then
- local track = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Combat["M" .. combo])
- track:Play()
- lastHit = TickNew()
- task.wait(0.2)
- punchModule.Punch(char, combatRayLength, true, "Normal", nil, combo)
- combo += 1
- elseif combo >= 4 then
- local track = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Combat.M4)
- track:Play()
- lastHit = TickNew()
- task.wait(0.2)
- punchModule.Punch(char, combatRayLength, true, "Heavy", nil, combo)
- combo = 1
- task.wait(0.8)
- end
- task.wait(0.5)
- debounce = false
- if plr.Character:GetAttribute("State") ~= "Stunned" then
- attributeRemote:FireServer("State", "Default")
- end
- end
- end)
- UserInputService.InputBegan:Connect(function(input, process)
- if process then return end
- if input.UserInputType == Enum.UserInputType.MouseButton1 then
- isHeld = true
- else
- if input.KeyCode == Enum.KeyCode.F then
- isBlockHeld = true
- end
- end
- end)
- UserInputService.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 then
- isHeld = false
- else
- if input.KeyCode == Enum.KeyCode.F then
- isBlockHeld = false
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement