Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Converted with ttyyuu12345's model to script plugin v4
- function sandbox(var,func)
- local env = getfenv(func)
- local newenv = setmetatable({},{
- __index = function(self,k)
- if k=="script" then
- return var
- else
- return env[k]
- end
- end,
- })
- setfenv(func,newenv)
- return func
- end
- cors = {}
- mas = Instance.new("Model",game:GetService("Lighting"))
- Tool0 = Instance.new("Tool")
- Part1 = Instance.new("Part")
- SpecialMesh2 = Instance.new("SpecialMesh")
- Sound3 = Instance.new("Sound")
- Sound4 = Instance.new("Sound")
- Animation5 = Instance.new("Animation")
- Configuration6 = Instance.new("Configuration")
- NumberValue7 = Instance.new("NumberValue")
- NumberValue8 = Instance.new("NumberValue")
- NumberValue9 = Instance.new("NumberValue")
- BoolValue10 = Instance.new("BoolValue")
- NumberValue11 = Instance.new("NumberValue")
- LocalScript12 = Instance.new("LocalScript")
- RemoteEvent13 = Instance.new("RemoteEvent")
- Script14 = Instance.new("Script")
- Tool0.Name = "Grenade"
- Tool0.Parent = mas
- Tool0.TextureId = "http://www.roblox.com/asset/?id=200845119"
- Tool0.GripForward = Vector3.new(0.447173357, -0.0044717337, -0.894436121)
- Tool0.GripPos = Vector3.new(0, 0, 0.200000003)
- Tool0.GripRight = Vector3.new(0.894391418, -0.00894391444, 0.447195709)
- Tool0.GripUp = Vector3.new(0.00999950059, 0.999949992, 0)
- Tool0.ToolTip = "KABOOM"
- Part1.Name = "Handle"
- Part1.Parent = Tool0
- Part1.BrickColor = BrickColor.new("Earth green")
- Part1.Rotation = Vector3.new(0, 90, 0)
- Part1.CanCollide = false
- Part1.Locked = true
- Part1.FormFactor = Enum.FormFactor.Custom
- Part1.Size = Vector3.new(0.800000131, 0.920000255, 0.799998164)
- Part1.CFrame = CFrame.new(-43.3999977, 0.460000128, 23.3999996, 0, 0, 1, 0, 1, 0, -1, 0, 0)
- Part1.BottomSurface = Enum.SurfaceType.Smooth
- Part1.TopSurface = Enum.SurfaceType.Smooth
- Part1.Color = Color3.new(0.152941, 0.27451, 0.176471)
- Part1.Position = Vector3.new(-43.3999977, 0.460000128, 23.3999996)
- Part1.Orientation = Vector3.new(0, 90, 0)
- Part1.Color = Color3.new(0.152941, 0.27451, 0.176471)
- SpecialMesh2.Parent = Part1
- SpecialMesh2.MeshId = "http://www.roblox.com/asset/?id=166887416"
- SpecialMesh2.Scale = Vector3.new(1.29999995, 1.5, 1.29999995)
- SpecialMesh2.MeshType = Enum.MeshType.FileMesh
- SpecialMesh2.Scale = Vector3.new(1.29999995, 1.5, 1.29999995)
- Sound3.Name = "Pin"
- Sound3.Parent = Part1
- Sound3.SoundId = "http://www.roblox.com/asset?id=168184001"
- Sound3.Volume = 1
- Sound4.Name = "Boom"
- Sound4.Parent = Part1
- Sound4.SoundId = "rbxasset://sounds/collide.wav"
- Sound4.Volume = 1
- Sound4.PlayOnRemove = true
- Animation5.Name = "ThrowAnimation"
- Animation5.Parent = Tool0
- Animation5.AnimationId = "http://www.roblox.com/Asset?ID=168160500"
- Configuration6.Name = "Configurations"
- Configuration6.Parent = Tool0
- NumberValue7.Name = "Cooldown"
- NumberValue7.Parent = Configuration6
- NumberValue7.Value = 3
- NumberValue8.Name = "GrenadeVelocity"
- NumberValue8.Parent = Configuration6
- NumberValue8.Value = 100
- NumberValue9.Name = "FuseTime"
- NumberValue9.Parent = Configuration6
- NumberValue9.Value = 5
- BoolValue10.Name = "ExplodeOnTouch"
- BoolValue10.Parent = Configuration6
- BoolValue10.Value = true
- NumberValue11.Name = "ExplosionRadius"
- NumberValue11.Parent = Configuration6
- NumberValue11.Value = 5
- LocalScript12.Name = "ClientScript"
- LocalScript12.Parent = Tool0
- table.insert(cors,sandbox(LocalScript12,function()
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local tool = script.Parent
- local config = tool:WaitForChild("Configurations")
- local canThrow = true
- tool.Equipped:connect(function()
- mouse.Icon = "rbxasset://textures/GunCursor.png"
- end)
- tool.Unequipped:connect(function()
- mouse.Icon = ""
- end)
- tool.Activated:connect(function()
- if canThrow then
- canThrow = false
- local throwAnimation = player.Character.Humanoid:LoadAnimation(tool.ThrowAnimation)
- throwAnimation:Play() -- Load and play the throwing animation
- throwAnimation.KeyframeReached:connect(function(keyframe) -- Wait 'til we reach a keyframe
- if keyframe == "tick" then -- if the keyframe is 'tick' then play the pin sound
- tool.Handle.Pin:Play()
- elseif keyframe == "throw" then -- otherwise, if it's 'throw,' tell the serverscript to throw our grenade
- tool.Throw:FireServer(mouse.Hit.p)
- throwAnimation:Stop()
- mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
- end
- end)
- wait(config.Cooldown.Value)
- mouse.Icon = "rbxasset://textures/GunCursor.png"
- canThrow = true
- end
- end)
- end))
- RemoteEvent13.Name = "Throw"
- RemoteEvent13.Parent = Tool0
- Script14.Name = "ServerScript"
- Script14.Parent = Tool0
- table.insert(cors,sandbox(Script14,function()
- local tool = script.Parent
- local config = tool:WaitForChild("Configurations")
- -- 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
- function AngleOfReach(distance, altitude, velocity)
- local theta = math.atan((velocity^2 + math.sqrt(velocity^4 -196.2*(196.2*distance^2 + 2*altitude*velocity^2)))/(196.2*distance))
- if theta ~= theta then
- theta = math.pi/4
- end
- return(theta)
- end
- -- A simple function to explode a specified part
- function Explode(part)
- local explosion = Instance.new("Explosion", workspace)
- explosion.Position = part.Position
- explosion.BlastRadius = config.ExplosionRadius.Value
- part:Destroy()
- end
- script.Parent.Throw.OnServerEvent:connect(function(player, mousePosition)
- local handlePos = Vector3.new(tool.Handle.Position.X, 0, tool.Handle.Position.Z) -- remove Y from the equation, it's not needed
- local mousePos = Vector3.new(mousePosition.X, 0, mousePosition.Z) -- ditto
- local distance = (handlePos - mousePos).magnitude -- Get the distance between the handle and the mouse
- local altitude = mousePosition.Y - tool.Handle.Position.Y
- local angle = AngleOfReach(distance, altitude, config.GrenadeVelocity.Value) -- Calculate the angle
- tool.Handle.Transparency = 1
- local grenade = tool.Handle:Clone()
- grenade.Parent = workspace
- grenade.Transparency = 0
- grenade.CanCollide = true
- grenade.CFrame = tool.Handle.CFrame
- 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
- spawn(function()
- if config.ExplodeOnTouch.Value then
- grenade.Touched:connect(function(hit)
- if hit.Parent ~= tool.Parent and hit.CanCollide then -- Make sure what we're hitting is collidable
- Explode(grenade)
- end
- end)
- else
- wait(config.FuseTime.Value)
- Explode(grenade)
- end
- end)
- wait(config.Cooldown.Value)
- tool.Handle.Transparency = 0
- end)
- end))
- for i,v in pairs(mas:GetChildren()) do
- v.Parent = game:GetService("Players").LocalPlayer.Backpack
- pcall(function() v:MakeJoints() end)
- end
- mas:Destroy()
- for i,v in pairs(cors) do
- spawn(function()
- pcall(v)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement