bigdookie23

Untitled

Jul 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. -------- Reworked by Malvaviscos
  2. pointsToDirection = false -- Change this to true if you want the sword to swing in the direction the mouse is on the screen.
  3.  
  4. r = game:service("RunService")
  5.  
  6. Animate = script.Parent.Animate
  7.  
  8. local damage = 5
  9.  
  10.  
  11. local slash_damage = 8
  12. local lunge_damage = 12
  13.  
  14. sword = script.Parent.Handle
  15. Tool = script.Parent
  16.  
  17. swordDirection = "Center"
  18.  
  19. local SlashSound = sword:findFirstChild("SlashSound")
  20. local LungeSound = sword:findFirstChild("LungeSound")
  21. local UnsheathSound = sword:findFirstChild("UnsheathSound")
  22.  
  23. tutorialized = false
  24.  
  25. if SlashSound == nil then
  26. SlashSound = Instance.new("Sound")
  27. SlashSound.Name = "SlashSound"
  28. SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
  29. SlashSound.Parent = sword
  30. SlashSound.Volume = .7
  31. end
  32.  
  33. if LungeSound == nil then
  34. LungeSound = Instance.new("Sound")
  35. LungeSound.Name = "LungeSound"
  36. LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav"
  37. LungeSound.Parent = sword
  38. LungeSound.Volume = .6
  39. end
  40.  
  41. if UnsheathSound == nil then
  42. UnsheathSound = Instance.new("Sound")
  43. UnsheathSound.Name = "UnsheathSound"
  44. UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav"
  45. UnsheathSound.Parent = sword
  46. UnsheathSound.Volume = 1
  47. end
  48.  
  49.  
  50. function onMove(mouse) -- Optional mouse directional attacks.
  51. local totalX = mouse.ViewSizeX
  52. if mouse.X >= totalX - totalX/3 then
  53. swordDirection = "Right"
  54. elseif mouse.X <= totalX/3 then
  55. swordDirection = "Left"
  56. else
  57. swordDirection = "Center"
  58. end
  59. end
  60.  
  61. function onKeyDown(key)
  62. key = key:lower()
  63. if key == "r" then
  64. stab()
  65. end
  66. if key == "e" then
  67. attackright()
  68. end
  69. if key == "q" then
  70. attackleft()
  71. end
  72. if key == "m" then
  73. printMessage("Press 'q' to swing to the left and press 'e' to swing to the right.", 3)
  74. wait(3)
  75. printMessage("Press 'r' to perform a stabbing attack.", 2)
  76. end
  77. end
  78.  
  79. function getHumanoid(model)
  80. function excluded(name)
  81. exclude = {}
  82. for i, ex in pairs(exclude) do
  83. if string.lower(ex) == string.lower(name) then
  84. return true
  85. end
  86. end
  87. return false
  88. end
  89. for i, child in pairs(model:getChildren()) do
  90. if child.className == "Humanoid" and not excluded(child.Name) then
  91. return child
  92. end
  93. end
  94. end
  95.  
  96. function blow(hit)
  97. local humanoid = getHumanoid(hit.Parent)
  98. local vCharacter = Tool.Parent
  99. local vPlayer = game.Players:playerFromCharacter(vCharacter)
  100. local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
  101. if humanoid~=nil and humanoid ~= hum and hum ~= nil then
  102. -- final check, make sure sword is in-hand
  103.  
  104. local right_arm = vCharacter:FindFirstChild("Right Arm")
  105. if (right_arm ~= nil) then
  106. local joint = right_arm:FindFirstChild("RightGrip")
  107. if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
  108. tagHumanoid(humanoid, vPlayer)
  109. humanoid:TakeDamage(damage)
  110. wait(1)
  111. untagHumanoid(humanoid)
  112. end
  113. end
  114.  
  115.  
  116. end
  117. end
  118.  
  119.  
  120. function tagHumanoid(humanoid, player)
  121. local creator_tag = Instance.new("ObjectValue")
  122. creator_tag.Value = player
  123. creator_tag.Name = "creator"
  124. creator_tag.Parent = humanoid
  125. end
  126.  
  127. function untagHumanoid(humanoid)
  128. if humanoid ~= nil then
  129. local tag = humanoid:findFirstChild("creator")
  130. if tag ~= nil then
  131. tag.Parent = nil
  132. end
  133. end
  134. end
  135.  
  136.  
  137. function attack()
  138. damage = slash_damage
  139. SlashSound:play()
  140. if swordDirection == "Center" then
  141. Animate.Value = "Slash1"
  142. elseif swordDirection == "Right" then
  143. Animate.Value = "SlashRight"
  144. elseif swordDirection == "Left" then
  145. Animate.Value = "SlashLeft"
  146. end
  147. --[[local anim = Instance.new("StringValue")
  148. anim.Name = "toolanim"
  149. anim.Value = "Slash"
  150. anim.Parent = Tool]]
  151. end
  152.  
  153. function lunge()
  154. damage = lunge_damage
  155.  
  156. LungeSound:play()
  157.  
  158. --[[local anim = Instance.new("StringValue")
  159. anim.Name = "toolanim"
  160. anim.Value = "Lunge"
  161. anim.Parent = Tool]]
  162.  
  163. Animate.Value = "Lunge"
  164. wait(0.6)
  165.  
  166. --[[
  167. wait(.2)
  168. swordOut()
  169. wait(.6)
  170. swordUp()
  171. ]]
  172.  
  173. damage = slash_damage
  174. end
  175.  
  176. stabenabled = true
  177. function stab()
  178. if not stabenabled then return end
  179. stabenabled = false
  180. damage = lunge_damage
  181.  
  182. LungeSound:play()
  183.  
  184. --[[local anim = Instance.new("StringValue")
  185. anim.Name = "toolanim"
  186. anim.Value = "Lunge"
  187. anim.Parent = Tool]]
  188.  
  189. Animate.Value = "Stab"
  190. wait(0.6)
  191.  
  192. --[[
  193. wait(.2)
  194. swordOut()
  195. wait(.6)
  196. swordUp()
  197. ]]
  198.  
  199. damage = slash_damage
  200. stabenabled = true
  201. end
  202.  
  203. function attackright()
  204. damage = slash_damage
  205. SlashSound:play()
  206. Animate.Value = "SlashRight"
  207. end
  208.  
  209. function attackleft()
  210. damage = slash_damage
  211. SlashSound:play()
  212. Animate.Value = "SlashLeft"
  213. end
  214.  
  215. function swordUp()
  216. Tool.GripForward = Vector3.new(-1,0,0)
  217. Tool.GripRight = Vector3.new(0,1,0)
  218. Tool.GripUp = Vector3.new(0,0,1)
  219.  
  220. --Tool.Parent["Right Arm"].RightGrip.C1 = CFrame.new(Tool.GripPos.x, Tool.GripPos.y, Tool.GripPos.z, -1,0,0, 0,1,0, 0,0,1)
  221. end
  222.  
  223. function swordOut()
  224. Tool.GripForward = Vector3.new(0,0,1)
  225. Tool.GripRight = Vector3.new(0,1,0)
  226. Tool.GripUp = Vector3.new(1,0,0)
  227.  
  228. --Tool.Parent["Right Arm"].RightGrip.C1 = CFrame.new(Tool.GripPos.x, Tool.GripPos.y, Tool.GripPos.z, 0,0,1, 0,1,0, 1,0,0)
  229. end
  230.  
  231. function swordAcross()
  232. -- parry
  233. end
  234.  
  235. function printMessage(text, time)
  236. local msg = Instance.new("Hint")
  237. msg.Text = text
  238. local player = game.Players:findFirstChild(Tool.Parent.Name)
  239. if player ~= nil then
  240. msg.Parent = player
  241. end
  242. game:getService("Debris"):addItem(msg, time)
  243. end
  244.  
  245. Tool.Enabled = true
  246. local last_attack = 0
  247. function onActivated()
  248.  
  249. if not Tool.Enabled then
  250. return
  251. end
  252.  
  253. Tool.Enabled = false
  254.  
  255. local character = Tool.Parent;
  256. local humanoid = character.Humanoid
  257. if humanoid == nil then
  258. print("Humanoid not found")
  259. return
  260. end
  261.  
  262. t = r.Stepped:wait()
  263. if (t - last_attack < .2) then
  264. lunge()
  265. else
  266. attack()
  267. end
  268.  
  269. last_attack = t
  270.  
  271. --wait(.5)
  272.  
  273. Tool.Enabled = true
  274. end
  275.  
  276.  
  277. function onEquipped(mouse)
  278. UnsheathSound:play()
  279. if pointsToDirection then
  280. mouse.Move:connect(function() onMove(mouse) end)
  281. end
  282. mouse.KeyDown:connect(onKeyDown)
  283. if not tutorialized then
  284. tutorialized = true
  285. printMessage("", 0)
  286. wait(2.5)
  287. printMessage("Press 'q' to swing to the left and press 'e' to swing to the right.", 3)
  288. wait(3)
  289. printMessage("Press 'r' to perform a stabbing attack.", 2)
  290. wait(2)
  291. printMessage("Click to control the sword otherwise. Press 'm' to see this message again.", 3.5)
  292. wait(3.5)
  293. end
  294. end
  295.  
  296.  
  297. script.Parent.Activated:connect(onActivated)
  298. script.Parent.Equipped:connect(onEquipped)
  299.  
  300.  
  301. connection = sword.Touched:connect(blow)
Advertisement
Add Comment
Please, Sign In to add comment