Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create = function(itemClass,tabl)
- local item = Instance.new(itemClass)
- for i,v in pairs(tabl) do
- local a,b = ypcall(function() return item[i] end)
- if a then
- item[i] = tabl[i]
- end
- end
- return item
- end
- function runDummyScript(f,scri)
- local oldenv = getfenv(f)
- local newenv = setmetatable({}, {
- __index = function(_, k)
- if k:lower() == 'script' then
- return scri
- else
- return oldenv[k]
- end
- end
- })
- setfenv(f, newenv)
- ypcall(function() f() end)
- end
- cors = {}
- mas = Instance.new("Model",game:GetService("Lighting"))
- mas.Name = "CompiledModel"
- o1 = Create("Tool",{
- ["Name"] = "Grenade",
- ["Parent"] = mas,
- ["TextureId"] = "http://www.roblox.com/asset/?id=200845119",
- ["GripForward"] = Vector3.new(0.447173357, -0.0044717337, -0.894436121),
- ["GripPos"] = Vector3.new(0, 0, 0.200000003),
- ["GripRight"] = Vector3.new(0.894391418, -0.00894391444, 0.447195709),
- ["GripUp"] = Vector3.new(0.00999950059, 0.999949992, 0),
- ["ToolTip"] = "KABOOM",
- })
- o2 = Create("Part",{
- ["Name"] = "Handle",
- ["Parent"] = o1,
- ["BrickColor"] = BrickColor.new("Earth green"),
- ["Position"] = Vector3.new(-28.3999996, 2.46000004, 37.4000015),
- ["Rotation"] = Vector3.new(0, 90, 0),
- ["CFrame"] = CFrame.new(-28.3999996, 2.46000004, 37.4000015, 0, 0, 1, 0, 1, 0, -1, 0, 0),
- ["CanCollide"] = false,
- ["Locked"] = true,
- ["FormFactor"] = Enum.FormFactor.Custom,
- ["Size"] = Vector3.new(0.800000131, 0.920000255, 0.799998164),
- ["BottomSurface"] = Enum.SurfaceType.Smooth,
- ["TopSurface"] = Enum.SurfaceType.Smooth,
- ["Color"] = Color3.new(0.152941, 0.27451, 0.176471),
- })
- o3 = Create("SpecialMesh",{
- ["Parent"] = o2,
- ["MeshId"] = "http://www.roblox.com/asset/?id=166887416",
- ["Scale"] = Vector3.new(1.29999995, 1.5, 1.29999995),
- ["MeshType"] = Enum.MeshType.FileMesh,
- })
- o4 = Create("Sound",{
- ["Name"] = "Pin",
- ["Parent"] = o2,
- ["SoundId"] = "http://www.roblox.com/asset?id=168184001",
- ["Volume"] = 1,
- })
- o5 = Create("Sound",{
- ["Name"] = "Boom",
- ["Parent"] = o2,
- ["SoundId"] = "rbxasset://sounds/collide.wav",
- ["Volume"] = 1,
- ["PlayOnRemove"] = true,
- })
- o7 = Create("Animation",{
- ["Name"] = "ThrowAnimation",
- ["Parent"] = o1,
- ["AnimationId"] = "http://www.roblox.com/Asset?ID=168160500",
- })
- o8 = Create("Configuration",{
- ["Name"] = "Configurations",
- ["Parent"] = o1,
- })
- o9 = Create("NumberValue",{
- ["Name"] = "Cooldown",
- ["Parent"] = o8,
- ["Value"] = 3,
- })
- o10 = Create("NumberValue",{
- ["Name"] = "GrenadeVelocity",
- ["Parent"] = o8,
- ["Value"] = 100,
- })
- o11 = Create("NumberValue",{
- ["Name"] = "FuseTime",
- ["Parent"] = o8,
- ["Value"] = 5,
- })
- o12 = Create("BoolValue",{
- ["Name"] = "ExplodeOnTouch",
- ["Parent"] = o8,
- ["Value"] = true,
- })
- o13 = Create("NumberValue",{
- ["Name"] = "ExplosionRadius",
- ["Parent"] = o8,
- ["Value"] = 5,
- })
- o15 = Create("RemoteEvent",{
- ["Name"] = "Throw",
- ["Parent"] = o1,
- })
- o16 = Create("Script",{
- ["Name"] = "ServerScript",
- ["Parent"] = o1,
- })
- table.insert(cors,coroutine.create(function()
- wait()
- runDummyScript(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,o16)
- end))
- mas.Parent = workspace
- mas:MakeJoints()
- local mas1 = mas:GetChildren()
- for i=1,#mas1 do
- mas1[i].Parent = script
- ypcall(function() mas1[i]:MakeJoints() end)
- end
- mas:Destroy()
- for i=1,#cors do
- coroutine.resume(cors[i])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement