Advertisement
Ultimate_69

Combat System (Server)

Feb 6th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. local remote = game.ReplicatedStorage.Remotes.Combat.CombatEvent
  2. local knockbackRemote = game.ReplicatedStorage.Remotes.Combat.KnockbackEvent
  3. local dummyKnockbackRemote = game.ReplicatedStorage.BindableEvents.Combat.DummyKnockback
  4.  
  5. local normalDmg = 4
  6. local heavyDmg = 6
  7. local barrageDmg = 1.5
  8.  
  9. local addRageAmount = 3.5
  10. local barrageAddRageAmount = addRageAmount / 16
  11.  
  12. local normalKnockback = 50
  13. local heavyKnockback = 100
  14.  
  15. local stunLength = 1
  16. local parryLength = 2
  17. local blockBreakLength = 2
  18.  
  19. local thread: thread
  20.  
  21. local function GetDamage(char)
  22. return char:GetAttribute("Rage") / 100
  23. end
  24.  
  25. local function AddRage(char, amount)
  26. return char:GetAttribute("Rage") + amount
  27. end
  28.  
  29. remote.OnServerEvent:Connect(function(plr: Player, hit: BasePart, punchType: string, direction: string, combo: number)
  30. local char = plr.Character
  31. local hum = char.Humanoid
  32. local humrp = char.HumanoidRootPart
  33.  
  34. local echar = hit.Parent
  35. local ehum: Humanoid = echar.Humanoid
  36. local ehumrp = echar.HumanoidRootPart
  37.  
  38. if echar:GetAttribute("State") == "IFrames" or echar:GetAttribute("NPC") then
  39. return
  40. end
  41.  
  42. local hitVFX = game.ReplicatedStorage.VFX.Hit:Clone()
  43. local hitFx: Sound
  44. if punchType == "Normal" or punchType == "Heavy" then
  45. hitFx = game.SoundService.Combat["M" .. combo]:Clone()
  46. elseif punchType == "StandHeavy" then
  47. hitFx = game.SoundService.Combat.M4:Clone()
  48. else
  49. hitFx = game.SoundService.Combat.HitSound:Clone()
  50. end
  51.  
  52. if ehum.Health <= normalDmg and punchType == "Normal" or ehum.Health <= heavyDmg and punchType == "Heavy" then
  53. hitFx = game.SoundService.Combat.M4:Clone()
  54. if not echar:FindFirstChild("Dummy") then
  55. knockbackRemote:FireClient(game.Players:GetPlayerFromCharacter(echar), char.Torso.CFrame.LookVector * heavyKnockback)
  56. else
  57. dummyKnockbackRemote:Fire(char.Torso.CFrame.LookVector * heavyKnockback, echar.Dummy.Value)
  58. end
  59. end
  60.  
  61. if punchType == "StandHeavy" then
  62. if echar:GetAttribute("State") == "Blocking" then
  63. if direction == "Front" then
  64. if echar:GetAttribute("Parry") == true then
  65. local parrySFX = game.SoundService.Combat.Parry:Clone()
  66. parrySFX.Parent = echar
  67. parrySFX:Destroy()
  68. char:SetAttribute("State", "Stunned")
  69. task.delay(parryLength, function()
  70. char:SetAttribute("State", "Default")
  71. end)
  72. return
  73. end
  74. end
  75. end
  76.  
  77. echar:SetAttribute("State", "Stunned")
  78.  
  79. task.delay(stunLength, function()
  80. echar:SetAttribute("State", "Default")
  81. end)
  82.  
  83. hitFx.Parent = echar
  84. hitFx:Destroy()
  85.  
  86. hitVFX.Parent = ehumrp
  87. hitVFX.Position = ehumrp.Position
  88. game.Debris:AddItem(hitVFX, 0.4)
  89.  
  90. ehum:TakeDamage(heavyDmg + GetDamage(char))
  91. char:SetAttribute("Rage", AddRage(char, addRageAmount))
  92.  
  93. if thread then
  94. task.cancel(thread)
  95. end
  96. if ehum.Health > 10 then
  97. if not echar:FindFirstChild("Dummy") then
  98. knockbackRemote:FireClient(game.Players:GetPlayerFromCharacter(echar), char.Torso.CFrame.LookVector * normalKnockback)
  99. else
  100. dummyKnockbackRemote:Fire(char.Torso.CFrame.LookVector * normalKnockback, echar.Dummy.Value)
  101. end
  102. echar.IsRagdoll.Value = true
  103. task.wait(3)
  104. echar.IsRagdoll.Value = false
  105. end
  106. elseif punchType == "Barrage" then
  107. if echar:GetAttribute("State") == "Blocking" then
  108. if direction == "Front" then
  109. if echar:GetAttribute("Parry") == true then
  110. local parrySFX = game.SoundService.Combat.Parry:Clone()
  111. parrySFX.Parent = echar
  112. parrySFX:Destroy()
  113. char:SetAttribute("State", "Stunned")
  114. task.delay(parryLength, function()
  115. char:SetAttribute("State", "Default")
  116. end)
  117. return
  118. end
  119. local blockSFX = game.SoundService.Combat.Block:Clone()
  120. blockSFX.Parent = echar
  121. blockSFX:Destroy()
  122. return
  123. end
  124. end
  125.  
  126. hitFx.Parent = echar
  127. hitFx:Destroy()
  128.  
  129. hitVFX.Parent = ehumrp
  130. hitVFX.Position = ehumrp.Position
  131. game.Debris:AddItem(hitVFX, 0.4)
  132.  
  133. ehum:TakeDamage(barrageDmg + GetDamage(char))
  134. char:SetAttribute("Rage", AddRage(char, barrageAddRageAmount))
  135. if thread then
  136. task.cancel(thread)
  137. end
  138. echar:SetAttribute("State", "Stunned")
  139. thread = task.delay(stunLength, function()
  140. echar:SetAttribute("State", "Default")
  141. end)
  142. elseif punchType == "Heavy" then
  143.  
  144. if echar:GetAttribute("State") == "Blocking" then
  145. if echar:GetAttribute("Parry") == true and direction == "Front" then
  146. local parrySFX = game.SoundService.Combat.Parry:Clone()
  147. parrySFX.Parent = echar
  148. parrySFX:Destroy()
  149. char:SetAttribute("State", "Stunned")
  150. thread = task.delay(parryLength, function()
  151. char:SetAttribute("State", "Default")
  152. end)
  153. return
  154. end
  155.  
  156. echar:SetAttribute("State", "Stunned")
  157.  
  158. thread = task.delay(blockBreakLength, function()
  159. echar:SetAttribute("State", "Default")
  160. end)
  161.  
  162. hitFx.Parent = echar
  163. hitFx:Destroy()
  164.  
  165. hitVFX.Parent = ehumrp
  166. hitVFX.Position = ehumrp.Position
  167. game.Debris:AddItem(hitVFX, 0.4)
  168.  
  169. ehum:TakeDamage(heavyDmg + GetDamage(char))
  170. char:SetAttribute("Rage", AddRage(char, addRageAmount))
  171. if thread then
  172. task.cancel(thread)
  173. end
  174. return
  175. end
  176.  
  177.  
  178. echar:SetAttribute("State", "Stunned")
  179.  
  180. task.delay(stunLength, function()
  181. echar:SetAttribute("State", "Default")
  182. end)
  183.  
  184. hitFx.Parent = echar
  185. hitFx:Destroy()
  186.  
  187. hitVFX.Parent = ehumrp
  188. hitVFX.Position = ehumrp.Position
  189. game.Debris:AddItem(hitVFX, 0.4)
  190.  
  191. ehum:TakeDamage(heavyDmg + GetDamage(char))
  192. char:SetAttribute("Rage", AddRage(char, addRageAmount))
  193. if thread then
  194. task.cancel(thread)
  195. end
  196. if ehum.Health > 10 then
  197. if not echar:FindFirstChild("Dummy") then
  198. knockbackRemote:FireClient(game.Players:GetPlayerFromCharacter(echar), char.Torso.CFrame.LookVector * normalKnockback)
  199. else
  200. dummyKnockbackRemote:Fire(char.Torso.CFrame.LookVector * normalKnockback, echar.Dummy.Value)
  201. end
  202. echar.IsRagdoll.Value = true
  203. task.wait(3)
  204. echar.IsRagdoll.Value = false
  205. end
  206. elseif punchType == "Normal" then
  207.  
  208. if echar:GetAttribute("State") == "Blocking" then
  209. if direction == "Front" then
  210. if echar:GetAttribute("Parry") == true then
  211. local parrySFX = game.SoundService.Combat.Parry:Clone()
  212. parrySFX.Parent = echar
  213. parrySFX:Destroy()
  214. char:SetAttribute("State", "Stunned")
  215. task.delay(parryLength, function()
  216. char:SetAttribute("State", "Default")
  217. end)
  218. return
  219. end
  220. local blockSFX = game.SoundService.Combat.Block:Clone()
  221. blockSFX.Parent = echar
  222. blockSFX:Destroy()
  223. return
  224. end
  225. end
  226.  
  227. hitFx.Parent = echar
  228. hitFx:Destroy()
  229.  
  230. hitVFX.Parent = ehumrp
  231. hitVFX.Position = ehumrp.Position
  232. game.Debris:AddItem(hitVFX, 0.4)
  233.  
  234. ehum:TakeDamage(normalDmg + GetDamage(char))
  235. char:SetAttribute("Rage", AddRage(char, addRageAmount))
  236. if thread then
  237. task.cancel(thread)
  238. end
  239. echar:SetAttribute("State", "Stunned")
  240. thread = task.delay(stunLength, function()
  241. echar:SetAttribute("State", "Default")
  242. end)
  243. end
  244. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement