Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. local plr = script.Parent.Parent.Parent
  2.  
  3. local char = plr.CharacterAdded:wait()
  4.  
  5. local hum = char:WaitForChild'Humanoid'
  6.  
  7. local tool = script.Parent
  8.  
  9. local debris = game:service'Debris'
  10.  
  11. local anims = {
  12. combatIdle = {'rbxassetid://0'},
  13. attack = {'rbxassetid://0'},
  14. }
  15.  
  16. local soundIndex = {
  17. punch = 'rbxassetid://0',
  18. equip = 'rbxassetid://0',
  19. }
  20.  
  21. local hitboxes = {}
  22.  
  23. local attribs = {baseDmg = 5, maxRange = 2}
  24.  
  25. local lastPlayed = nil
  26.  
  27. local function playAnimation(type,index)
  28. local anim = hum:LoadAnimation(anims.type[index])
  29. anim:Play()
  30. lastPlayed = anim
  31. end
  32.  
  33. local function stopAnimation(name)
  34. for _,anim in pairs(hum:GetPlayingAnimationTracks()) do
  35. if anim.Name == name then
  36. anim:Stop()
  37. end
  38. end
  39. end
  40.  
  41. local function playSound(source,volume,id)
  42. local sound = Instance.new('Sound',source)
  43. sound.Volume = volume
  44. sound.SoundId = id
  45.  
  46. sound:Play()
  47.  
  48. wait()
  49.  
  50. debris:AddItem(sound,sound.TimeLength)
  51. end
  52.  
  53. local function initWeld()
  54. local p1 = Instance.new('Part',char)
  55. p1.Size = Vector3.new(char:WaitForChild'Left Arm'.Size.X,2,char:WaitForChild'Left Arm'.Size.Z)
  56. p1.BrickColor = BrickColor.Red()
  57. p1.Transparency = .5
  58.  
  59. local p2 = p1:clone()
  60. p2.Parent = char
  61.  
  62. table.insert(hitboxes,p1)
  63. table.insert(hitboxes,p2)
  64.  
  65. local w1 = Instance.new('Weld',p1)
  66. w1.Part0 = p1
  67. w1.Part1 = char['Left Arm']
  68. w1.C0 = CFrame.new(0,0,1.1) -- jeton test!!!
  69.  
  70. local w2 = Instance.new('Weld',p2)
  71. w2.Part0 = p1
  72. w2.Part1 = char['Right Arm']
  73. w2.C0 = CFrame.new(0,0,1.1) -- jeton test!!!
  74. end
  75.  
  76. tool.Equipped:connect(function())
  77. playAnimation(idle,1)
  78. initWeld()
  79. playSound(char:WaitForChild'HumanoidRootPart',.5,soundIndex.equip)
  80. end)
  81.  
  82. tool.Unequipped:connect(function())
  83. stopAnimation('combatIdle')
  84. for _,v in pairs(hitboxes) do
  85. v:Destroy()
  86. end
  87. end
  88.  
  89. local function calcRange(obj)
  90. local magnitudes = {}
  91.  
  92. local inRange = false
  93.  
  94. for _,p in pairs(obj:GetChildren()) do
  95. if p:IsA'Union' or p:IsA'Part' or p:IsA'MeshPart' then
  96. local mag = (hitboxes[hitbox].Position - p.Position).magnitude
  97. table.insert(magnitudes,mag)
  98. end
  99. end
  100.  
  101. for _,mag in pairs(magnitudes) do
  102. if mag <= attribs.maxRange and not inRange then
  103. inRange = true
  104. end
  105. end
  106.  
  107. return inRange
  108. end
  109.  
  110. local function hitFrom(object)
  111. for _,victim in pairs(workspace:GetChildren()) do
  112. if victim:FindFirstChild'Humanoid' and victim:FindFirstChild'HumanoidRootPart' then
  113. if calcRange(victim) then
  114. victim.Humanoid:TakeDamage(attribs.baseDmg)
  115. end
  116. end
  117. end
  118. end
  119.  
  120. local swinging = false
  121.  
  122. local currentAnim = 1
  123.  
  124. local maxAnims = #anims.attack
  125.  
  126. local delay = .1
  127.  
  128. local hitbox = 1
  129.  
  130. tool.Activated:connect(function())
  131. if char:FindFirstChild'stun' then return end
  132. if not swinging then
  133. swinging = true
  134.  
  135. if currentAnim > maxAnims then
  136. currentAnim = 1
  137. end
  138.  
  139. playAnimation('attack',currentAnim)
  140.  
  141. wait(lastPlayed.AnimationLength + delay)
  142.  
  143. hitFrom(hitboxes[hitbox])
  144.  
  145. if hitbox == 1 then
  146. hitbox = 2
  147. else
  148. hitbox = 1
  149. end
  150.  
  151. wait(cd)
  152.  
  153. swinging = false
  154. end
  155. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement