astronaut32

spear

Jun 9th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.43 KB | None | 0 0
  1. ToolName = "Test"
  2. Player = game.Players.LocalPlayer
  3. Char = Player.Character
  4. Hum = Char.Humanoid
  5. Head = Char.Head
  6. Torso = Char.Torso
  7. Ra = Char["Right Arm"]
  8. La = Char["Left Arm"]
  9. Rl = Char["Right Leg"]
  10. Ll = Char["Left Leg"]
  11. Mouse = Player:GetMouse()
  12. ThrowDamage = math.random(60,80)
  13. pcall(function()Char[ToolName]:Destroy()end)
  14. pcall(function()Player.Backpack[ToolName]:Destroy()end)
  15. local Main = Instance.new("Model",Char)
  16. Main.Name = ToolName
  17. script.Parent = Main
  18. v3 = Vector3.new; mr = math.rad;
  19. cw = coroutine.wrap; mrd = math.random;
  20. cf = CFrame.new; ud2 = UDim2.new;
  21. ca = CFrame.Angles; v2 = Vector2.new
  22. bc = BrickColor.new; inst = Instance.new
  23. http = "http://www.roblox.com/asset/?id="
  24. Attacking = false
  25. Walking = false
  26. --Hum.Jump == Jumping
  27. Sitting = false
  28. FreeFalling = false
  29. function part(par,size,color,tra,can)
  30. local P = Instance.new("Part",par)
  31. P.Locked = true
  32. P.FormFactor = "Custom"
  33. P.Size = size
  34. P.Anchored = false
  35. P.BrickColor = BrickColor.new(color)
  36. P.Transparency = tra
  37. P.CanCollide = can
  38. P.TopSurface = 0
  39. P.BottomSurface = 0
  40. P:BreakJoints()
  41. return P
  42. end
  43. function w(par,p0,p1,cfz,typ)
  44. local W = Instance.new("Weld",par)
  45. W.Part0 = p0
  46. W.Part1 = p1
  47. if typ == true then
  48. W.C1 = cfz
  49. else
  50. W.C0 = cfz
  51. end
  52. return W
  53. end
  54. function mesh(par,id,tex,typ,scal)
  55. local M = Instance.new("SpecialMesh",par)
  56. M.MeshId = id
  57. M.TextureId = tex
  58. M.MeshType = typ
  59. M.Scale = scal
  60. return M
  61. end
  62. function fj(lim,tor,cf1)
  63. local w1 = w(Main,tor,lim,cf1)
  64. w1.C1 = cf(0,.5,0)
  65. return w1
  66. end
  67. function DamageFunc(hit,Damage,timz)
  68. local hum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
  69. if hum and not hum:FindFirstChild("Dmgz:"..Player.Name) and hit.Parent ~= Char and hit.Parent ~= Workspace and Damage and timz then
  70. hum.Health = hum.Health-Damage
  71. local a = Instance.new("StringValue",hum)a.Name = "Dmgz:"..Player.Name
  72. game.Debris:AddItem(a,timz)
  73. local b = Instance.new("ObjectValue",hum)b.Name = "creator" b.Value = Player
  74. game.Debris:AddItem(b,10)
  75. if hum.Health <=0 then return true else return false end -- To see if he died or not.
  76. end
  77. end
  78. function lerp(a,b,c)return a+(b-a)*c end
  79. function lerp2(a,b,c)return a*(1-c)+b*c end
  80. function clerp(c1,c2,al,x) --Smooth Animation!
  81. local com1 = {c1.X,c1.Y,c1.Z,c1:toEulerAnglesXYZ()}local com2 = {c2.X,c2.Y,c2.Z,c2:toEulerAnglesXYZ()}
  82. for i,v in pairs(com1) do if x == true then com1[i] = lerp2(v,com2[i],al) else com1[i] = lerp(v,com2[i],al)end end
  83. return CFrame.new(com1[1],com1[2],com1[3]) * CFrame.Angles(select(4,unpack(com1)))
  84. end
  85. RaW = fj(Ra,Torso,cf(1.5,.5,0)*ca(mr(35),mr(0),mr(0)) )
  86. Handle = part(Main,v3(.2,.2,.2),0,1,false)HandleW = w(Handle,Ra,Handle,cf(0,-1,0)*ca(mr(-135),0,0))
  87. local staff = part(Main,v3(.2,5,.2),"Brown",0,false)w(staff,Handle,staff,cf(0,-.5,0))inst("CylinderMesh",staff)
  88. local p = part(Main,v3(.25,2,.25),"Nougat",0,false)w(p,staff,p,cf(0,.5,0))inst("CylinderMesh",p)
  89. local p = part(Main,v3(0,0,0),"Nougat",0,false)w(p,staff,p,cf(0,1.5,0)*ca(mr(90),0,0))mesh(p,http.."3270017","","FileMesh",v3(.25,.25,.25))
  90. local p = part(Main,v3(0,0,0),"Nougat",0,false)w(p,staff,p,cf(0,-.5,0)*ca(mr(90),0,0))mesh(p,http.."3270017","","FileMesh",v3(.25,.25,.25))
  91. local ring = part(Main,v3(0,0,0),"Silver",0,false)w(ring,staff,ring,cf(0,-2.75,0)*ca(0,mr(90),0))mesh(ring,http.."3270017","","FileMesh",v3(.75,.5,2))
  92. local p = part(Main,v3(.25,.25,.25),"Silver",0,false)w(p,staff,p,cf(0,-2.5+(.25/2),0))inst("CylinderMesh",p)
  93. local p = part(Main,v3(0,0,0),"Silver",0,false)w(p,staff,p,cf(0,-2.25,0)*ca(mr(90),0,0))mesh(p,http.."3270017","","FileMesh",v3(.25,.25,.25))
  94. local p = part(Main,v3(.25,1,.25),"Silver",0,false)w(p,staff,p,cf(0,-1.5,0))inst("CylinderMesh",p)
  95. local p = part(Main,v3(0,0,0),"Silver",0,false)w(p,staff,p,cf(0,-2,0)*ca(mr(90),0,0))mesh(p,http.."3270017","","FileMesh",v3(.25,.25,.25))
  96. local p = part(Main,v3(0,0,0),"Silver",0,false)w(p,staff,p,cf(0,-1,0)*ca(mr(90),0,0))mesh(p,http.."3270017","","FileMesh",v3(.25,.25,.25))
  97. --A bit below tip
  98. local p = part(Main,v3(.25,.5,.25),"Silver",0,false)w(p,staff,p,cf(0,2.55,.25/2)*ca(mr(180),0,0))mesh(p,"","","Wedge",v3(1,1,1))
  99. local p = part(Main,v3(.25,.5,.25),"Silver",0,false)w(p,staff,p,cf(0,2.55,-.25/2)*ca(mr(180),mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  100. local p = part(Main,v3(.25,.35,.35),"Silver",0,false)w(p,staff,p,cf(0,2.6,.35/2)*ca(mr(180),0,0))mesh(p,"","","Wedge",v3(1,1,1))
  101. local p = part(Main,v3(.25,.35,.35),"Silver",0,false)w(p,staff,p,cf(0,2.6,-.35/2)*ca(mr(180),mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  102. local p = part(Main,v3(.25,.25,.5),"Silver",0,false)w(p,staff,p,cf(0,2.675,.25)*ca(mr(180),0,0))mesh(p,"","","Wedge",v3(1,1,1))
  103. local p = part(Main,v3(.25,.25,.5),"Silver",0,false)w(p,staff,p,cf(0,2.675,-.25)*ca(mr(180),mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  104. local p = part(Main,v3(.25,.3,.5),"Silver",0,false)w(p,staff,p,cf(0,2.95,-.25)*ca(0,mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  105. local p = part(Main,v3(.25,.3,.5),"Silver",0,false)w(p,staff,p,cf(0,2.95,.25))mesh(p,"","","Wedge",v3(1,1,1))
  106. local p = part(Main,v3(.25,.4,.4),"Silver",0,false)w(p,staff,p,cf(0,3,-.3)*ca(0,mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  107. local p = part(Main,v3(.25,.4,.4),"Silver",0,false)w(p,staff,p,cf(0,3,.3))mesh(p,"","","Wedge",v3(1,1,1))
  108. local p = part(Main,v3(.25,.5,.3),"Silver",0,false)w(p,staff,p,cf(0,3.05,-.35)*ca(0,mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  109. local p = part(Main,v3(.25,.5,.3),"Silver",0,false)w(p,staff,p,cf(0,3.05,.35))mesh(p,"","","Wedge",v3(1,1,1))
  110. --Tip
  111. local p = part(Main,v3(.2,1,.4),"Silver",0,false)w(p,staff,p,cf(0,3.25,0))
  112. local p = part(Main,v3(.2,.25,.25),"Silver",0,false)w(p,staff,p,cf(0,3.625,.3)*ca(mr(180),0,0))mesh(p,"","","Wedge",v3(1,1,1))
  113. local p = part(Main,v3(.2,.25,.25),"Silver",0,false)w(p,staff,p,cf(0,3.625,-.3)*ca(mr(180),mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  114. local p = part(Main,v3(.2,1,.25),"Silver",0,false)w(p,staff,p,cf(0,4.25,.3))
  115. local p = part(Main,v3(.2,1,.25),"Silver",0,false)w(p,staff,p,cf(0,4.25,-.3))
  116. local p = part(Main,v3(.2,.25,.425),"Silver",0,false)w(p,staff,p,cf(0,4.875,.2125)*ca(0,mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  117. local p = part(Main,v3(.2,.25,.425),"Silver",0,false)w(p,staff,p,cf(0,4.875,-.2125))mesh(p,"","","Wedge",v3(1,1,1))
  118. local p = part(Main,v3(.2,.5,.325),"Silver",0,false)w(p,staff,p,cf(0,5,.16)*ca(0,mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  119. local p = part(Main,v3(.2,.5,.325),"Silver",0,false)w(p,staff,p,cf(0,5,-.16))mesh(p,"","","Wedge",v3(1,1,1))
  120. local p = part(Main,v3(.2,.75,.275),"Silver",0,false)w(p,staff,p,cf(0,5.125,.2125/2+.025)*ca(0,mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  121. local p = part(Main,v3(.2,.75,.275),"Silver",0,false)w(p,staff,p,cf(0,5.125,-.2125/2-.025))mesh(p,"","","Wedge",v3(1,1,1))
  122. local p = part(Main,v3(.2,.25,.25),"Silver",0,false)w(p,staff,p,cf(0,3.875,.25/2))mesh(p,"","","Wedge",v3(1,1,1))
  123. local p = part(Main,v3(.2,.25,.25),"Silver",0,false)w(p,staff,p,cf(0,3.875,-.25/2)*ca(0,mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  124. local p = part(Main,v3(.2,.25,.25),"Silver",0,false)w(p,staff,p,cf(0,4.675,-.2/2)*ca(mr(180),0,0))mesh(p,"","","Wedge",v3(1,1,1))
  125. local p = part(Main,v3(.2,.25,.25),"Silver",0,false)w(p,staff,p,cf(0,4.675,.2/2)*ca(mr(180),mr(180),0))mesh(p,"","","Wedge",v3(1,1,1))
  126. hitbox = part(Main,v3(.3,3,1.25),"Silver",1,false)w(hitbox,staff,hitbox,cf(0,4,0))
  127. Hum.Running:connect(function(s)
  128. if s == 0 then
  129. Walking = false
  130. else
  131. Walking = true
  132. end
  133. end)
  134. --[[Hum.FreeFalling:connect(function(s)
  135. if s == true then
  136. FreeFalling = true
  137. else
  138. FreeFalling = false
  139. end
  140. end)]]
  141. local didHit = false
  142. Mouse.KeyDown:connect(function(Key)
  143. if Key == "q" and Attacking == false then
  144. didHit = true
  145. Attacking = true
  146. local aim = true
  147. local torbg = Instance.new("BodyGyro",Torso)
  148. torbg.cframe = cf(Torso.CFrame.p,v3(Mouse.Hit.p.x,Torso.CFrame.p.y,Mouse.Hit.p.z))
  149. torbg.maxTorque = v3()*math.huge
  150. torbg.D = 0
  151. torbg.P = 50000
  152. cw(function()
  153. while aim do
  154. wait(.02)
  155. torbg.cframe = cf(Torso.CFrame.p,v3(Mouse.Hit.p.x,Torso.CFrame.p.y,Mouse.Hit.p.z))
  156. end
  157. torbg:Destroy()
  158. end)()
  159. for i = 0,5 do
  160. wait(.02)
  161. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(170),0,mr(0)),.5)
  162. HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),0,mr(180)),.5)
  163. end
  164. wait(.05)
  165. cw(function()
  166. wait(.2)
  167. local handlecf = Handle.CFrame
  168. local Hit = Mouse.Hit.p
  169. HandleW.Part0 = nil
  170. Handle.Anchored = true
  171. Handle.CFrame = cf(handlecf.p,Hit)*ca(mr(-90),0,0)
  172. didHit = false
  173. local typez = false
  174. local pos = v3()
  175. local hit = nil
  176. local d = 0
  177. cw(function()
  178. repeat wait(.002)
  179. local r = Ray.new(Handle.CFrame.p,(Hit-Handle.CFrame.p).unit*10)
  180. local h,p = workspace:FindPartOnRay(r,Char)
  181. local dis = (Handle.CFrame.p-p).magnitude
  182. --local P=part(Workspace,v3(1,1,1),"Silver",0,false)P.Anchored = true P.CFrame = cf(p)
  183. if h ~= nil and dis >= .5 then
  184. didHit = true
  185. pos = p
  186. hit = h
  187. typez = true
  188. end
  189. until didHit == true
  190. end)()
  191. local x = 0
  192. local distance = ((Ra.CFrame*cf(0,-1,0)).p-ring.Position).magnitude
  193. local p = part(Main,v3(.2,.2,distance),"Silver",0,false)p.Anchored = true p.CFrame = cf((Ra.CFrame*cf(0,-1,0)).p,ring.Position)*cf(0,-.2,-distance/2)
  194. cw(function()
  195. while Attacking == true and p ~= nil do
  196. wait(.02)
  197. distance = ((Ra.CFrame*cf(0,-1,0)).p-ring.Position).magnitude
  198. p.Size=v3(.2,.2,distance)
  199. p.CFrame = cf((Ra.CFrame*cf(0,-1,0)).p,ring.Position)*cf(0,-.25,-distance/2)
  200. end
  201. p:Destroy()
  202. end)()
  203. for i = 0,500,2 do
  204. if d == 3 then
  205. wait(.02)
  206. d = 0
  207. end
  208. d = d + 1
  209. x = x-.1
  210. Handle.CFrame = cf(handlecf.p,Hit)*ca(mr(-90),0,0)*cf(0,i,0)
  211. if didHit == true then break end
  212. end
  213. didHit = false
  214. aim = false
  215. if typez == true and hit~=nil then
  216. local cfz = cf(pos,(Handle.CFrame*cf(0,-10,0)).p)*ca(math.pi/2,0,0)*cf(0,-3,0)
  217. Handle.Anchored = false
  218. local we = w(Handle,Handle,hit,cfz:toObjectSpace(hit.CFrame))
  219. local bp = Instance.new("BodyPosition",Torso)
  220. bp.position = ring.Position
  221. bp.maxForce = v3()*math.huge
  222. repeat wait()bp.position = ring.Position until didHit == true
  223. bp:Destroy()
  224. we:Destroy()
  225. Handle.Anchored = true
  226. end
  227. didHit = true
  228. for i = 0,20 do
  229. wait(.002)
  230. Handle.CFrame = clerp(Handle.CFrame,Ra.CFrame*cf(0,-1,0)*ca(mr(-90),0,0),.3)
  231. end
  232. wait(.2)
  233. Handle.Anchored = false
  234.  
  235. HandleW.Part0 = Ra
  236. HandleW.C0 = cf(0,-1,0)*ca(mr(-90),0,0)
  237. Attacking = false
  238. end)()
  239. for i = 0,5 do
  240. wait(.02)
  241. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(-45),0,mr(0)),.5)
  242. --HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),mr(180),0),.5)
  243. end
  244. aim = false
  245. wait(1)
  246. for i = 0,5 do
  247. wait(.02)
  248. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(100),0,mr(0)),.5)
  249. --HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),mr(180),0),.5)
  250. end
  251. end
  252. end)
  253. Mouse.Button1Down:connect(function()
  254. didHit = true
  255. if Attacking == false then
  256. Attacking = true
  257. local aim = true
  258. local torbg = Instance.new("BodyGyro",Torso)
  259. torbg.cframe = cf(Torso.CFrame.p,v3(Mouse.Hit.p.x,Torso.CFrame.p.y,Mouse.Hit.p.z))
  260. torbg.maxTorque = v3()*math.huge
  261. torbg.D = 0
  262. torbg.P = 50000
  263. cw(function()
  264. while aim do
  265. wait(.02)
  266. torbg.cframe = cf(Torso.CFrame.p,v3(Mouse.Hit.p.x,Torso.CFrame.p.y,Mouse.Hit.p.z))
  267. end
  268. torbg:Destroy()
  269. end)()
  270. for i = 0,5 do
  271. wait(.02)
  272. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(170),0,mr(0)),.5)
  273. HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),0,mr(180)),.5)
  274. end
  275. wait(.05)
  276. cw(function()
  277. wait(.2)
  278. local handlecf = Handle.CFrame
  279. local Hit = Mouse.Hit.p
  280. HandleW.Part0 = nil
  281. Handle.Anchored = true
  282. Handle.CFrame = cf(handlecf.p,Hit)*ca(mr(-90),0,0)
  283. didHit = false
  284. local typez = false
  285. local pos = v3()
  286. local hit = nil
  287. local d = 0
  288. cw(function()
  289. repeat wait(.002)
  290. local r = Ray.new(Handle.CFrame.p,(Hit-Handle.CFrame.p).unit*10)
  291. local h,p = workspace:FindPartOnRay(r,Char)
  292. local dis = (Handle.CFrame.p-p).magnitude
  293. --local P=part(Workspace,v3(1,1,1),"Silver",0,false)P.Anchored = true P.CFrame = cf(p)
  294. if h ~= nil and dis >= .5 then
  295. didHit = true
  296. pos = p
  297. hit = h
  298. typez = true
  299. end
  300. until didHit == true
  301. end)()
  302. local x = 0
  303. for i = 0,500,2 do
  304. if d == 3 then
  305. wait(.02)
  306. d = 0
  307. end
  308. d = d + 1
  309. x = x-.01
  310. Handle.CFrame = cf(handlecf.p,Hit)*ca(mr(-90),0,0)*cf(0,i,0)
  311. Hit = Hit+v3(0,x,0)
  312. if didHit == true then break end
  313. end
  314. didHit = false
  315. aim = false
  316. if typez == true and hit~=nil then
  317. local cfz = cf(pos,(Handle.CFrame*cf(0,-10,0)).p)*ca(math.pi/2,0,0)*cf(0,-3,0)
  318. Handle.Anchored = false
  319. local we = w(Handle,Handle,hit,cfz:toObjectSpace(hit.CFrame))
  320. DamageFunc(hit,ThrowDamage,.1)
  321. for i = 0,10,.1 do
  322. wait(.1)
  323. if didHit == true or hit == nil then
  324. break
  325. else
  326. local x = DamageFunc(hit,math.random(2,5),0)
  327. if x == true then
  328. didHit = true
  329. end
  330. end
  331. end
  332. we:Destroy()
  333. Handle.Anchored = true
  334. end
  335. didHit = true
  336. for i = 0,30 do
  337. wait(.002)
  338. Handle.CFrame = clerp(Handle.CFrame,Ra.CFrame*cf(0,-1,0)*ca(mr(-90),0,0),.2)
  339. end
  340. wait(.2)
  341. Handle.Anchored = false
  342.  
  343. HandleW.Part0 = Ra
  344. HandleW.C0 = cf(0,-1,0)*ca(mr(-90),0,0)
  345. Attacking = false
  346. end)()
  347. for i = 0,5 do
  348. wait(.02)
  349. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(-45),0,mr(0)),.5)
  350. --HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),mr(180),0),.5)
  351. end
  352. aim = false
  353. wait(1)
  354. for i = 0,5 do
  355. wait(.02)
  356. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(100),0,mr(0)),.5)
  357. --HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),mr(180),0),.5)
  358. end
  359. end
  360. end)
  361. cw(function()
  362. while true do
  363. wait(.02)
  364. if Attacking == false then
  365. if Walking == true then
  366. for i = 0,5 do
  367. wait(.02)
  368. if Walking == false or Attacking == true then break end
  369. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(0),0,mr(20)),.5)
  370. HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-135),0,0),.5)
  371. end
  372. repeat wait() until Walking == false or Attacking == true
  373. else
  374. if FreeFalling == true then
  375. for i = 0,5 do
  376. wait(.02)
  377. if Hum.Jump == false or Attacking == true then break end
  378. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(0),0,mr(100)),.5)
  379. HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-100),0,0),.5)
  380. end
  381. repeat wait() until FreeFalling == false or Attacking == true
  382. elseif Hum.Jump == true then
  383. for i = 0,5 do
  384. wait(.02)
  385. if Hum.Jump == false or Attacking == true then break end
  386. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(0),0,mr(30)),.5)
  387. HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),0,0),.5)
  388. end
  389. repeat wait() until Hum.Jump == false or FreeFalling == true or Attacking == true
  390. else
  391. for i = 0,10 do
  392. wait(.02)
  393. if Walking == true or Attacking == true then break end
  394. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(100),0,mr(5)),.4)
  395. HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),0,0),.4)
  396. end
  397. for i = 0,20 do
  398. wait(.02)
  399. if Walking == true or Attacking == true then break end
  400. RaW.C0 = clerp(RaW.C0,cf(1.5,.5,0)*ca(mr(90),0,mr(5)),.2)
  401. HandleW.C0 = clerp(HandleW.C0,cf(0,-1,0)*ca(mr(-90),0,0),.2)
  402. end
  403. repeat wait() until Walking == true or Attacking == true or Hum.Jump == true or FreeFalling == true
  404. end
  405. end
  406. end
  407. end
  408. end)()
Add Comment
Please, Sign In to add comment