Dark_EccentricYT

Untitled

Nov 9th, 2017
1,774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.49 KB | None | 0 0
  1. for i, v in pairs(game.Players.LocalPlayer.Backpack:children()) do
  2. if v.className == "HopperBin" and v.Name == "PPATTA's Trap Script" then
  3. v:Destroy()
  4. end
  5. end
  6.  
  7. local player = game:service("Players").LocalPlayer
  8. local mouse = player:GetMouse()
  9. local char = player.Character
  10. local Torsoz = char:findFirstChild("Torso")
  11. local RA = char:findFirstChild("Right Arm")
  12. local LA = char:findFirstChild("Left Arm")
  13. local RL = char:findFirstChild("Right Leg")
  14. local LL = char:findFirstChild("Left Leg")
  15. local H = char:findFirstChild("Head")
  16. local RS = Torsoz:findFirstChild("Right Shoulder")
  17. local LS = Torsoz:findFirstChild("Left Shoulder")
  18. local RH = Torsoz:findFirstChild("Right Hip")
  19. local LH = Torsoz:findFirstChild("Left Hip")
  20. local N = Torsoz:findFirstChild("Neck")
  21. local NV = Vector3.new()
  22. local Main
  23. local Traps = {}
  24. local Projectiles = {}
  25. local Bolts = {}
  26.  
  27. local bin = Instance.new("HopperBin")
  28. bin.Name = "PPATTA's Trap Script"
  29. bin.Parent = player.Backpack
  30.  
  31. local P = Instance.new("Part")
  32. P.Anchored = false
  33. P.CanCollide = false
  34. P.Name = "Part"
  35. P.formFactor = "Custom"
  36. P.Size = Vector3.new(0.2,0.2,0.2)
  37. P.BrickColor = BrickColor.new("Black")
  38. P.Locked = true
  39. P.TopSurface = 10
  40. P.BottomSurface = 10
  41. P.FrontSurface = 10
  42. P.BackSurface = 10
  43. P.LeftSurface = 10
  44. P.RightSurface = 10
  45.  
  46. local AnimJoints = {}
  47.  
  48. function GetWeld(weld)
  49. local obj
  50. for i, v in pairs(AnimJoints) do
  51. if v[1] == weld then
  52. obj = v
  53. break
  54. end
  55. end
  56. if not obj then
  57. obj = {weld,NV}
  58. table.insert(AnimJoints,obj)
  59. end
  60. return weld.C0.p, obj[2]
  61. end
  62.  
  63. function SetWeld(weld, i, loops, origpos,origangle, nextpos,nextangle,smooth)
  64. smooth = smooth or 1
  65. local obj
  66. for i, v in pairs(AnimJoints) do
  67. if v[1] == weld then
  68. obj = v
  69. break
  70. end
  71. end
  72. if not obj then
  73. obj = {weld,NV}
  74. table.insert(AnimJoints,obj)
  75. end
  76.  
  77. local perc = (smooth == 1 and math.sin((math.pi/2)/loops*i)) or i/loops
  78.  
  79. local tox,toy,toz = 0,0,0
  80. tox = math.abs(origangle.x - nextangle.x) *perc
  81. toy = math.abs(origangle.y - nextangle.y) *perc
  82. toz = math.abs(origangle.z - nextangle.z) *perc
  83. tox = (origangle.x > nextangle.x and -tox) or tox
  84. toy = (origangle.y > nextangle.y and -toy) or toy
  85. toz = (origangle.z > nextangle.z and -toz) or toz
  86.  
  87. local tox2,toy2,toz2 = 0,0,0
  88. tox2 = math.abs(origpos.x - nextpos.x) *perc
  89. toy2 = math.abs(origpos.y - nextpos.y) *perc
  90. toz2 = math.abs(origpos.z - nextpos.z) *perc
  91. tox2 = (origpos.x > nextpos.x and -tox2) or tox2
  92. toy2 = (origpos.y > nextpos.y and -toy2) or toy2
  93. toz2 = (origpos.z > nextpos.z and -toz2) or toz2
  94.  
  95. obj[2] = Vector3.new(origangle.x + tox, origangle.y + toy, origangle.z + toz)
  96. weld.C0 = CFrame.new(origpos.x + tox2,origpos.y + toy2,origpos.z + toz2) * CFrame.Angles(origangle.x + tox,origangle.y + toy,origangle.z + toz)
  97. end
  98.  
  99. function RAY(pos, dir, collidedlist, startpos, endpos, distleft)
  100. collidedlist = collidedlist or {char}
  101. startpos = startpos or pos
  102. distleft = distleft or dir.unit * dir.magnitude
  103. endpos = endpos or pos + distleft
  104. local ray = Ray.new(pos, distleft)
  105. local hitz,enz = workspace:FindPartOnRayWithIgnoreList(ray, collidedlist)
  106. if hitz ~= nil and not hitz.Parent:findFirstChild("Humanoid") then
  107. if hitz.CanCollide == false then
  108. table.insert(collidedlist, hitz)
  109. local newpos = enz
  110. local newdistleft = distleft - (dir.unit * (pos - newpos).magnitude)
  111. if newdistleft ~= NV then
  112. return RAY(newpos-(dir*0.01), dir, collidedlist, startpos, endpos, newdistleft+(dir*0.01))
  113. end
  114. end
  115. end
  116. return hitz, enz, ray
  117. end
  118.  
  119. function FindSurface(part, position)
  120. local obj = part.CFrame:pointToObjectSpace(position)
  121. local siz = part.Size/2
  122. for i,v in pairs(Enum.NormalId:GetEnumItems()) do
  123. local vec = Vector3.FromNormalId(v)
  124. local wvec = part.CFrame:vectorToWorldSpace(vec)
  125. local vz = (obj)/(siz*vec)
  126. 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
  127. return wvec,vec
  128. end
  129. end
  130. if part.className == "WedgePart" then
  131. local pos = (part.CFrame * CFrame.new(0,part.Size.y/2,part.Size.z/2)).p
  132. 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
  133. local wvec,vec = (apos - part.Position).unit, part.CFrame:pointToObjectSpace(apos)
  134. return wvec,vec
  135. elseif part.className == "Part" and (part.Shape == Enum.PartType.Ball or part.Shape == Enum.PartType.Cylinder) then
  136. return (position - part.Position).unit, part.CFrame:vectorToObjectSpace((position - part.Position).unit)
  137. end
  138. end
  139.  
  140. function CreateTrap(target,pos)
  141. local m = Instance.new("Model", char)
  142. m.Name = "Trap"
  143.  
  144. local cframe = CFrame.new()
  145. local anchor = true
  146.  
  147. if not target:IsA("Terrain") then
  148. local wvec,vec = FindSurface(target,pos)
  149. cframe = CFrame.new(NV,wvec) * CFrame.Angles(-math.pi/2,0,0)
  150. anchor = target.Anchored
  151. end
  152.  
  153. local c = P:Clone()
  154. c.Parent = m
  155. c.Anchored = anchor
  156. c.CanCollide = true
  157. c.CFrame = (cframe +pos) * CFrame.Angles(0,math.rad(math.random(1,360)),0)
  158. c.BrickColor = BrickColor.new("Dark stone grey")
  159. local light = Instance.new("PointLight", c)
  160. light.Brightness = 2
  161. light.Range = 7
  162. light.Color = Color3.new(1,0.8,0.1)
  163. local mesh = Instance.new("CylinderMesh",c)
  164. mesh.Scale = Vector3.new(0.2,0.4,0.2) *5
  165. if not anchor then
  166. local newpos = target.CFrame:toObjectSpace(c.CFrame)
  167. local w = Instance.new("Weld",c)
  168. w.Part0 = target
  169. w.Part1 = c
  170. w.C0 = newpos
  171. end
  172.  
  173. local tabl = {}
  174. for i = 1, 3 do
  175. local p = P:Clone()
  176. p.Parent = m
  177. p.Anchored = anchor
  178. 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)
  179. local mesh = Instance.new("SpecialMesh",p)
  180. mesh.MeshType = "Wedge"
  181. mesh.Scale = Vector3.new(0.15,1.2,0.16) *5
  182. if not anchor then
  183. local w = Instance.new("Weld",p)
  184. w.Part0 = c
  185. w.Part1 = p
  186. 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)
  187. end
  188.  
  189. for j = -1,1,2 do
  190. local p = P:Clone()
  191. p.Parent = m
  192. p.Anchored = anchor
  193. p.Transparency = 0.6
  194. p.BrickColor = BrickColor.new("Bright yellow")
  195. 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)
  196. local mesh = Instance.new("SpecialMesh",p)
  197. mesh.MeshType = "Wedge"
  198. mesh.Scale = Vector3.new(0.03,0.6,1.1) *5
  199. if not anchor then
  200. local w = Instance.new("Weld",p)
  201. w.Part0 = c
  202. w.Part1 = p
  203. 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)
  204. end
  205. table.insert(tabl,p)
  206. end
  207. end
  208.  
  209. table.insert(Traps,{m,c,tabl,0,light})
  210. end
  211.  
  212. function Build()
  213. for i, v in pairs(char:children()) do
  214. if v.className == "Model" and (v.Name == "" or v.Name == "Trap" or v.Name == "TrapProjectile") then
  215. v:Destroy()
  216. end
  217. end
  218. local mdl = Instance.new("Model", char)
  219. mdl.Name = ""
  220.  
  221. end
  222. Build()
  223.  
  224. function Throw(aim)
  225. local mdl = Instance.new("Model",char)
  226. mdl.Name = "TrapProjectile"
  227. local p = P:Clone()
  228. p.Parent = mdl
  229. p.Anchored = true
  230. p.Size = Vector3.new(0.5,0.5,1.5)
  231. p.CFrame = CFrame.new(Torsoz.Position,Torsoz.Position+aim)
  232. table.insert(Projectiles,{mdl,p,aim,0.05})
  233. end
  234.  
  235. function JumbleBolt(bolt)
  236. local lastpos = bolt[2][3]
  237. for i, v in pairs(bolt) do
  238. if i == 1 then
  239. bolt[1] = bolt[1] - 1
  240. else
  241. local point = v[4] * CFrame.new(math.random(-100,100)*v[5]/200,math.random(-100,100)*v[5]/200,0)
  242. v[1].CFrame = CFrame.new((lastpos+point.p)/2,point.p)
  243. v[2].Scale = Vector3.new(0.1,0.1,(lastpos-point.p).magnitude) *5
  244. lastpos = point.p
  245. end
  246. end
  247. end
  248.  
  249. function Bolt(par,start,endpos,jumble)
  250. jumble = jumble or 8
  251. local dist = (start - endpos).magnitude
  252. if dist < 200 then
  253. local tab = {jumble}
  254. local dir = (endpos - start).unit
  255. local jump = dist/math.floor(dist)
  256. local lastpos = start
  257. local lastraw
  258. for i = 1, math.floor(dist) do
  259. local rawpoint = CFrame.new(start,endpos) + dir*jump*i
  260. local point = rawpoint
  261. if i ~= math.floor(dist) then
  262. point = point * CFrame.new(math.random(-100,100)*jump/200,math.random(-100,100)*jump/200,0)
  263. end
  264. local p = P:Clone()
  265. p.Parent = par
  266. p.Anchored = true
  267. p.BrickColor = BrickColor.new("Royal purple")
  268. p.CFrame = CFrame.new((lastpos+point.p)/2,point.p)
  269. local mesh = Instance.new("BlockMesh",p)
  270. mesh.Scale = Vector3.new(0.1,0.1,(lastpos-point.p).magnitude) *5
  271. game:GetService("Debris"):AddItem(p,5)
  272. table.insert(tab,{p,mesh,start,rawpoint,jump})
  273. lastpos = point.p
  274. lastraw = rawpoint
  275. end
  276. table.insert(Bolts,tab)
  277. end
  278. end
  279.  
  280. function Explode(pos,bolts)
  281. local mdl = Instance.new("Model",char)
  282. mdl.Name = "Explosion"
  283. local p = P:Clone()
  284. p.Parent = mdl
  285. p.Anchored = true
  286. p.CanCollide = false
  287. p.CFrame = CFrame.new(pos)
  288. local l = Instance.new("PointLight",p)
  289. l.Color = Color3.new(0.5,0.1,1)
  290. l.Range = 10
  291. l.Brightness = 2
  292. game:GetService("Debris"):AddItem(mdl,0.7)
  293. for i, v in pairs(game:GetService("Players"):GetChildren()) do
  294. if v.Character ~= nil then
  295. if v.Character:findFirstChild("Torso") and v.Character:findFirstChild("Humanoid") then
  296. if (v.Character.Torso.Position - pos).magnitude < 6.5 then
  297. v.Character.Humanoid:TakeDamage(math.random(30,45))
  298. end
  299. end
  300. end
  301. end
  302. for i = 1, bolts do
  303. local dist = math.random(38,64) /10
  304. local dir = Vector3.new(math.random(-50,50),math.random(-50,50),math.random(-50,50)).unit
  305. Bolt(mdl,pos,pos+dir*dist)
  306. end
  307. end
  308.  
  309. function Detonate()
  310. for i, v in pairs(Traps) do
  311. Explode(v[2].Position,10)
  312. v[1]:Destroy()
  313. Traps[i] = nil
  314. end
  315. end
  316.  
  317. function B1D(mouse)
  318. --[[if mouse.Target and #Traps < 6 then
  319. CreateTrap(mouse.Hit.p,mouse.Target)
  320. end ]]
  321. if #Traps + #Projectiles < 6 then
  322. Throw((mouse.Hit.p - Torsoz.Position).unit)
  323. end
  324. --Bolt(char,Torsoz.Position,mouse.Hit.p)
  325. --Explode(mouse.Hit.p,10)
  326. end
  327.  
  328. function KD(key, mouse)
  329. if key == "e" then
  330. Detonate()
  331. --[[elseif key == "r" then
  332. for i, v in pairs(Traps) do
  333. v[1]:Destroy()
  334. Traps[i] = nil
  335. end ]]
  336. end
  337. end
  338.  
  339. function Equip()
  340. end
  341.  
  342. function Unequip()
  343. end
  344.  
  345. bin.Selected:connect(function(mouse)
  346. mouse.Icon = "rbxasset://textures\\GunCursor.png"
  347. mouse.Button1Down:connect(function() B1D(mouse) end)
  348. mouse.KeyDown:connect(function(key) KD(key, mouse) end)
  349. end)
  350.  
  351. bin.Deselected:connect(function()
  352. end)
  353.  
  354. local jumpcount = 0
  355. game:GetService("RunService").Stepped:connect(function()
  356. jumpcount = (jumpcount%2) + 1
  357. for i, trap in pairs(Traps) do
  358. trap[4] = (trap[4] + 1) %2
  359. if trap[4] == 0 then
  360. local randum = math.random()
  361. local zaptrans = 0.3 + 0.45*randum
  362. trap[5].Brightness = 0.8 + 2.8*randum --math.random(-65,60)/100
  363. for j, v in pairs(trap[3]) do
  364. v.Transparency = zaptrans
  365. end
  366. end
  367. end
  368.  
  369. for i, proj in pairs(Projectiles) do
  370. local spd = (proj[3]*3) + Vector3.new(0,proj[4],0)
  371. local hitz,enz = RAY(proj[2].Position,spd)
  372. if hitz then
  373. proj[1]:Destroy()
  374. CreateTrap(hitz,enz)
  375. table.remove(Projectiles,i)
  376. else
  377. proj[2].CFrame = CFrame.new(NV,spd) + proj[2].Position + spd
  378. proj[4] = proj[4] - 0.05
  379. end
  380. end
  381.  
  382. if jumpcount == 1 then
  383. for i, bolt in pairs(Bolts) do
  384. JumbleBolt(bolt)
  385. if bolt[1] <= 0 then
  386. for j, v in pairs(bolt) do
  387. if j ~= 1 then
  388. v[1]:Destroy()
  389. end
  390. end
  391. table.remove(Bolts,i)
  392. end
  393. end
  394. end
  395. end)
Add Comment
Please, Sign In to add comment