Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. local Tool = script.Parent
  2. local Handle = Tool.Handle
  3. local Config = Tool:WaitForChild'Configurations'
  4. local Sword = {
  5. -- Advanced settings
  6. DoubleClickMaxTime = 0.2,
  7. LocalDoubleClickMaxTime = 0.2,
  8.  
  9. -- Variables
  10. State = 'Idle', -- Idle, Slashing, Lunging
  11. LocalState = 'Idle',
  12. SlashingStartedAt = 0,
  13. LocalSlashingStartedAt = 0,
  14. AttackTicket = 0,
  15. LocalAttackTicket = 0,
  16. DestroyOnUnequip = {}
  17. }
  18.  
  19. local GLib = require(Tool:WaitForChild'GLib') -- Library of useful functions
  20.  
  21. --
  22. --
  23. function Sword:Connect()
  24. Handle.Touched:connect(function(hit)
  25. local myPlayer = GLib.GetPlayerFromPart(Tool)
  26. local character, player, humanoid = GLib.GetCharacterFromPart(hit)
  27.  
  28. if myPlayer~=nil and character~=nil and humanoid~=nil and myPlayer~=player then
  29. local isTeammate = GLib.IsTeammate(myPlayer, player)
  30. local myCharacter = myPlayer.Character
  31. local myHumanoid = myCharacter and myCharacter:FindFirstChild'Humanoid'
  32.  
  33. if (Config.CanTeamkill.Value==true or isTeammate~=true) and (myHumanoid and myHumanoid:IsA'Humanoid' and myHumanoid.Health > 0) and (Config.CanKillWithForceField.Value or myCharacter:FindFirstChild'ForceField'==nil) then
  34. local doDamage = Config.IdleDamage.Value
  35. if Sword.State == 'Slashing' then
  36. doDamage = Config.SlashDamage.Value
  37. elseif Sword.State == 'Lunging' then
  38. doDamage = Config.LungeDamage.Value
  39. end
  40.  
  41. GLib.TagHumanoid(humanoid, myPlayer, 1)
  42. humanoid:TakeDamage(doDamage)
  43. end
  44. end
  45. end)
  46. end
  47.  
  48. function Sword:Attack()
  49. local myCharacter, myPlayer, myHumanoid = GLib.GetCharacterFromPart(Tool)
  50.  
  51. if myHumanoid~=nil and myHumanoid.Health > 0 then
  52. if Config.CanKillWithForceField.Value or myCharacter:FindFirstChild'ForceField'==nil then
  53. local now = tick()
  54.  
  55. if Sword.State == 'Slashing' and now-Sword.SlashingStartedAt < Sword.DoubleClickMaxTime then
  56. Sword.AttackTicket = Sword.AttackTicket+1
  57.  
  58. Sword:Lunge(Sword.AttackTicket)
  59. elseif Sword.State == 'Idle' then
  60. Sword.AttackTicket = Sword.AttackTicket+1
  61. Sword.SlashingStartedAt = now
  62.  
  63. Sword:Slash(Sword.AttackTicket)
  64. end
  65. end
  66. end
  67. end
  68.  
  69. function Sword:LocalAttack()
  70. local myCharacter, myPlayer, myHumanoid = GLib.GetCharacterFromPart(Tool)
  71.  
  72. if myHumanoid~=nil and myHumanoid.Health > 0 then
  73. if Config.CanKillWithForceField.Value or myCharacter:FindFirstChild'ForceField'==nil then
  74. local now = tick()
  75.  
  76. if Sword.LocalState == 'Slashing' and now-Sword.LocalSlashingStartedAt < Sword.LocalDoubleClickMaxTime then
  77. Sword.LocalAttackTicket = Sword.LocalAttackTicket+1
  78.  
  79. Sword:LocalLunge(Sword.LocalAttackTicket)
  80. elseif Sword.LocalState == 'Idle' then
  81. Sword.LocalAttackTicket = Sword.LocalAttackTicket+1
  82. Sword.LocalSlashingStartedAt = now
  83.  
  84. Sword:LocalSlash(Sword.LocalAttackTicket)
  85. end
  86. end
  87. end
  88. end
  89.  
  90. function Sword:Slash(ticket)
  91. Sword.State = 'Slashing'
  92.  
  93. Handle.SlashSound:Play()
  94. Sword:Animate'Slash'
  95.  
  96. wait(0.5)
  97.  
  98. if Sword.AttackTicket == ticket then
  99. Sword.State = 'Idle'
  100. end
  101. end
  102.  
  103. function Sword:LocalSlash(ticket)
  104. Sword.LocalState = 'Slashing'
  105.  
  106. wait(0.5)
  107.  
  108. if Sword.LocalAttackTicket == ticket then
  109. Sword.LocalState = 'Idle'
  110. end
  111. end
  112.  
  113. function Sword:Lunge(ticket)
  114. Sword.State = 'Lunging'
  115.  
  116. Handle.LungeSound:Play()
  117. Sword:Animate'Lunge'
  118.  
  119. local force = Instance.new'BodyVelocity'
  120. force.velocity = Vector3.new(0, 10, 0)
  121. force.maxForce = Vector3.new(0, 4000, 0)
  122. force.Parent = Tool.Parent.Torso
  123. Sword.DestroyOnUnequip[force] = true
  124.  
  125. wait(0.25)
  126. Tool.Grip = CFrame.new(0, 0, -1.5, 0, -1, -0, -1, 0, -0, 0, 0, -1)
  127. wait(0.25)
  128. force:Destroy()
  129. Sword.DestroyOnUnequip[force] = nil
  130. wait(0.5)
  131. Tool.Grip = CFrame.new(0, 0, -1.5, 0, 0, 1, 1, 0, 0, 0, 1, 0)
  132.  
  133. Sword.State = 'Idle'
  134. end
  135.  
  136. function Sword:LocalLunge(ticket)
  137. Sword.LocalState = 'Lunging'
  138.  
  139. wait(0.25)
  140. wait(0.25)
  141. wait(0.5)
  142.  
  143. Sword.LocalState = 'Idle'
  144. end
  145.  
  146. function Sword:Animate(name)
  147. local tag = Instance.new'StringValue'
  148. tag.Name = 'toolanim'
  149. tag.Value = name
  150. tag.Parent = Tool -- Tag gets removed by the animation script
  151. end
  152.  
  153. function Sword:Unequip()
  154. for obj in next, Sword.DestroyOnUnequip do
  155. obj:Destroy()
  156. end
  157.  
  158. Sword.DestroyOnUnequip = {}
  159.  
  160. Tool.Grip = CFrame.new(0, 0, -1.5, 0, 0, 1, 1, 0, 0, 0, 1, 0)
  161. Sword.State = 'Idle'
  162. Sword.LocalState = 'Idle'
  163. end
  164.  
  165. --
  166. function Sword:Initialize()
  167. Sword:Connect()
  168. end
  169.  
  170. --
  171. --
  172. return Sword
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement