Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for i, v in pairs(game.Players.LocalPlayer.Backpack:children()) do
- if v.className == "HopperBin" and v.Name == "PPATTA's Trap Script" then
- v:Destroy()
- end
- end
- local player = game:service("Players").LocalPlayer
- local mouse = player:GetMouse()
- local char = player.Character
- local Torsoz = char:findFirstChild("Torso")
- local RA = char:findFirstChild("Right Arm")
- local LA = char:findFirstChild("Left Arm")
- local RL = char:findFirstChild("Right Leg")
- local LL = char:findFirstChild("Left Leg")
- local H = char:findFirstChild("Head")
- local RS = Torsoz:findFirstChild("Right Shoulder")
- local LS = Torsoz:findFirstChild("Left Shoulder")
- local RH = Torsoz:findFirstChild("Right Hip")
- local LH = Torsoz:findFirstChild("Left Hip")
- local N = Torsoz:findFirstChild("Neck")
- local NV = Vector3.new()
- local Main
- local Traps = {}
- local Projectiles = {}
- local Bolts = {}
- local bin = Instance.new("HopperBin")
- bin.Name = "PPATTA's Trap Script"
- bin.Parent = player.Backpack
- local P = Instance.new("Part")
- P.Anchored = false
- P.CanCollide = false
- P.Name = "Part"
- P.formFactor = "Custom"
- P.Size = Vector3.new(0.2,0.2,0.2)
- P.BrickColor = BrickColor.new("Black")
- P.Locked = true
- P.TopSurface = 10
- P.BottomSurface = 10
- P.FrontSurface = 10
- P.BackSurface = 10
- P.LeftSurface = 10
- P.RightSurface = 10
- local AnimJoints = {}
- function GetWeld(weld)
- local obj
- for i, v in pairs(AnimJoints) do
- if v[1] == weld then
- obj = v
- break
- end
- end
- if not obj then
- obj = {weld,NV}
- table.insert(AnimJoints,obj)
- end
- return weld.C0.p, obj[2]
- end
- function SetWeld(weld, i, loops, origpos,origangle, nextpos,nextangle,smooth)
- smooth = smooth or 1
- local obj
- for i, v in pairs(AnimJoints) do
- if v[1] == weld then
- obj = v
- break
- end
- end
- if not obj then
- obj = {weld,NV}
- table.insert(AnimJoints,obj)
- end
- local perc = (smooth == 1 and math.sin((math.pi/2)/loops*i)) or i/loops
- local tox,toy,toz = 0,0,0
- tox = math.abs(origangle.x - nextangle.x) *perc
- toy = math.abs(origangle.y - nextangle.y) *perc
- toz = math.abs(origangle.z - nextangle.z) *perc
- tox = (origangle.x > nextangle.x and -tox) or tox
- toy = (origangle.y > nextangle.y and -toy) or toy
- toz = (origangle.z > nextangle.z and -toz) or toz
- local tox2,toy2,toz2 = 0,0,0
- tox2 = math.abs(origpos.x - nextpos.x) *perc
- toy2 = math.abs(origpos.y - nextpos.y) *perc
- toz2 = math.abs(origpos.z - nextpos.z) *perc
- tox2 = (origpos.x > nextpos.x and -tox2) or tox2
- toy2 = (origpos.y > nextpos.y and -toy2) or toy2
- toz2 = (origpos.z > nextpos.z and -toz2) or toz2
- obj[2] = Vector3.new(origangle.x + tox, origangle.y + toy, origangle.z + toz)
- weld.C0 = CFrame.new(origpos.x + tox2,origpos.y + toy2,origpos.z + toz2) * CFrame.Angles(origangle.x + tox,origangle.y + toy,origangle.z + toz)
- end
- function RAY(pos, dir, collidedlist, startpos, endpos, distleft)
- collidedlist = collidedlist or {char}
- startpos = startpos or pos
- distleft = distleft or dir.unit * dir.magnitude
- endpos = endpos or pos + distleft
- local ray = Ray.new(pos, distleft)
- local hitz,enz = workspace:FindPartOnRayWithIgnoreList(ray, collidedlist)
- if hitz ~= nil and not hitz.Parent:findFirstChild("Humanoid") then
- if hitz.CanCollide == false then
- table.insert(collidedlist, hitz)
- local newpos = enz
- local newdistleft = distleft - (dir.unit * (pos - newpos).magnitude)
- if newdistleft ~= NV then
- return RAY(newpos-(dir*0.01), dir, collidedlist, startpos, endpos, newdistleft+(dir*0.01))
- end
- end
- end
- return hitz, enz, ray
- end
- function FindSurface(part, position)
- local obj = part.CFrame:pointToObjectSpace(position)
- local siz = part.Size/2
- for i,v in pairs(Enum.NormalId:GetEnumItems()) do
- local vec = Vector3.FromNormalId(v)
- local wvec = part.CFrame:vectorToWorldSpace(vec)
- local vz = (obj)/(siz*vec)
- if (math.abs(vz.X-1) < 0.01 or math.abs(vz.Y-1) < 0.01 or math.abs(vz.Z-1) < 0.01) then
- return wvec,vec
- end
- end
- if part.className == "WedgePart" then
- local pos = (part.CFrame * CFrame.new(0,part.Size.y/2,part.Size.z/2)).p
- local apos = (part.CFrame * CFrame.Angles(-math.atan2(part.CFrame:pointToObjectSpace(pos).y,part.CFrame:pointToObjectSpace(pos).z),0,0) * CFrame.new(0,1,0)).p
- local wvec,vec = (apos - part.Position).unit, part.CFrame:pointToObjectSpace(apos)
- return wvec,vec
- elseif part.className == "Part" and (part.Shape == Enum.PartType.Ball or part.Shape == Enum.PartType.Cylinder) then
- return (position - part.Position).unit, part.CFrame:vectorToObjectSpace((position - part.Position).unit)
- end
- end
- function CreateTrap(target,pos)
- local m = Instance.new("Model", char)
- m.Name = "Trap"
- local cframe = CFrame.new()
- local anchor = true
- if not target:IsA("Terrain") then
- local wvec,vec = FindSurface(target,pos)
- cframe = CFrame.new(NV,wvec) * CFrame.Angles(-math.pi/2,0,0)
- anchor = target.Anchored
- end
- local c = P:Clone()
- c.Parent = m
- c.Anchored = anchor
- c.CanCollide = true
- c.CFrame = (cframe +pos) * CFrame.Angles(0,math.rad(math.random(1,360)),0)
- c.BrickColor = BrickColor.new("Dark stone grey")
- local light = Instance.new("PointLight", c)
- light.Brightness = 2
- light.Range = 7
- light.Color = Color3.new(1,0.8,0.1)
- local mesh = Instance.new("CylinderMesh",c)
- mesh.Scale = Vector3.new(0.2,0.4,0.2) *5
- if not anchor then
- local newpos = target.CFrame:toObjectSpace(c.CFrame)
- local w = Instance.new("Weld",c)
- w.Part0 = target
- w.Part1 = c
- w.C0 = newpos
- end
- local tabl = {}
- for i = 1, 3 do
- local p = P:Clone()
- p.Parent = m
- p.Anchored = anchor
- p.CFrame = c.CFrame * CFrame.Angles(0,math.pi*2/3*i,0) * CFrame.new(0,0.04,-0.12) * CFrame.Angles(-math.pi/2 +0.05,0,0) * CFrame.new(0,0.55,0)
- local mesh = Instance.new("SpecialMesh",p)
- mesh.MeshType = "Wedge"
- mesh.Scale = Vector3.new(0.15,1.2,0.16) *5
- if not anchor then
- local w = Instance.new("Weld",p)
- w.Part0 = c
- w.Part1 = p
- w.C0 = CFrame.Angles(0,math.pi*2/3*i,0) * CFrame.new(0,0.04,-0.12) * CFrame.Angles(-math.pi/2 +0.05,0,0) * CFrame.new(0,0.55,0)
- end
- for j = -1,1,2 do
- local p = P:Clone()
- p.Parent = m
- p.Anchored = anchor
- p.Transparency = 0.6
- p.BrickColor = BrickColor.new("Bright yellow")
- p.CFrame = c.CFrame * CFrame.new(0,0.2,0) * CFrame.Angles(0,math.pi*2/3*i,0) * CFrame.new(0.32*j,0,-0.55) * CFrame.Angles(0.06,0,-math.pi/2*j)
- local mesh = Instance.new("SpecialMesh",p)
- mesh.MeshType = "Wedge"
- mesh.Scale = Vector3.new(0.03,0.6,1.1) *5
- if not anchor then
- local w = Instance.new("Weld",p)
- w.Part0 = c
- w.Part1 = p
- w.C0 = CFrame.new(0,0.2,0) * CFrame.Angles(0,math.pi*2/3*i,0) * CFrame.new(0.32*j,0,-0.55) * CFrame.Angles(0.06,0,-math.pi/2*j)
- end
- table.insert(tabl,p)
- end
- end
- table.insert(Traps,{m,c,tabl,0,light})
- end
- function Build()
- for i, v in pairs(char:children()) do
- if v.className == "Model" and (v.Name == "" or v.Name == "Trap" or v.Name == "TrapProjectile") then
- v:Destroy()
- end
- end
- local mdl = Instance.new("Model", char)
- mdl.Name = ""
- end
- Build()
- function Throw(aim)
- local mdl = Instance.new("Model",char)
- mdl.Name = "TrapProjectile"
- local p = P:Clone()
- p.Parent = mdl
- p.Anchored = true
- p.Size = Vector3.new(0.5,0.5,1.5)
- p.CFrame = CFrame.new(Torsoz.Position,Torsoz.Position+aim)
- table.insert(Projectiles,{mdl,p,aim,0.05})
- end
- function JumbleBolt(bolt)
- local lastpos = bolt[2][3]
- for i, v in pairs(bolt) do
- if i == 1 then
- bolt[1] = bolt[1] - 1
- else
- local point = v[4] * CFrame.new(math.random(-100,100)*v[5]/200,math.random(-100,100)*v[5]/200,0)
- v[1].CFrame = CFrame.new((lastpos+point.p)/2,point.p)
- v[2].Scale = Vector3.new(0.1,0.1,(lastpos-point.p).magnitude) *5
- lastpos = point.p
- end
- end
- end
- function Bolt(par,start,endpos,jumble)
- jumble = jumble or 8
- local dist = (start - endpos).magnitude
- if dist < 200 then
- local tab = {jumble}
- local dir = (endpos - start).unit
- local jump = dist/math.floor(dist)
- local lastpos = start
- local lastraw
- for i = 1, math.floor(dist) do
- local rawpoint = CFrame.new(start,endpos) + dir*jump*i
- local point = rawpoint
- if i ~= math.floor(dist) then
- point = point * CFrame.new(math.random(-100,100)*jump/200,math.random(-100,100)*jump/200,0)
- end
- local p = P:Clone()
- p.Parent = par
- p.Anchored = true
- p.BrickColor = BrickColor.new("Royal purple")
- p.CFrame = CFrame.new((lastpos+point.p)/2,point.p)
- local mesh = Instance.new("BlockMesh",p)
- mesh.Scale = Vector3.new(0.1,0.1,(lastpos-point.p).magnitude) *5
- game:GetService("Debris"):AddItem(p,5)
- table.insert(tab,{p,mesh,start,rawpoint,jump})
- lastpos = point.p
- lastraw = rawpoint
- end
- table.insert(Bolts,tab)
- end
- end
- function Explode(pos,bolts)
- local mdl = Instance.new("Model",char)
- mdl.Name = "Explosion"
- local p = P:Clone()
- p.Parent = mdl
- p.Anchored = true
- p.CanCollide = false
- p.CFrame = CFrame.new(pos)
- local l = Instance.new("PointLight",p)
- l.Color = Color3.new(0.5,0.1,1)
- l.Range = 10
- l.Brightness = 2
- game:GetService("Debris"):AddItem(mdl,0.7)
- for i, v in pairs(game:GetService("Players"):GetChildren()) do
- if v.Character ~= nil then
- if v.Character:findFirstChild("Torso") and v.Character:findFirstChild("Humanoid") then
- if (v.Character.Torso.Position - pos).magnitude < 6.5 then
- v.Character.Humanoid:TakeDamage(math.random(30,45))
- end
- end
- end
- end
- for i = 1, bolts do
- local dist = math.random(38,64) /10
- local dir = Vector3.new(math.random(-50,50),math.random(-50,50),math.random(-50,50)).unit
- Bolt(mdl,pos,pos+dir*dist)
- end
- end
- function Detonate()
- for i, v in pairs(Traps) do
- Explode(v[2].Position,10)
- v[1]:Destroy()
- Traps[i] = nil
- end
- end
- function B1D(mouse)
- --[[if mouse.Target and #Traps < 6 then
- CreateTrap(mouse.Hit.p,mouse.Target)
- end ]]
- if #Traps + #Projectiles < 6 then
- Throw((mouse.Hit.p - Torsoz.Position).unit)
- end
- --Bolt(char,Torsoz.Position,mouse.Hit.p)
- --Explode(mouse.Hit.p,10)
- end
- function KD(key, mouse)
- if key == "e" then
- Detonate()
- --[[elseif key == "r" then
- for i, v in pairs(Traps) do
- v[1]:Destroy()
- Traps[i] = nil
- end ]]
- end
- end
- function Equip()
- end
- function Unequip()
- end
- bin.Selected:connect(function(mouse)
- mouse.Icon = "rbxasset://textures\\GunCursor.png"
- mouse.Button1Down:connect(function() B1D(mouse) end)
- mouse.KeyDown:connect(function(key) KD(key, mouse) end)
- end)
- bin.Deselected:connect(function()
- end)
- local jumpcount = 0
- game:GetService("RunService").Stepped:connect(function()
- jumpcount = (jumpcount%2) + 1
- for i, trap in pairs(Traps) do
- trap[4] = (trap[4] + 1) %2
- if trap[4] == 0 then
- local randum = math.random()
- local zaptrans = 0.3 + 0.45*randum
- trap[5].Brightness = 0.8 + 2.8*randum --math.random(-65,60)/100
- for j, v in pairs(trap[3]) do
- v.Transparency = zaptrans
- end
- end
- end
- for i, proj in pairs(Projectiles) do
- local spd = (proj[3]*3) + Vector3.new(0,proj[4],0)
- local hitz,enz = RAY(proj[2].Position,spd)
- if hitz then
- proj[1]:Destroy()
- CreateTrap(hitz,enz)
- table.remove(Projectiles,i)
- else
- proj[2].CFrame = CFrame.new(NV,spd) + proj[2].Position + spd
- proj[4] = proj[4] - 0.05
- end
- end
- if jumpcount == 1 then
- for i, bolt in pairs(Bolts) do
- JumbleBolt(bolt)
- if bolt[1] <= 0 then
- for j, v in pairs(bolt) do
- if j ~= 1 then
- v[1]:Destroy()
- end
- end
- table.remove(Bolts,i)
- end
- end
- end
- end)
Add Comment
Please, Sign In to add comment