Facebook
From Billwa, 9 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 432
  1. grenade = Instance.new("Tool")
  2. grenade.Parent = game.Players.meunumbertwo.Backpack
  3. grenade.GripPos = Vector3.new(0,0,0.20000000298023)
  4. grenade.Grip = CFrame.new(0,0,0.20000000298023) * CFrame.Angles(-0.0049994587898254, -0.46360263228416, -0.011179762892425)
  5. grenade.TextureId = "http://www.roblox.com/asset/?id=200845119"
  6. grenade.GripForward = Vector3.new(0.44717335700989,-0.004471733700484,-0.89443612098694)
  7. grenade.Name = "Grenade"
  8. grenade.GripRight = Vector3.new(0.89439141750336,-0.0089439144358039,0.44719570875168)
  9. grenade.GripUp = Vector3.new(0.0099995005875826,0.99994999170303,0)
  10. grenade.ToolTip = "KABOOM"
  11.  
  12. handle = Instance.new("Part",grenade)
  13. handle.FormFactor = Enum.FormFactor.Custom
  14. handle.TopSurface = Enum.SurfaceType.Smooth
  15. handle.Size = Vector3.new(0.80000013113022,0.92000025510788,0.79999816417694)
  16. handle.Name = "Handle"
  17. handle.Locked = true
  18. handle.CFrame = CFrame.new(-25.705892562866,0.38461595773697,7.3462233543396) * CFrame.Angles(1.5769363641739, -0.0078776096925139, 2.243584394455)
  19. handle.BrickColor = BrickColor.new("Earth green")
  20. handle.Friction = 0.30000001192093
  21. handle.BottomSurface = Enum.SurfaceType.Smooth
  22.  
  23. mesh = Instance.new("SpecialMesh",handle)
  24. mesh.Scale = Vector3.new(1.2999999523163,1.5,1.2999999523163)
  25. mesh.MeshId = "http://www.roblox.com/asset/?id=166887416"
  26. mesh.MeshType = Enum.MeshType.FileMesh
  27.  
  28. pin = Instance.new("Sound",handle)
  29. pin.Name = "Pin"
  30. pin.Volume = 1
  31. pin.SoundId = "http://www.roblox.com/asset?id=168184001"
  32.  
  33. boom = Instance.new("Sound",handle)
  34. boom.Name = "Boom"
  35. boom.Volume = 1
  36. boom.SoundId = "rbxasset://sounds/collide.wav"
  37. boom.PlayOnRemove = true
  38.  
  39. throwanimation = Instance.new("Animation",grenade)
  40. throwanimation.AnimationId = "http://www.roblox.com/Asset?ID=168160500"
  41. throwanimation.Name = "ThrowAnimation"
  42.  
  43. configurations = Instance.new("Configuration",grenade)
  44. configurations.Name = "Configurations"
  45.  
  46. cooldown = Instance.new("NumberValue",configurations)
  47. cooldown.Name = "Cooldown"
  48. cooldown.Value = 3
  49.  
  50. grenadevelocity = Instance.new("NumberValue",configurations)
  51. grenadevelocity.Name = "GrenadeVelocity"
  52. grenadevelocity.Value = 100
  53.  
  54. fusetime = Instance.new("NumberValue",configurations)
  55. fusetime.Name = "FuseTime"
  56. fusetime.Value = 5
  57.  
  58. explodeontouch = Instance.new("BoolValue",configurations)
  59. explodeontouch.Name = "ExplodeOnTouch"
  60. explodeontouch.Value = true
  61.  
  62. explosionradius = Instance.new("NumberValue",configurations)
  63. explosionradius.Name = "ExplosionRadius"
  64. explosionradius.Value = 5
  65.  
  66. throw = Instance.new("RemoteEvent",grenade)
  67. throw.Name = "Throw"
  68.  
  69. local player = game.Players.LocalPlayer
  70. local mouse = player:GetMouse()
  71. local tool = grenade
  72. local config = tool:WaitForChild("Configurations")
  73.  
  74. local canThrow = true
  75.  
  76. tool.Equipped:connect(function()
  77.         mouse.Icon = "rbxasset://textures/GunCursor.png"
  78. end)
  79.  
  80. tool.Unequipped:connect(function()
  81.         mouse.Icon = ""
  82. end)
  83.  
  84. tool.Activated:connect(function()
  85.         if canThrow then
  86.                 canThrow = false
  87.                 local throwAnimation = player.Character.Humanoid:LoadAnimation(tool.ThrowAnimation)
  88.                 throwAnimation:Play() -- Load and play the throwing animation
  89.                 throwAnimation.KeyframeReached:connect(function(keyframe) -- Wait 'til we reach a keyframe
  90.                         if keyframe == "tick" then -- if the keyframe is 'tick' then play the pin sound
  91.                                 tool.Handle.Pin:Play()
  92.                         elseif keyframe == "throw" then -- otherwise, if it's 'throw,' tell the serverscript to throw our grenade
  93.                                 tool.Throw:FireServer(mouse.Hit.p)
  94.                                 throwAnimation:Stop()
  95.                                 mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
  96.                         end
  97.                 end)
  98.                 wait(config.Cooldown.Value)
  99.                 mouse.Icon = "rbxasset://textures/GunCursor.png"
  100.                 canThrow = true
  101.         end
  102. end)
  103.  
  104. grenade.Activated:connect(onActivated)
  105.  
  106. local tool = grenade
  107. local config = tool:WaitForChild("Configurations")
  108.  
  109.  
  110. function AngleOfReach(distance, altitude, velocity)
  111.         local theta = math.atan((velocity^2 + math.sqrt(velocity^4 -196.2*(196.2*distance^2 + 2*altitude*velocity^2)))/(196.2*distance))
  112.         if theta ~= theta then
  113.                 theta = math.pi/4
  114.         end
  115.         return(theta)
  116. end
  117.  
  118.  
  119. function Explode(part)
  120.         local explosion = Instance.new("Explosion", workspace)
  121.         explosion.Position = part.Position
  122.         explosion.BlastRadius = config.ExplosionRadius.Value
  123.         part:Destroy()
  124. end
  125.  
  126. grenade.Throw.OnServerEvent:connect(function(player, mousePosition)
  127.         local handlePos = Vector3.new(tool.Handle.Position.X, 0, tool.Handle.Position.Z) -- remove Y from the equation, it's not needed
  128.         local mousePos = Vector3.new(mousePosition.X, 0, mousePosition.Z) -- ditto
  129.         local distance = (handlePos - mousePos).magnitude -- Get the distance between the handle and the mouse
  130.         local altitude = mousePosition.Y - tool.Handle.Position.Y
  131.         local angle = AngleOfReach(distance, altitude, config.GrenadeVelocity.Value) -- Calculate the angle
  132.        
  133.         tool.Handle.Transparency = 1
  134.         local grenade = tool.Handle:Clone()
  135.         grenade.Parent = workspace
  136.         grenade.Transparency = 0
  137.         grenade.CanCollide = true
  138.         grenade.CFrame = tool.Handle.CFrame
  139.         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
  140.         spawn(function()
  141.         if config.ExplodeOnTouch.Value then
  142.                 grenade.Touched:connect(function(hit)
  143.                         if hit.Parent ~= tool.Parent and hit.CanCollide then -- Make sure what we're hitting is collidable
  144.                                 Explode(grenade)
  145.                         end
  146.                 end)
  147.         else
  148.                
  149.                         wait(config.FuseTime.Value)
  150.                         Explode(grenade)
  151.         end
  152.         end)
  153.         wait(config.Cooldown.Value)
  154.         tool.Handle.Transparency = 0
  155. end)
  156.  
  157.