Advertisement
astronaut32

grenade

Oct 7th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. local tool = Instance.new("Tool", game.Players.PabloRV.Backpack)
  2. local Launcher = Instance.new("Script",tool)Launcher.Name = "Launcher"
  3. Launcher.Source = [[Tool = script.Parent
  4. thrown = true
  5. VELOCITY = 40
  6.  
  7. function Nade()
  8. local model = Instance.new("Model")
  9. model.Name = "Nade"
  10. model.Parent = game.Workspace
  11. nade = Tool.Handle:clone()
  12. nade1 = Tool.Handle1:clone()
  13. nade2 = Tool.Handle2:clone()
  14. nade3 = Tool.Handle3:clone()
  15. nade.Parent = model
  16. nade1.Parent = model
  17. nade2.Parent = model
  18. nade3.Parent = model
  19. nade.CanCollide = true
  20. nade1.CanCollide = true
  21. nade2.CanCollide = true
  22. nade3.CanCollide = true
  23. local script = Tool.NadeScript:clone()
  24. script.Disabled = false
  25. script.Parent = nade
  26. return model
  27. end
  28.  
  29. function lob(mousepos)
  30. local vCharacter = Tool.Parent
  31. local vPlayer = game.Players:playerFromCharacter(vCharacter)
  32. local head = Tool:findFirstChild("Handle")
  33. if head == nil then return end
  34. local dir = mousepos - head.Position
  35. dir = computeDirection(dir)
  36. local launch = head.Position + 10 * dir
  37. local delta = mousepos - launch
  38. local dy = delta.y
  39. local new_delta = Vector3.new(delta.x, 0, delta.z)
  40. delta = new_delta
  41. local dx = delta.magnitude
  42. local unit_delta = delta.unit
  43. local g = (-9.81 * 20)
  44. local theta = computeLaunchAngle(dx, dy, g)
  45. local vy = math.sin(theta)
  46. local xz = math.cos(theta)
  47. local vx = unit_delta.x * xz
  48. local vz = unit_delta.z * xz
  49. local missile = Nade()
  50. missile.Handle.Position = launch
  51. missile.Handle.Velocity = Vector3.new(vx, vy, vz) * VELOCITY
  52. local creator_tag = Instance.new("ObjectValue")
  53. creator_tag.Value = vPlayer
  54. creator_tag.Name = "creator"
  55. creator_tag.Parent = missile.Handle
  56. end
  57.  
  58.  
  59. function computeLaunchAngle(dx, dy, grav)
  60. -- http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
  61. local g = math.abs(grav)
  62. local inRoot = (VELOCITY*VELOCITY*VELOCITY*VELOCITY) - (g * ((g*dx*dx) + (2*dy*VELOCITY*VELOCITY)))
  63. if inRoot <= 0 then
  64. return .25 * math.pi
  65. end
  66. local root = math.sqrt(inRoot)
  67. local inATan1 = ((VELOCITY*VELOCITY) + root) / (g*dx)
  68. local inATan2 = ((VELOCITY*VELOCITY) - root) / (g*dx)
  69. local answer1 = math.atan(inATan1)
  70. local answer2 = math.atan(inATan2)
  71. if answer1 < answer2 then return answer1 end
  72. return answer2
  73. end
  74.  
  75. function computeDirection(vec)
  76. local lenSquared = vec.magnitude * vec.magnitude
  77. local invSqrt = 1 / math.sqrt(lenSquared)
  78. return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
  79. end
  80.  
  81. function Weld(parentObj)
  82. local w1 = Instance.new("Weld")
  83. local w2 = Instance.new("Weld")
  84. local w3 = Instance.new("Weld")
  85. w1.Parent = parentObj.Handle
  86. w2.Parent = parentObj.Handle
  87. w3.Parent = parentObj.Handle
  88. w1.Part0 = w1.Parent
  89. w2.Part0 = w2.Parent
  90. w3.Part0 = w3.Parent
  91. w1.Part1 = parentObj.Handle1
  92. w2.Part1 = parentObj.Handle2
  93. w3.Part1 = parentObj.Handle3
  94. w1.C1 = CFrame.new(0, -0.5, 0)
  95. w2.C1 = CFrame.new(0, -0.6, 0)
  96. w3.C1 = CFrame.new(-0.2, -0.75,0)
  97.  
  98. end
  99.  
  100. function onThrow()
  101. if thrown == true then return end
  102. thrown = true
  103. local character = Tool.Parent
  104. local humanoid = character.Humanoid
  105. if humanoid == nil then return end
  106. local targetPos = humanoid.TargetPoint
  107. lob(targetPos)
  108. wait(5)
  109. thrown = false
  110. end
  111.  
  112. function onEquipped()
  113. Weld(Tool)
  114. end
  115.  
  116. function onUnequipped()
  117. Weld(Tool)
  118. end
  119.  
  120. thrown = false
  121.  
  122. Tool.Equipped:connect(onEquipped)
  123. Tool.Unequipped:connect(onUnequipped)
  124. Tool.Activated:connect(onThrow)
  125. Weld(Tool)]]
  126. local Nadescript = Instance.new("Script",tool)Nadescript.Name = "Nadescript"
  127. Nadescript.Source = [[flash = Instance.new("Part")
  128. flash.formFactor = "Symmetric"
  129. flash.Size = Vector3.new(1, 1, 1)
  130. flash.BrickColor = BrickColor.new(26)
  131. flash.Reflectance = 0.1
  132. flash.Anchored = true
  133. flash.Name = "Dot"
  134. flash.CanCollide = false
  135. mesh = Instance.new("SpecialMesh")
  136. mesh.Parent = flash
  137. mesh.MeshType = "Sphere"
  138. mesh.Scale = Vector3.new(0.5, 0.5, 0.5)
  139.  
  140. for i=1, 50 do
  141. wait(0.1)
  142. local dot = flash:clone()
  143. local Script2 = script.DotScript:clone()
  144. Script2.Disabled = false
  145. Script2.Parent = dot
  146. dot.Parent = game.Workspace
  147. dot.Position = script.Parent.Position
  148. end
  149.  
  150. local exp = Instance.new("Explosion")
  151. exp.Position = script.Parent.Position
  152. exp.Parent = game.Workspace
  153. script.Parent.Parent:remove()]]
  154. local Dotscript = Instance.new(script,Nadescript)Dotscript.Name = "Dotscript"
  155. Dotscript.Source = [[ script.Parent.Transparency = script.Parent.Transparency + 0.1
  156. wait(0.2)
  157. end
  158. script.Parent:remove()
  159. ]]
  160. local handle = Instance.new("Part",tool)tool.part.Name = ("Handle")handle.Brickcolor = BrickColor.new("Lime Green")
  161. Instance.new("Fire",handle) handle.Fire.Enabled = false
  162. Instance.new("TouchInterest", handle)
  163. Instance.new("Mesh",handle) handle.Mesh.Meshtype = ("Brick")handle.mesh.scale = Vector3.new (0.5, 1.0, 0.5)
  164. local handle1 = Instance.new("Part",tool)handle1.Name = ("Handle1")
  165. Instance.new("CylinderMesh",handle1)handle1.Mesh.scale = Vector3.new (0.5, 0.1, 1)
  166. Instance.new("Fire",handle1) handle1.Fire.Enabled = false
  167. local handle2 = Instance.new("Part",tool)handle2.Name = ("Handle2")
  168. Instance.new("CylinderMesh",handle2)handle2.Mesh = Vector3.new (0.3, 0.4, 1)
  169. local handle3 = Instance.new("Part",tool)handle3.Name = ("Handle3")
  170. Instance.new("SpecialMesh",handle3) handle3.Mesh.MeshType = ("Filemesh") handle3.Mesh.Meshid = ("http://www.roblox.com/asset/?id=3270017") handle3.Mesh.Scale = Vector3.new(0.2, 0.2, 0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement