Advertisement
Aaronremmers14

Grenade

May 28th, 2016
2,244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. Create = function(itemClass,tabl)
  2. local item = Instance.new(itemClass)
  3. for i,v in pairs(tabl) do
  4. local a,b = ypcall(function() return item[i] end)
  5. if a then
  6. item[i] = tabl[i]
  7. end
  8. end
  9. return item
  10. end
  11. function runDummyScript(f,scri)
  12. local oldenv = getfenv(f)
  13. local newenv = setmetatable({}, {
  14. __index = function(_, k)
  15. if k:lower() == 'script' then
  16. return scri
  17. else
  18. return oldenv[k]
  19. end
  20. end
  21. })
  22. setfenv(f, newenv)
  23. ypcall(function() f() end)
  24. end
  25. cors = {}
  26. mas = Instance.new("Model",game:GetService("Lighting"))
  27. mas.Name = "CompiledModel"
  28. o1 = Create("Tool",{
  29. ["Name"] = "Grenade",
  30. ["Parent"] = mas,
  31. ["TextureId"] = "http://www.roblox.com/asset/?id=200845119",
  32. ["GripForward"] = Vector3.new(0.447173357, -0.0044717337, -0.894436121),
  33. ["GripPos"] = Vector3.new(0, 0, 0.200000003),
  34. ["GripRight"] = Vector3.new(0.894391418, -0.00894391444, 0.447195709),
  35. ["GripUp"] = Vector3.new(0.00999950059, 0.999949992, 0),
  36. ["ToolTip"] = "KABOOM",
  37. })
  38. o2 = Create("Part",{
  39. ["Name"] = "Handle",
  40. ["Parent"] = o1,
  41. ["BrickColor"] = BrickColor.new("Earth green"),
  42. ["Position"] = Vector3.new(-28.3999996, 2.46000004, 37.4000015),
  43. ["Rotation"] = Vector3.new(0, 90, 0),
  44. ["CFrame"] = CFrame.new(-28.3999996, 2.46000004, 37.4000015, 0, 0, 1, 0, 1, 0, -1, 0, 0),
  45. ["CanCollide"] = false,
  46. ["Locked"] = true,
  47. ["FormFactor"] = Enum.FormFactor.Custom,
  48. ["Size"] = Vector3.new(0.800000131, 0.920000255, 0.799998164),
  49. ["BottomSurface"] = Enum.SurfaceType.Smooth,
  50. ["TopSurface"] = Enum.SurfaceType.Smooth,
  51. ["Color"] = Color3.new(0.152941, 0.27451, 0.176471),
  52. })
  53. o3 = Create("SpecialMesh",{
  54. ["Parent"] = o2,
  55. ["MeshId"] = "http://www.roblox.com/asset/?id=166887416",
  56. ["Scale"] = Vector3.new(1.29999995, 1.5, 1.29999995),
  57. ["MeshType"] = Enum.MeshType.FileMesh,
  58. })
  59. o4 = Create("Sound",{
  60. ["Name"] = "Pin",
  61. ["Parent"] = o2,
  62. ["SoundId"] = "http://www.roblox.com/asset?id=168184001",
  63. ["Volume"] = 1,
  64. })
  65. o5 = Create("Sound",{
  66. ["Name"] = "Boom",
  67. ["Parent"] = o2,
  68. ["SoundId"] = "rbxasset://sounds/collide.wav",
  69. ["Volume"] = 1,
  70. ["PlayOnRemove"] = true,
  71. })
  72. o7 = Create("Animation",{
  73. ["Name"] = "ThrowAnimation",
  74. ["Parent"] = o1,
  75. ["AnimationId"] = "http://www.roblox.com/Asset?ID=168160500",
  76. })
  77. o8 = Create("Configuration",{
  78. ["Name"] = "Configurations",
  79. ["Parent"] = o1,
  80. })
  81. o9 = Create("NumberValue",{
  82. ["Name"] = "Cooldown",
  83. ["Parent"] = o8,
  84. ["Value"] = 3,
  85. })
  86. o10 = Create("NumberValue",{
  87. ["Name"] = "GrenadeVelocity",
  88. ["Parent"] = o8,
  89. ["Value"] = 100,
  90. })
  91. o11 = Create("NumberValue",{
  92. ["Name"] = "FuseTime",
  93. ["Parent"] = o8,
  94. ["Value"] = 5,
  95. })
  96. o12 = Create("BoolValue",{
  97. ["Name"] = "ExplodeOnTouch",
  98. ["Parent"] = o8,
  99. ["Value"] = true,
  100. })
  101. o13 = Create("NumberValue",{
  102. ["Name"] = "ExplosionRadius",
  103. ["Parent"] = o8,
  104. ["Value"] = 5,
  105. })
  106. o15 = Create("RemoteEvent",{
  107. ["Name"] = "Throw",
  108. ["Parent"] = o1,
  109. })
  110. o16 = Create("Script",{
  111. ["Name"] = "ServerScript",
  112. ["Parent"] = o1,
  113. })
  114. table.insert(cors,coroutine.create(function()
  115. wait()
  116. runDummyScript(function()
  117. local tool = script.Parent
  118. local config = tool:WaitForChild("Configurations")
  119.  
  120. -- Uber l33t maths to calcluate the angle needed to throw a projectile a distance, given the altitude of the end point and the projectile's velocity
  121. function AngleOfReach(distance, altitude, velocity)
  122. local theta = math.atan((velocity^2 + math.sqrt(velocity^4 -196.2*(196.2*distance^2 + 2*altitude*velocity^2)))/(196.2*distance))
  123. if theta ~= theta then
  124. theta = math.pi/4
  125. end
  126. return(theta)
  127. end
  128.  
  129. -- A simple function to explode a specified part
  130. function Explode(part)
  131. local explosion = Instance.new("Explosion", workspace)
  132. explosion.Position = part.Position
  133. explosion.BlastRadius = config.ExplosionRadius.Value
  134. part:Destroy()
  135. end
  136.  
  137. script.Parent.Throw.OnServerEvent:connect(function(player, mousePosition)
  138. local handlePos = Vector3.new(tool.Handle.Position.X, 0, tool.Handle.Position.Z) -- remove Y from the equation, it's not needed
  139. local mousePos = Vector3.new(mousePosition.X, 0, mousePosition.Z) -- ditto
  140. local distance = (handlePos - mousePos).magnitude -- Get the distance between the handle and the mouse
  141. local altitude = mousePosition.Y - tool.Handle.Position.Y
  142. local angle = AngleOfReach(distance, altitude, config.GrenadeVelocity.Value) -- Calculate the angle
  143.  
  144. tool.Handle.Transparency = 1
  145. local grenade = tool.Handle:Clone()
  146. grenade.Parent = workspace
  147. grenade.Transparency = 0
  148. grenade.CanCollide = true
  149. grenade.CFrame = tool.Handle.CFrame
  150. grenade.Velocity = (CFrame.new(grenade.Position, Vector3.new(mousePosition.X, grenade.Position.Y, mousePosition.Z)) * CFrame.Angles(angle, 0, 0)).lookVector * config.GrenadeVelocity.Value -- Throwing 'n stuff, it probably didn't need to be this long
  151. spawn(function()
  152. if config.ExplodeOnTouch.Value then
  153. grenade.Touched:connect(function(hit)
  154. if hit.Parent ~= tool.Parent and hit.CanCollide then -- Make sure what we're hitting is collidable
  155. Explode(grenade)
  156. end
  157. end)
  158. else
  159.  
  160. wait(config.FuseTime.Value)
  161. Explode(grenade)
  162. end
  163. end)
  164. wait(config.Cooldown.Value)
  165. tool.Handle.Transparency = 0
  166. end)
  167. end,o16)
  168. end))
  169. mas.Parent = workspace
  170. mas:MakeJoints()
  171. local mas1 = mas:GetChildren()
  172. for i=1,#mas1 do
  173. mas1[i].Parent = script
  174. ypcall(function() mas1[i]:MakeJoints() end)
  175. end
  176. mas:Destroy()
  177. for i=1,#cors do
  178. coroutine.resume(cors[i])
  179. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement