Advertisement
billwa

Combat Knife

Nov 5th, 2015
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.72 KB | None | 0 0
  1. local combatknife = Instance.new("Tool", game.Players.LocalPlayer.Backpack)
  2. combatknife.Grip = CFrame.new(0, 0, 0)* CFrame.Angles(-1.5707963705063, 0, -1.5707963705063)
  3. combatknife.GripForward = Vector3.new(0, -1, 0)
  4. combatknife.Name = "Combatknife"
  5. combatknife.GripRight = Vector3.new(0, 0, 1)
  6. combatknife.GripUp = Vector3.new(1, 0, 0)
  7.  
  8. local edge = Instance.new("Part", combatknife)
  9. edge.FormFactor = Enum.FormFactor.Custom
  10. edge.LeftSurface = Enum.SurfaceType.Weld
  11. edge.Transparency = 1
  12. edge.TopSurface = Enum.SurfaceType.Weld
  13. edge.Anchored = false
  14. edge.Size = Vector3.new(1.4, 0.4, 0.2)
  15. edge.Name = "Edge"
  16. edge.FrontSurface = Enum.SurfaceType.Weld
  17. edge.Locked = true
  18. edge.CFrame = CFrame.new(-4.6, 1.451, 2.911)* CFrame.Angles(-0.00022851390531287, -1.3008351325989, 1.5705379247665)
  19. edge.RightSurface = Enum.SurfaceType.Weld
  20. edge.BackSurface = Enum.SurfaceType.Weld
  21. edge.BrickColor = BrickColor.new("Dark grey metallic")
  22. edge.Friction = 0.3
  23. edge.BottomSurface = Enum.SurfaceType.Weld
  24.  
  25. local mesh = Instance.new("BlockMesh", edge)
  26. mesh.Scale = Vector3.new(1, 1, 0.1)
  27.  
  28. local decal = Instance.new("Decal", edge)
  29. decal.Texture = "http://www.roblox.com/asset/?id=41872978"
  30.  
  31. local decal_2 = Instance.new("Decal", edge)
  32. decal_2.Face = Enum.NormalId.Back
  33. decal_2.Texture = "http://www.roblox.com/asset/?id=41873039"
  34.  
  35. local edge_2 = Instance.new("Part", combatknife)
  36. edge_2.FormFactor = Enum.FormFactor.Custom
  37. edge_2.LeftSurface = Enum.SurfaceType.Weld
  38. edge_2.Transparency = 1
  39. edge_2.TopSurface = Enum.SurfaceType.Weld
  40. edge_2.Anchored = false
  41. edge_2.Size = Vector3.new(0.8, 0.4, 0.2)
  42. edge_2.Name = "Edge"
  43. edge_2.FrontSurface = Enum.SurfaceType.Weld
  44. edge_2.Locked = true
  45. edge_2.CFrame = CFrame.new(-4.6, 0.39, 2.911)* CFrame.Angles(-0.00023184972815216, -1.3008621931076, 1.5705318450928)
  46. edge_2.RightSurface = Enum.SurfaceType.Weld
  47. edge_2.BackSurface = Enum.SurfaceType.Weld
  48. edge_2.BrickColor = BrickColor.new("Dark grey metallic")
  49. edge_2.Friction = 0.3
  50. edge_2.BottomSurface = Enum.SurfaceType.Weld
  51.  
  52. local mesh_2 = Instance.new("BlockMesh", edge_2)
  53. mesh_2.Scale = Vector3.new(1, 1, 0.1)
  54.  
  55. local decal_3 = Instance.new("Decal", edge_2)
  56. decal_3.Texture = "http://www.roblox.com/asset/?id=41872988"
  57.  
  58. local decal_4 = Instance.new("Decal", edge_2)
  59. decal_4.Face = Enum.NormalId.Back
  60. decal_4.Texture = "http://www.roblox.com/asset/?id=41873073"
  61.  
  62. local handle = Instance.new("Part", combatknife)
  63. handle.FormFactor = Enum.FormFactor.Custom
  64. handle.LeftSurface = Enum.SurfaceType.Weld
  65. handle.TopSurface = Enum.SurfaceType.Weld
  66. handle.Anchored = false
  67. handle.Size = Vector3.new(0.8, 0.4, 0.2)
  68. handle.Name = "Handle"
  69. handle.FrontSurface = Enum.SurfaceType.Weld
  70. handle.Locked = true
  71. handle.CFrame = CFrame.new(-4.6, 2.545, 2.911)* CFrame.Angles(-8.5182124166749e-005, -1.3009506464005, 1.570799946785)
  72. handle.RightSurface = Enum.SurfaceType.Weld
  73. handle.BackSurface = Enum.SurfaceType.Weld
  74. handle.BrickColor = BrickColor.new("Bright red")
  75. handle.Friction = 0.3
  76. handle.BottomSurface = Enum.SurfaceType.Weld
  77.  
  78. local mesh_3 = Instance.new("BlockMesh", handle)
  79. mesh_3.Scale = Vector3.new(1, 0.75, 1)
  80.  
  81. local decal_5 = Instance.new("Decal", handle)
  82. decal_5.Face = Enum.NormalId.Back
  83. decal_5.Texture = "http://www.roblox.com/asset/?id=41872777"
  84.  
  85. local decal_6 = Instance.new("Decal", handle)
  86. decal_6.Texture = "http://www.roblox.com/asset/?id=41872766"
  87.  
  88. local decal_7 = Instance.new("Decal", handle)
  89. decal_7.Face = Enum.NormalId.Top
  90. decal_7.Texture = "http://www.roblox.com/asset/?id=41872777"
  91.  
  92. local decal_8 = Instance.new("Decal", handle)
  93. decal_8.Face = Enum.NormalId.Bottom
  94. decal_8.Texture = "http://www.roblox.com/asset/?id=41872777"
  95.  
  96. local decal_9 = Instance.new("Decal", handle)
  97. decal_9.Face = Enum.NormalId.Right
  98. decal_9.Texture = "http://www.roblox.com/asset/?id=41872777"
  99.  
  100. local decal_10 = Instance.new("Decal", handle)
  101. decal_10.Face = Enum.NormalId.Left
  102. decal_10.Texture = "http://www.roblox.com/asset/?id=41872824"
  103.  
  104. local slash = Instance.new("Sound", handle)
  105. slash.Pitch = 2
  106. slash.Name = "Slash"
  107. slash.Volume = 1
  108. slash.SoundId = "http://roblox.com/asset/?id=10209850"
  109. slash.PlayOnRemove = true
  110.  
  111. local hit = Instance.new("Sound", handle)
  112. hit.Pitch = 4
  113. hit.Name = "Hit"
  114. hit.Volume = 1
  115. hit.SoundId = "http://roblox.com/asset/?id=10209596"
  116. hit.PlayOnRemove = true
  117.  
  118. local pewpew = Instance.new("Sound", handle)
  119. pewpew.Name = "PewPew"
  120. pewpew.Volume = 1
  121. pewpew.SoundId = "http://www.roblox.com/asset/?id=13775480"
  122.  
  123. local knifepart = Instance.new("Part", combatknife)
  124. knifepart.FormFactor = Enum.FormFactor.Custom
  125. knifepart.LeftSurface = Enum.SurfaceType.Weld
  126. knifepart.TopSurface = Enum.SurfaceType.Weld
  127. knifepart.Anchored = false
  128. knifepart.Size = Vector3.new(0.2, 0.2, 0.2)
  129. knifepart.Name = "KnifePart"
  130. knifepart.FrontSurface = Enum.SurfaceType.Weld
  131. knifepart.Locked = true
  132. knifepart.CFrame = CFrame.new(-4.645, 2.08, 2.705)* CFrame.Angles(-8.9700122771319e-005, 0.2698617875576, -3.1415920257568)
  133. knifepart.RightSurface = Enum.SurfaceType.Weld
  134. knifepart.BackSurface = Enum.SurfaceType.Weld
  135. knifepart.BrickColor = BrickColor.new("Dark grey metallic")
  136. knifepart.Friction = 0.3
  137. knifepart.BottomSurface = Enum.SurfaceType.Weld
  138.  
  139. local mesh_4 = Instance.new("SpecialMesh", knifepart)
  140. mesh_4.Scale = Vector3.new(0.25, 1, 1)
  141. mesh_4.MeshType = Enum.MeshType.Wedge
  142.  
  143. local decal_11 = Instance.new("Decal", knifepart)
  144. decal_11.Face = Enum.NormalId.Top
  145. decal_11.Texture = "http://www.roblox.com/asset/?id=41872824"
  146.  
  147. local decal_12 = Instance.new("Decal", knifepart)
  148. decal_12.Face = Enum.NormalId.Bottom
  149. decal_12.Texture = "http://www.roblox.com/asset/?id=41872824"
  150.  
  151. local decal_13 = Instance.new("Decal", knifepart)
  152. decal_13.Face = Enum.NormalId.Back
  153. decal_13.Texture = "http://www.roblox.com/asset/?id=41872824"
  154.  
  155. local decal_14 = Instance.new("Decal", knifepart)
  156. decal_14.Texture = "http://www.roblox.com/asset/?id=41872824"
  157.  
  158. local decal_15 = Instance.new("Decal", knifepart)
  159. decal_15.Face = Enum.NormalId.Right
  160. decal_15.Texture = "http://www.roblox.com/asset/?id=41872824"
  161.  
  162. local decal_16 = Instance.new("Decal", knifepart)
  163. decal_16.Face = Enum.NormalId.Left
  164. decal_16.Texture = "http://www.roblox.com/asset/?id=41872824"
  165.  
  166. local knifepart_2 = Instance.new("Part", combatknife)
  167. knifepart_2.FormFactor = Enum.FormFactor.Custom
  168. knifepart_2.LeftSurface = Enum.SurfaceType.Weld
  169. knifepart_2.TopSurface = Enum.SurfaceType.Weld
  170. knifepart_2.Anchored = false
  171. knifepart_2.Size = Vector3.new(0.2, 0.2, 0.2)
  172. knifepart_2.Name = "KnifePart"
  173. knifepart_2.FrontSurface = Enum.SurfaceType.Weld
  174. knifepart_2.Locked = true
  175. knifepart_2.CFrame = CFrame.new(-4.547, 2.045, 3.102)* CFrame.Angles(3.1415030956268, -0.2698617875576, -7.4260981364205e-007)
  176. knifepart_2.RightSurface = Enum.SurfaceType.Weld
  177. knifepart_2.BackSurface = Enum.SurfaceType.Weld
  178. knifepart_2.BrickColor = BrickColor.new("Dark grey metallic")
  179. knifepart_2.Friction = 0.3
  180. knifepart_2.BottomSurface = Enum.SurfaceType.Weld
  181.  
  182. local mesh_5 = Instance.new("SpecialMesh", knifepart_2)
  183. mesh_5.Scale = Vector3.new(0.25, 1, 1)
  184. mesh_5.MeshType = Enum.MeshType.Wedge
  185.  
  186. local decal_17 = Instance.new("Decal", knifepart_2)
  187. decal_17.Face = Enum.NormalId.Top
  188. decal_17.Texture = "http://www.roblox.com/asset/?id=41872824"
  189.  
  190. local decal_18 = Instance.new("Decal", knifepart_2)
  191. decal_18.Face = Enum.NormalId.Bottom
  192. decal_18.Texture = "http://www.roblox.com/asset/?id=41872824"
  193.  
  194. local decal_19 = Instance.new("Decal", knifepart_2)
  195. decal_19.Face = Enum.NormalId.Back
  196. decal_19.Texture = "http://www.roblox.com/asset/?id=41872824"
  197.  
  198. local decal_20 = Instance.new("Decal", knifepart_2)
  199. decal_20.Texture = "http://www.roblox.com/asset/?id=41872824"
  200.  
  201. local decal_21 = Instance.new("Decal", knifepart_2)
  202. decal_21.Face = Enum.NormalId.Right
  203. decal_21.Texture = "http://www.roblox.com/asset/?id=41872824"
  204.  
  205. local decal_22 = Instance.new("Decal", knifepart_2)
  206. decal_22.Face = Enum.NormalId.Left
  207. decal_22.Texture = "http://www.roblox.com/asset/?id=41872824"
  208.  
  209. local humanoid = Instance.new("Humanoid", combatknife)
  210. humanoid.Health = 0
  211.  
  212. local prev
  213. local parts = combatknife:GetChildren()
  214.  
  215. for i = 1,#parts do
  216.         if (parts[i].className == "Part") then
  217.                 if (prev ~= nil)then
  218.                         local weld = Instance.new("Weld")
  219.                         weld.Part0 = prev
  220.                         weld.Part1 = parts[i]
  221.                         weld.C0 = prev.CFrame:inverse()
  222.                         weld.C1 = parts[i].CFrame:inverse()
  223.                         weld.Parent = prev
  224.                 end
  225.                 prev = parts[i]
  226.         end
  227. end
  228.  
  229. local Tool = combatknife;
  230.  
  231. enabled = true
  232. function onButton1Down(mouse)
  233.     if not enabled then
  234.         return
  235.     end
  236.  
  237.     enabled = false
  238.     mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
  239.  
  240.     wait(.05)
  241.     mouse.Icon = "rbxasset://textures\\GunCursor.png"
  242.     enabled = true
  243.  
  244. end
  245.  
  246. function onEquippedLocal(mouse)
  247.  
  248.     if mouse == nil then
  249.         print("Mouse not found")
  250.         return
  251.     end
  252.  
  253.     mouse.Icon = "rbxasset://textures\\GunCursor.png"
  254.     mouse.Button1Down:connect(function() onButton1Down(mouse) end)
  255.  
  256.     local g = combatknife:GetChildren()
  257.     for i=1, #g do
  258.         if g[i].className == "Part" then
  259.             g[i].CanCollide = false
  260.         end
  261.     end
  262. end
  263.  
  264.  
  265. Tool.Equipped:connect(onEquippedLocal)
  266.  
  267. function onUnequippedLocal(mouse)
  268.     local g = combatknife:GetChildren()
  269.     for i=1, #g do
  270.         if g[i].className == "Part" then
  271.             g[i].CanCollide = true
  272.         end
  273.     end
  274. end
  275.  
  276. Tool.Unequipped:connect(onUnequippedLocal)
  277.  
  278. r = game:service("RunService")
  279.  
  280.  
  281. local damage = 75
  282.  
  283. local slash_damage = 75
  284.  
  285. sword = combatknife.Handle
  286. Tool = combatknife
  287.  
  288. local arms = nil
  289. local torso = nil
  290. local welds = {}
  291.  
  292. function Equip(mouse)
  293. wait(0.01)
  294. arms = {Tool.Parent:FindFirstChild("Left Arm"), Tool.Parent:FindFirstChild("Right Arm")}
  295. torso = Tool.Parent:FindFirstChild("Torso")
  296. if arms ~= nil and torso ~= nil then
  297. local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
  298. if sh ~= nil then
  299. local yes = true
  300. if yes then
  301. yes = false
  302. sh[1].Part1 = nil
  303. sh[2].Part1 = nil
  304. local weld1 = Instance.new("Weld")
  305. weld1.Part0 = torso
  306. weld1.Parent = torso
  307. weld1.Part1 = arms[1]
  308. weld1.C1 = CFrame.new(1.5,0,0) * CFrame.fromEulerAnglesXYZ(math.rad(0), 0, math.rad(0))
  309. welds[1] = weld1
  310. local weld2 = Instance.new("Weld")
  311. weld2.Part0 = torso
  312. weld2.Parent = torso
  313. weld2.Part1 = arms[2]
  314. weld2.C1 = CFrame.new(-1.2, 0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
  315. welds[2] = weld2
  316. end
  317. else
  318. print("sh")
  319. end
  320. else
  321. print("arms")
  322. end
  323. end
  324.  
  325. function Unequip(mouse)
  326. if arms ~= nil and torso ~= nil then
  327. local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
  328. if sh ~= nil then
  329. local yes = true
  330. if yes then
  331. yes = false
  332. sh[1].Part1 = arms[1]
  333. sh[2].Part1 = arms[2]
  334. welds[1].Parent = nil
  335. welds[2].Parent = nil
  336. end
  337. else
  338. print("sh")
  339. end
  340. else
  341. print("arms")
  342. end
  343. end
  344.  
  345. Tool.Equipped:connect(Equip)
  346. Tool.Unequipped:connect(Unequip)
  347.  
  348.  
  349. edge.Touched:connect(function(hit)
  350.     local h = hit.Parent:FindFirstChild('Humanoid')
  351.     if h then
  352.         h.Health = h.Health - 5
  353.     end
  354. end)
  355.  
  356.  
  357.  
  358.  
  359. function blow(hit)
  360.     local humanoid = hit.Parent:findFirstChild("Zombie")
  361.     local vCharacter = Tool.Parent
  362.     local vPlayer = game.Players:playerFromCharacter(vCharacter)
  363.     local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
  364.     if humanoid~=nil and humanoid ~= hum and hum ~= nil then
  365.         if sword.Hit.IsPaused == true then
  366.             sword.Hit:play()
  367.         end
  368.         print("SWORD HIT")
  369.         tagHumanoid(humanoid, vPlayer)
  370.         humanoid:TakeDamage(damage)
  371.         wait(1)
  372.         untagHumanoid(humanoid)
  373.     end
  374. end
  375.  
  376.  
  377. function tagHumanoid(humanoid, player)
  378.     local creator_tag = Instance.new("ObjectValue")
  379.     creator_tag.Value = player
  380.     creator_tag.Name = "creator"
  381.     creator_tag.Parent = humanoid
  382. end
  383.  
  384. function untagHumanoid(humanoid)
  385.     if humanoid ~= nil then
  386.         local tag = humanoid:findFirstChild("creator")
  387.         if tag ~= nil then
  388.             tag.Parent = nil
  389.         end
  390.     end
  391. end
  392.  
  393.  
  394. function attack()
  395.     damage = slash_damage
  396.     local anim = Instance.new("StringValue")
  397.     anim.Name = "toolanim"
  398.     anim.Value = "Slash"
  399.     anim.Parent = Tool
  400.  
  401.     local weld1 = Instance.new("Weld")
  402.     weld1.Part0 = torso
  403.     weld1.Parent = torso
  404.     weld1.Part1 = arms[1]
  405.     weld1.C1 = CFrame.new(1.5,.4,.5) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(0))
  406.     welds[1] = weld1
  407.     local weld2 = Instance.new("Weld")
  408.     weld2.Part0 = torso
  409.     weld2.Parent = torso
  410.     weld2.Part1 = arms[2]
  411.     weld2.C1 = CFrame.new(-1.2, 0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
  412.     welds[2] = weld2
  413.     Tool.GripForward = Vector3.new(0, -1, 0)
  414.     Tool.GripPos = Vector3.new(0,0,0)
  415.     Tool.GripRight = Vector3.new(-1, 0, 0.001)
  416.     Tool.GripUp = Vector3.new(0.001, 0, 1)
  417.     wait(0.125)
  418.     weld1.C1 = CFrame.new(1.5,0,0) * CFrame.fromEulerAnglesXYZ(math.rad(0), 0, math.rad(0))
  419.     weld2.C1 = CFrame.new(-1.2, 0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-50), 0)
  420.     wait(0.0625)
  421.     sword.Slash:play()
  422.     weld1.C1 = CFrame.new(1.5,0,0) * CFrame.fromEulerAnglesXYZ(math.rad(0), 0, math.rad(0))
  423.     weld2.C1 = CFrame.new(-1.2, 0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-100), 0)
  424.     wait(0.2)
  425.     weld1.C1 = CFrame.new(1.5,0,0) * CFrame.fromEulerAnglesXYZ(math.rad(0), 0, math.rad(0))
  426.     weld2.C1 = CFrame.new(-1.2, 0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
  427.     wait(0.0625)
  428.     Tool.GripForward = Vector3.new(0, -1, 0)
  429.     Tool.GripPos = Vector3.new(0,0,0)
  430.     Tool.GripRight = Vector3.new(0, 0, 1)
  431.     Tool.GripUp = Vector3.new(1, 0, 0)
  432. end
  433.  
  434.  
  435. function swordUp()
  436.     Tool.GripForward = Vector3.new(-0, -0, -1)
  437.     Tool.GripPos = Vector3.new(0,0,0)
  438.     Tool.GripRight = Vector3.new(-1e-005, 1, 0)
  439.     Tool.GripUp = Vector3.new(-1, -1e-005, 0)
  440. end
  441.  
  442. function swordOut()
  443.     Tool.GripForward = Vector3.new(-0,-0,-1)
  444.     Tool.GripPos = Vector3.new(0,0,0)
  445.     Tool.GripRight = Vector3.new(-1, 0, 0)
  446.     Tool.GripUp = Vector3.new(0, -1, 0)
  447. end
  448.  
  449. function swordAcross()
  450.     -- parry
  451. end
  452.  
  453.  
  454. Tool.Enabled = true
  455. local last_attack = 0
  456. function onActivated()
  457.  
  458.     if not Tool.Enabled then
  459.         return
  460.     end
  461.  
  462.     Tool.Enabled = false
  463.  
  464.     local character = Tool.Parent;
  465.     local humanoid = character.Humanoid
  466.     if humanoid == nil then
  467.         print("Humanoid not found")
  468.         return
  469.     end
  470.  
  471.     t = r.Stepped:wait()
  472.     attack()
  473.     last_attack = t
  474.  
  475.     --wait(.5)
  476.  
  477.     Tool.Enabled = true
  478. end
  479.  
  480.  
  481. function onEquipped()
  482.     print("LOL")
  483. end
  484.  
  485.  
  486. combatknife.Activated:connect(onActivated)
  487. combatknife.Equipped:connect(onEquipped)
  488.  
  489. for i,part in pairs(Tool:GetChildren()) do
  490.     if part.Name == "Edge" then
  491.         connection = part.Touched:connect(blow)
  492.     end
  493. end
  494.  
  495. function onEquipped()
  496.     p= combatknife:GetChildren()
  497.     for i= 1, #p do
  498.         if p[i].className == "Part" or p[i].className == "TrussPart" or p[i].className == "WedgePart" then
  499.             p[i].Locked = true
  500.         end
  501.     end
  502. end
  503.  
  504. combatknife.Equipped:connect(onEquipped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement