Advertisement
Guest User

Combat System Server Side (Module Script)

a guest
Jun 21st, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. local replicatedStorage = game.ReplicatedStorage
  2. local serverStorage = game.ServerStorage
  3.  
  4. local models = serverStorage.Assets.Models
  5. local animationFolder = serverStorage.Assets.Animations
  6. local weapons = game.ServerStorage.Assets.Weapons
  7.  
  8. local combatAnimations = {animationFolder.RightPunch, animationFolder.LeftPunch, animationFolder.LeftKick, animationFolder.RightKick}
  9. local swordCombatAnimations = {animationFolder.SwordSlash}
  10.  
  11. local contentProvider = game:GetService("ContentProvider")
  12. local animationsToPreload = {animationFolder.RightPunch, animationFolder.LeftPunch, animationFolder.LeftKick, animationFolder.RightKick,
  13. animationFolder.SwordSlash}
  14.  
  15. contentProvider:PreloadAsync(animationsToPreload)
  16.  
  17. local combatHandler = {}
  18.  
  19. combatHandler.combatEvent = function(plr, combatAnimNum)
  20. local char = plr.Character or plr.CharaterAdded:Wait()
  21. local human = char:FindFirstChild("Humanoid")
  22. if human == nil then return end
  23.  
  24. local hitDebounce = false
  25.  
  26. local anim = combatAnimations[combatAnimNum]
  27. local animTrack = human:LoadAnimation(anim)
  28.  
  29. local hitbox = serverStorage.Assets.Hitboxes.ArmHitbox:Clone()
  30.  
  31. if combatAnimNum == 1 then
  32. hitbox.CFrame = char:WaitForChild("RightLowerArm").CFrame
  33. hitbox.Name = "ArmHitbox"
  34.  
  35. local w = Instance.new("Weld", hitbox)
  36. w.Part0 = hitbox
  37. w.Part1 = char.RightLowerArm
  38. elseif combatAnimNum == 2 then
  39. hitbox.CFrame = char:WaitForChild("LeftLowerArm").CFrame
  40. hitbox.Name = "ArmHitbox"
  41.  
  42. local w = Instance.new("Weld", hitbox)
  43. w.Part0 = hitbox
  44. w.Part1 = char.LeftLowerArm
  45. elseif combatAnimNum == 3 then
  46. hitbox.CFrame = char:WaitForChild("LeftLowerLeg").CFrame
  47. hitbox.Name = "LegHitbox"
  48.  
  49. local w = Instance.new("Weld", hitbox)
  50. w.Part0 = hitbox
  51. w.Part1 = char.LeftLowerLeg
  52. elseif combatAnimNum == 4 then
  53. hitbox.CFrame = char:WaitForChild("RightLowerLeg").CFrame
  54. hitbox.Name = "LegHitbox"
  55.  
  56. local w = Instance.new("Weld", hitbox)
  57. w.Part0 = hitbox
  58. w.Part1 = char.RightLowerLeg
  59. end
  60.  
  61. hitbox.Parent = char
  62.  
  63. spawn(function()
  64. wait(1)
  65. if char:FindFirstChild("ArmHitbox") or char:FindFirstChild("LegHitbox") then
  66. print("Removed")
  67. hitbox:Remove()
  68. end
  69. end)
  70.  
  71. animTrack:Play()
  72. return hitbox
  73. end
  74.  
  75. combatHandler.swordDrawEvent = function(plr)
  76. local char = plr.Character or plr.CharaterAdded:Wait()
  77. local human = char:FindFirstChild("Humanoid")
  78. if human == nil then return end
  79.  
  80. local dataModule = require(game.ServerScriptService.CoreSystems.DATASTORE.DATA)
  81. local data = dataModule.DATA[plr]
  82. if data == nil then return end
  83.  
  84. local equippedWeapon = data.Equipped
  85. local equippedType = char.Equipped
  86.  
  87. if equippedWeapon and equippedWeapon ~= "None" then
  88. print(equippedWeapon)
  89. local weapon = weapons:FindFirstChild(equippedWeapon):Clone()
  90. if weapon == nil then return end
  91.  
  92. print("Weapon Found!")
  93.  
  94. weapon.Name = "Sword"
  95. local w = Instance.new("Weld", weapon)
  96. w.Part0 = weapon.Handle
  97. w.Part1 = char.RightHand
  98. w.C0 = CFrame.new(0,0,0) * CFrame.Angles(math.rad(0), math.rad(0), math.rad(90))
  99. equippedType.Value = "Sword"
  100.  
  101. local swordType = weapon.Settings.Type.Value
  102.  
  103. print(swordType)
  104. if swordType == "Rapier" then
  105. --Anim Play Here
  106. print(1)
  107. wait(0.5)
  108. weapon.Parent = char
  109.  
  110. elseif swordType == "Dagger" then
  111. --Anim Play Here
  112. wait(0.5)
  113. weapon.Parent = char
  114.  
  115. elseif swordType == "OneHand" then
  116. --Anim Play Here
  117. wait(0.5)
  118. weapon.Parent = char
  119.  
  120. elseif swordType == "TwoHand" then
  121. --Anim Play Here
  122. wait(0.5)
  123. weapon.Parent = char
  124. end
  125. end
  126. end
  127.  
  128. combatHandler.swordSheathEvent = function(plr)
  129. local char = plr.Character or plr.CharaterAdded:Wait()
  130. local human = char:FindFirstChild("Humanoid")
  131. if human == nil then return end
  132.  
  133. local dataModule = require(game.ServerScriptService.CoreSystems.DATASTORE.DATA)
  134. local data = dataModule.DATA[plr]
  135. if data == nil then return end
  136.  
  137. local equippedWeapon = data.Equipped
  138. local equippedType = char.Equipped
  139.  
  140. if equippedWeapon and equippedWeapon ~= "None" then
  141. local weapon = char:FindFirstChild("Sword")
  142. if weapon then
  143. local swordType = weapon.Settings.Type.Value
  144.  
  145. if swordType == "Rapier" then
  146. --Anim Play Here
  147. wait(0.5)
  148. weapon:Remove()
  149.  
  150. elseif swordType == "Dagger" then
  151. --Anim Play Here
  152. wait(0.5)
  153. weapon:Remove()
  154.  
  155. elseif swordType == "OneHand" then
  156. --Anim Play Here
  157. wait(0.5)
  158. weapon:Remove()
  159.  
  160. elseif swordType == "TwoHand" then
  161. --Anim Play Here
  162. wait(0.5)
  163. weapon:Remove()
  164. end
  165. end
  166. end
  167. end
  168.  
  169. combatHandler.swordCombatEvent = function(plr, combatAnimNum)
  170. local char = plr.Character or plr.CharaterAdded:Wait()
  171. local human = char:FindFirstChild("Humanoid")
  172. if human == nil then return end
  173.  
  174. local sword = char:FindFirstChild("Sword")
  175. if sword == nil then return end
  176.  
  177. local swordType = sword.Settings.Type.Value
  178. print(swordType)
  179. local hitbox
  180. if swordType == "Rapier" then
  181. hitbox = combatHandler.rapierCombatEvent(plr, combatAnimNum)
  182. end
  183. return hitbox
  184. end
  185.  
  186. combatHandler.rapierCombatEvent = function(plr, combatAnimNum)
  187. local char = plr.Character or plr.CharaterAdded:Wait()
  188. local human = char:FindFirstChild("Humanoid")
  189. if human == nil then return end
  190.  
  191. local hitDebounce = false
  192.  
  193. print("Test")
  194.  
  195. return "Test"
  196. end
  197.  
  198. combatHandler.damageCombatEvent = function(plr, hitChar, dmg)
  199. if hitChar:FindFirstChild("Humanoid") then
  200. local hitHuman = hitChar.Humanoid
  201. hitHuman:TakeDamage(dmg)
  202. end
  203. end
  204.  
  205. return combatHandler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement