wulfbawg

Simple Rocket Launcher - RBXLUA

Jun 30th, 2014
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.37 KB | None | 0 0
  1. -- > Made by wulfbug9
  2. -- > Simple rocket launcher.
  3. function Random(R) return (math.random()-.5)*2*(R or 1) end
  4. function Create(Data)
  5.     local Obj = Instance.new(Data[1])
  6.     table.remove(Data,1)
  7.     for i,v in pairs(Data)do
  8.         Obj[i] = v
  9.     end
  10.     return Obj
  11. end
  12. function C(Func,Args)
  13.     return coroutine.resume(coroutine.create(Func),unpack(Args or {}))
  14. end
  15. ------------------------------------------------------------------------
  16. function Part(Parent,Size,CFrame,Anchored,CanCollide,Colour,Trans,Material)
  17.     local Part = Instance.new("Part",Parent)
  18.     Part.FormFactor = "Custom"
  19.     Part.Anchored = Anchored
  20.     Part.CanCollide = CanCollide
  21.     Part.Size = Size
  22.     Part.CFrame = CFrame
  23.     Part.BrickColor = BrickColor.new(Colour)
  24.     Part.Transparency = Trans
  25.     Part.Material = Material
  26.     Part.TopSurface,Part.BottomSurface = 0,0
  27.     Part:BreakJoints()
  28.     Part.Velocity = Vector3.new(0,0,0)
  29.     Part.Locked = true
  30.     return Part
  31. end
  32. function Weld(p1,p2,c0,c1)
  33.     local w = Instance.new("Weld",p1)w.Part0 = p1;w.Part1 = p2
  34.     w.C0,w.C1 = c0 or CFrame.new(),c1 or CFrame.new()
  35.     return w
  36. end
  37. Tween = {}
  38. function slerp(a,b,c)return (1-c)*a+(c*b)end
  39. function cslerp(start,destination,increment)
  40.     local c1 = {start.X,start.Y,start.Z,start:toEulerAnglesXYZ()}
  41.     local c2 = {destination.X,destination.Y,destination.Z,destination:toEulerAnglesXYZ()}
  42.     for i,v in pairs(c1)do c1[i] = slerp(v,c2[i],increment)end
  43.     return CFrame.new(c1[1],c1[2],c1[3])*CFrame.Angles(c1[4],c1[5],c1[6])
  44. end
  45. c0 = {
  46.     ls = CFrame.new(-.5,0.5,0);
  47.     rs = CFrame.new(.5,0.5,0);
  48. }
  49. c1 = {
  50.     ls = CFrame.new(0.5,0.5,0);
  51.     rs = CFrame.new(-0.5,0.5,0);
  52. }
  53. ------------------------------------------------------------------------
  54. Player = game:service("Players").LocalPlayer
  55. Mouse = Player:GetMouse()
  56. local Character
  57. repeat wait() Character = Player.Character until Character
  58. Shooting = false
  59. asset = "rbxassetid://"
  60. meshes = {["blast"] = 20329976,["ring"] = 3270017,["spike"] = 1033714,["cone"] = 1082802,["crown"] = 20329976,["cloud"] = 1095708,["diamond"] = 9756362}
  61. Camera = workspace.CurrentCamera
  62. RenderStepped = game:service("RunService").RenderStepped
  63. Torso = Character:WaitForChild("Torso")
  64. RArm = Character:WaitForChild("Right Arm")
  65. LArm = Character:WaitForChild("Left Arm")
  66. RLeg = Character:WaitForChild("Right Leg")
  67. LLeg = Character:WaitForChild("Left Leg")
  68. Head = Character:WaitForChild("Head")
  69. HRP = Character:WaitForChild("HumanoidRootPart")
  70. RS = Weld(Torso,RArm,c0.rs,c1.rs)
  71. LS = Weld(Torso,LArm,c0.ls,c1.ls)
  72. BG = Instance.new("BodyGyro",HRP)
  73. BG.maxTorque = Vector3.new(1,1,1)*10^6
  74. BG.P = 10^4
  75. local Tip
  76. ------------------------------------------------------------------------
  77. function Smoke(Origin)
  78.     local Part = Part(Character,Vector3.new(5,5,5),Origin*CFrame.new(Random(1),Random(1),Random(1)),true,false,"Grey",1,"Plastic")
  79.     local Mesh = Create{"SpecialMesh",Parent = Part,MeshType = "Sphere"}
  80.     C(function(P,M)
  81.         for i=1,0,-.1 do
  82.             P.CFrame = P.CFrame+(Origin*CFrame.Angles(0,math.pi,0)).lookVector
  83.             P.Transparency = i
  84.             wait()
  85.         end
  86.         for i=0,1,.025 do
  87.             P.CFrame = P.CFrame+(Origin*CFrame.Angles(0,math.pi,0)).lookVector
  88.             P.Transparency = i
  89.             M.Scale = M.Scale - Vector3.new(.025,.025,.025)
  90.             wait()
  91.         end
  92.         P:Destroy()
  93.     end,{Part,Mesh})
  94. end
  95. function findNearbyHumans(Origin,Distance)
  96.     local Found = {}
  97.     for i,v in pairs(workspace:children()) do
  98.         local Human;
  99.         local Torso;
  100.         if v:FindFirstChild("Torso") and v~=Character then
  101.             Torso = v:FindFirstChild("Torso")
  102.             for _,h in pairs(v:children())do if h:IsA("Humanoid") then Human = h end end
  103.             if Human then
  104.                 local D = (Origin.p - Torso.CFrame.p).magnitude
  105.                 if Distance >= D then
  106.                     table.insert(Found,{v,Torso,Human})
  107.                 end
  108.             end
  109.         end
  110.     end
  111.     return Found
  112. end
  113. function EXPLOD(Origin,Colour,Size)
  114.     local Part = Part(Character,Vector3.new(Size,Size,Size),Origin*CFrame.new(Random(1),Random(1),Random(1)),true,false,Colour,1,"Plastic")
  115.     local Mesh = Create{"SpecialMesh",Parent = Part,MeshType = "Sphere"}
  116.     C(function(P,M)
  117.         for i=1,0,-.1 do
  118.             P.Transparency = i
  119.             wait()
  120.         end
  121.         for i=0,1,.05 do
  122.             P.Transparency = i
  123.             M.Scale = M.Scale - Vector3.new(.05,.05,.05)
  124.             wait()
  125.         end
  126.         P:Destroy()
  127.     end,{Part,Mesh})
  128. end
  129. function Shoot(start,dmg)
  130.     dmg = dmg or 15
  131.     local vel = start.lookVector
  132.     local p = Part(Character,Vector3.new(.5,.5,3),start,true,false,"Grey",0,"DiamondPlate")
  133.     local num = 0
  134.     local ign = Character:children()
  135.     local connect
  136.     connect = RenderStepped:connect(function()
  137.         num = num + 1
  138.         local pp = p.Position
  139.         local h,po
  140.         vel = vel - Vector3.new(0,math.min(999.5,vel.magnitude/500),0)
  141.         repeat
  142.             local r = Ray.new(pp,vel.unit*math.min(999.5,vel.magnitude/100+2))
  143.             h,po = workspace:FindPartOnRayWithIgnoreList(r,ign)
  144.             if h then
  145.                 if h.CanCollide then break
  146.                 else table.insert(ign,h)h = nil
  147.                 end
  148.             else break
  149.             end
  150.         until false
  151.         if num%5==0 then Smoke(p.CFrame) end
  152.         p.CFrame = CFrame.new(po,po+vel)
  153.         if h or num > 300 then
  154.             local cf = p.CFrame
  155.             for i,v in pairs(findNearbyHumans(cf,10))do
  156.                 v[3].Health = v[3].Health - 25
  157.                 v[3].Sit = true
  158.                 v[2].Velocity = -(CFrame.new(v[2].CFrame.p,cf.p)).lookVector*100
  159.             end
  160.             local colurz = {"Bright red","Bright yellow","Bright orange"}
  161.             for i=1,math.random(3,6) do
  162.                 EXPLOD(cf,colurz[math.random(1,#colurz)],math.random(10,20))
  163.             end
  164.             p:Destroy()
  165.             connect:disconnect()
  166.         end
  167.     end)
  168. end
  169. function TakeShot()
  170.     Shooting = true
  171.     wait()
  172.     Shoot(Tip.CFrame*CFrame.Angles(0,-math.pi/2,0))
  173.     Torso.Velocity = -(Tip.CFrame*CFrame.Angles(0,-math.pi/2,0)).lookVector*100
  174.     wait(2)
  175.     Shooting = false
  176. end
  177. ------------------------------------------------------------------------
  178. pcall(function()Character:FindFirstChild("Rocket"):Destroy()end)
  179. Model = Create{"Model",Parent = Character,Name = "Rocket"}
  180. Handle = Part(Model,Vector3.new(2.5,0.5,0.5),Torso.CFrame,false,false,"Grey",0,"Plastic")
  181. HandleM = Create{"SpecialMesh",Parent = Handle,MeshType = "Cylinder"}
  182. HandleW = Weld(RArm,Handle,CFrame.new(0,0,-.75)*CFrame.Angles(math.pi/2,math.pi/2,math.pi))
  183. Tip = Part(Model,Vector3.new(.5,0.5,0.5),Torso.CFrame,false,false,"Bright red",0,"Plastic")
  184. TipM = Create{"SpecialMesh",Parent = Tip,MeshType = "Cylinder"}
  185. TipW = Weld(Handle,Tip,CFrame.new(2.5/2 + .25,0,0))
  186. Trig = Part(Model,Vector3.new(0.25,.75,.4),Torso.CFrame,false,false,"Grey",0,"Plastic")
  187. TrigW = Weld(Handle,Trig,CFrame.new(-1,-.25,0)*CFrame.Angles(0,0,-math.pi/8))
  188. Trig2 = Part(Model,Vector3.new(0.25,.75,.4),Torso.CFrame,false,false,"Grey",0,"Plastic")
  189. Trig2W = Weld(Handle,Trig2,CFrame.new(1,-.25,0))
  190. End = Part(Model,Vector3.new(.5,0.6,0.6),Torso.CFrame,false,false,"Black",0,"Plastic")
  191. EndM = Create{"SpecialMesh",Parent = End,MeshType = "Cylinder"}
  192. EndW = Weld(Handle,End,CFrame.new(-2.5/2 + .2,0,0))
  193. ------------------------------------------------------------------------
  194. Mouse.Button1Down:connect(function()
  195.     if Shooting then return end
  196.     TakeShot()
  197. end)
  198. RenderStepped:connect(function()
  199.     RS.C0 = c0.rs*CFrame.Angles(Torso.CFrame:toObjectSpace(CFrame.new((Torso.CFrame*RS.C0).p,Mouse.Hit.p)*CFrame.Angles(math.pi/2,0,0)):toEulerAnglesXYZ())
  200.     LS.C0 = c0.ls*CFrame.Angles(Torso.CFrame:toObjectSpace(CFrame.new((Torso.CFrame*LS.C0).p,Mouse.Hit.p)*CFrame.Angles(math.pi/2,0,math.pi/4)):toEulerAnglesXYZ())
  201.     BG.cframe = CFrame.new(CFrame.new(HRP.CFrame.x,HRP.CFrame.y,HRP.CFrame.z).p,CFrame.new(Camera.CoordinateFrame.x,HRP.CFrame.y,Camera.CoordinateFrame.z).p)*CFrame.Angles(0,math.pi,0)
  202. end)
Add Comment
Please, Sign In to add comment