Advertisement
Ultimate_69

Combat System (Client)

Feb 6th, 2025
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.10 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2. local char = plr.Character
  3. local remote = game.ReplicatedStorage.Remotes.Combat.CombatEvent
  4. local attributeRemote = game.ReplicatedStorage.Remotes.Misc.AttributeRemote
  5. local standRemote = game.ReplicatedStorage.Remotes.Stands.StandRemote
  6. local standAttributeRemote = game.ReplicatedStorage.Remotes.Stands.StandAttributeRemote
  7.  
  8. local punchModule = require(game.ReplicatedStorage.Modules.PunchModule)
  9.  
  10. local UserInputService = game:GetService("UserInputService")
  11. local RunService = game:GetService("RunService")
  12.  
  13. local stand
  14. local triggered = false
  15. local debounce = false
  16. local standParamsTriggered = false
  17. local isHeld = false
  18. local isBlockHeld = false
  19. local visualize = true
  20. local combo = 1
  21. local comboResetTime = 2 + 0.7 -- 0.7 because of the cooldowns and stuff
  22. local combatRayLength = 7
  23.  
  24. local blockTrack: AnimationTrack = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Combat.Block)
  25.  
  26. local standParams = RaycastParams.new()
  27. standParams.IgnoreWater = true
  28. standParams.FilterType = Enum.RaycastFilterType.Exclude
  29. standParams.FilterDescendantsInstances = char:GetDescendants()
  30.  
  31. local function TickNew()
  32. return DateTime.now().UnixTimestampMillis / 1000
  33. end
  34.  
  35. local lastHit = TickNew()
  36.  
  37. --[[local function Punch(punchType: string, standCast: Part)
  38. local sfx = game:GetService("SoundService").Combat.Swing:Clone()
  39. sfx.Parent = char
  40. sfx:Destroy()
  41.  
  42. local raycastResults
  43.  
  44. if not standCast then
  45. raycastResults = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * combatRayLength, raycastParams)
  46. else
  47. raycastResults = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * combatRayLength, standParams)
  48. end
  49.  
  50. local distance = combatRayLength
  51.  
  52.  
  53. if visualize then
  54. local visualizer = Instance.new("Part")
  55. visualizer.Anchored = true
  56. visualizer.Transparency = 0.3
  57. visualizer.Parent = workspace
  58. visualizer.CanCollide = false
  59. visualizer.CanQuery = false
  60. visualizer.Size = Vector3.new(0.1, 0.1, distance)
  61. visualizer.CFrame = CFrame.new(char.HumanoidRootPart.Position, char.HumanoidRootPart.Position + char.HumanoidRootPart.CFrame.LookVector * 6) * CFrame.new(0, 0, -distance/2)
  62. game.Debris:AddItem(visualizer, 2)
  63. end
  64.  
  65. if raycastResults then
  66. local name = raycastResults.Instance.Name
  67. local hitDirection = "None"
  68.  
  69. print(raycastResults.Instance.Name)
  70. print(raycastResults.Instance.Parent.Name)
  71.  
  72. if raycastResults.Instance.Parent:FindFirstChild("HumanoidRootPart") then
  73. local lookArea = (char.HumanoidRootPart.Position - raycastResults.Instance.Position).Unit
  74. local dotProduct = lookArea:Dot(raycastResults.Instance.Parent.HumanoidRootPart.CFrame.LookVector)
  75. if dotProduct >= 0 then
  76. -- FRONT
  77. hitDirection = "Front"
  78. else
  79. -- BACK
  80. hitDirection = "Back"
  81. end
  82.  
  83. remote:FireServer(raycastResults.Instance, punchType, hitDirection, combo)
  84. end
  85. end
  86. end]]
  87.  
  88. RunService.Heartbeat:Connect(function()
  89.  
  90. if char:GetAttribute("StandSummoned") == true then
  91. if not triggered then
  92. triggered = true
  93. if char:FindFirstChild("Stand", true) then
  94. stand = char:FindFirstChild("Stand", true).Parent
  95. end
  96. end
  97.  
  98.  
  99. if not standParamsTriggered then
  100. repeat
  101. if not stand then
  102. stand = char:FindFirstChild("Stand", true).Parent
  103. end
  104. task.wait(0.1)
  105. until stand and stand:FindFirstChild("Humanoid")
  106. standParamsTriggered = true
  107. standParams.FilterDescendantsInstances = { char:GetDescendants(), stand:GetDescendants() }
  108. end
  109.  
  110. if isBlockHeld then
  111. if char:GetAttribute("State") ~= "Default" then return end
  112. if char:GetAttribute("State") == "Default" then
  113. attributeRemote:FireServer("Parry", true)
  114. task.delay(0.1, function()
  115. attributeRemote:FireServer("Parry", false)
  116. end)
  117. end
  118. attributeRemote:FireServer("State", "Blocking")
  119.  
  120. if stand:GetAttribute("StandState") ~= "Blocking" then
  121. standRemote:FireServer("move", "InFront")
  122. standAttributeRemote:FireServer("StandState", "Blocking")
  123. end
  124. else
  125. if char:GetAttribute("State") == "Blocking" then
  126. attributeRemote:FireServer("State", "Default")
  127. end
  128.  
  129. if stand and stand:GetAttribute("StandState") == "Blocking" then
  130. standRemote:FireServer("move", "Behind")
  131. standAttributeRemote:FireServer("StandState", "Idle")
  132. end
  133. end
  134.  
  135. if isHeld then
  136. if debounce then return end
  137. if char:GetAttribute("State") ~= "Default" then return end
  138.  
  139. debounce = true
  140.  
  141. if combo ~= 1 and TickNew() - lastHit >= comboResetTime then
  142. combo = 1
  143. end
  144.  
  145. attributeRemote:FireServer("State", "Attacking")
  146. if stand:GetAttribute("StandState") ~= "Attacking" then
  147. standAttributeRemote:FireServer("StandState", "Attacking")
  148. standRemote:FireServer("move", "InFront")
  149. end
  150.  
  151. repeat
  152. if not stand then
  153. stand = char:FindFirstChild("Stand", true).Parent
  154. end
  155. task.wait(0.1)
  156. until stand and stand:FindFirstChild("Humanoid")
  157.  
  158. if combo < 4 then
  159. local track = stand:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.Combat["M" .. combo])
  160. track:Play()
  161. lastHit = TickNew()
  162. task.wait(0.2)
  163. punchModule.Punch(char, combatRayLength, true, "Normal", stand, combo)
  164. combo += 1
  165. elseif combo >= 4 then
  166. local track = stand:WaitForChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Animations.Combat.M4)
  167. track:Play()
  168. lastHit = TickNew()
  169. task.wait(0.2)
  170. punchModule.Punch(char, combatRayLength, true, "Heavy", stand, combo)
  171. combo = 1
  172. task.wait(0.8)
  173. end
  174.  
  175. task.wait(0.5)
  176. debounce = false
  177. if stand:GetAttribute("StandState") == "Attacking" then
  178. if stand:GetAttribute("StandState") == "Barraging" then return end
  179. standRemote:FireServer("move", "Behind")
  180. standAttributeRemote:FireServer("StandState", "Idle")
  181. end
  182.  
  183. if plr.Character:GetAttribute("State") ~= "Stunned" then
  184. attributeRemote:FireServer("State", "Default")
  185. end
  186. end
  187. return
  188. else
  189. triggered = false
  190. end
  191.  
  192. if isBlockHeld then
  193. if char:GetAttribute("State") ~= "Default" then return end
  194. if char:GetAttribute("State") == "Default" then
  195. attributeRemote:FireServer("Parry", true)
  196. task.delay(0.1, function()
  197. attributeRemote:FireServer("Parry", false)
  198. end)
  199. end
  200. attributeRemote:FireServer("State", "Blocking")
  201. if not blockTrack.IsPlaying then
  202. blockTrack:Play()
  203. end
  204. else
  205. if char:GetAttribute("State") == "Blocking" then
  206. attributeRemote:FireServer("State", "Default")
  207. end
  208. if blockTrack.IsPlaying then
  209. blockTrack:Stop()
  210. end
  211. end
  212.  
  213. if isHeld then
  214. if debounce then return end
  215. if char:GetAttribute("State") ~= "Default" then return end
  216.  
  217. debounce = true
  218.  
  219. if combo ~= 1 and TickNew() - lastHit >= comboResetTime then
  220. combo = 1
  221. end
  222.  
  223. attributeRemote:FireServer("State", "Attacking")
  224. if combo < 4 then
  225. local track = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Combat["M" .. combo])
  226. track:Play()
  227. lastHit = TickNew()
  228. task.wait(0.2)
  229. punchModule.Punch(char, combatRayLength, true, "Normal", nil, combo)
  230. combo += 1
  231. elseif combo >= 4 then
  232. local track = char.Humanoid:LoadAnimation(game.ReplicatedStorage.Animations.Combat.M4)
  233. track:Play()
  234. lastHit = TickNew()
  235. task.wait(0.2)
  236. punchModule.Punch(char, combatRayLength, true, "Heavy", nil, combo)
  237. combo = 1
  238. task.wait(0.8)
  239. end
  240.  
  241. task.wait(0.5)
  242. debounce = false
  243.  
  244. if plr.Character:GetAttribute("State") ~= "Stunned" then
  245. attributeRemote:FireServer("State", "Default")
  246. end
  247. end
  248. end)
  249.  
  250. UserInputService.InputBegan:Connect(function(input, process)
  251. if process then return end
  252.  
  253. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  254. isHeld = true
  255. else
  256. if input.KeyCode == Enum.KeyCode.F then
  257. isBlockHeld = true
  258. end
  259. end
  260. end)
  261.  
  262. UserInputService.InputEnded:Connect(function(input)
  263. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  264. isHeld = false
  265. else
  266. if input.KeyCode == Enum.KeyCode.F then
  267. isBlockHeld = false
  268. end
  269. end
  270. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement