DDDDDtuij

earthbending!

Jul 24th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.04 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------[[Mediafire]]-----------------------------------------------------------------------------------------------------------
  2.  
  3. -- Player declarations
  4. local player = game.Players.LocalPlayer
  5. local char = player.Character
  6.  
  7. -- Body parts
  8. local head = char.Head
  9. local torso = char.Torso
  10.  
  11. -- Tool declarations
  12. local mouseDown = false
  13. local keysDown = {}
  14.  
  15. -- Earth bending declarations
  16. local raisingEarth = false
  17. local raisingTower = false
  18. local groundAttack = false
  19. local flyingEarth = nil
  20. local lastTower = nil
  21. local disabled = {}
  22. local frames = {}
  23. local parts = {}
  24.  
  25. local bloodBodies = {}
  26.  
  27. -- Main
  28. function main(mouse)
  29. while true do wait(1/60)
  30. local look = CFrame.new(torso.Position, torso.Position + mouse.Hit.lookVector)
  31.  
  32. -- Reset parts
  33. parts = {}
  34.  
  35. -- Get parts
  36. for x = -20, 20, 10 do
  37. for y = -20, 20, 10 do
  38. for z = -30, -10, 10 do
  39. local pos = look * Vector3.new(x, y, z)
  40. getPartsInRegion3(
  41. Region3.new(
  42. pos + Vector3.new(1,1,1)*-9,
  43. pos + Vector3.new(1,1,1)* 9
  44. ),
  45. parts
  46. )
  47. end
  48. end
  49. end
  50.  
  51. -- Blood bending
  52. if keysDown["q"] then
  53. for _, part in pairs(parts) do
  54. local oPlayer = game.Players:GetPlayerFromCharacter(part.Parent)
  55. if oPlayer and oPlayer ~= player then
  56. local oTorso = part.Parent:FindFirstChild("Torso")
  57. if oTorso then
  58. local bodyPos = oTorso:FindFirstChild("BodyPosition")
  59. local bodyGyr = oTorso:FindFirstChild("BodyGyro")
  60. if not bodyPos then
  61. bodyPos = createBody("Position", oTorso)
  62. table.insert(bloodBodies, bodyPos)
  63. end
  64. if not bodyGyr then
  65. bodyGyr = createBody("Gyro", oTorso)
  66. table.insert(bloodBodies, bodyGyr)
  67. end
  68. end
  69. break
  70. end
  71. end
  72. for _, body in pairs(bloodBodies) do
  73. body.Parent.Anchored = false
  74. if body.className == "BodyPosition" then
  75. body.maxForce = Vector3.new(math.huge, math.huge, math.huge)
  76. elseif body.className == "BodyGyro" then
  77. body.maxTorque = Vector3.new(math.huge, math.huge, math.huge)
  78. end
  79. local oTorso = body.Parent
  80. local hit, posd = rayCast(oTorso.Position, Vector3.new(0, -50, 0), {oTorso.Parent})
  81. posd = posd + Vector3.new(0, 3, 0)
  82. local tor = oTorso.Position
  83. local pos = planeY(mouse.Hit.p, posd.y)
  84. local frame = CFrame.new(tor, tor + (pos - tor).unit) * CFrame.new(0, 0, -10)
  85.  
  86. if body.className == "BodyPosition" then
  87. body.position = frame.p
  88. else
  89. body.cframe = frame
  90. end
  91. end
  92. else
  93. for i in pairs(bloodBodies) do
  94. bloodBodies[i]:Destroy()
  95. bloodBodies[i] = nil
  96. end
  97. end
  98.  
  99. -- Mouse down
  100. if mouseDown then
  101. -- Create dif and bodies
  102. for _, part in pairs(parts) do
  103. if part.Name == "Earth" and not disabled[part] then
  104. if not frames[part] and part ~= lastTower then
  105. frames[part] = look:toObjectSpace(part.CFrame)
  106.  
  107. part:ClearAllChildren()
  108. part.Anchored = false
  109.  
  110. -- Create bodies
  111. createBody("Position", part)
  112. createBody("Gyro", part)
  113. end
  114. end
  115. end
  116.  
  117. -- Move bodies
  118. for part in pairs(frames) do
  119. local bodyPos = part:FindFirstChild("BodyPosition")
  120. local bodyGyr = part:FindFirstChild("BodyGyro")
  121.  
  122. -- Bodies exist
  123. if bodyPos and bodyGyr then
  124. local dif = look * frames[part]
  125.  
  126. bodyPos.position = dif.p
  127. bodyGyr.cframe = dif
  128. else
  129. frames[part] = nil
  130. end
  131. end
  132. else
  133. for part in pairs(frames) do
  134. if part.Name == "Earth" then
  135. frames[part] = nil
  136.  
  137. part:ClearAllChildren()
  138. end
  139. end
  140. end
  141. end
  142. end
  143.  
  144. -- On key change
  145. function onKeyChange(mouse, key, state)
  146. -- Raise earth
  147. if key == "e" and state and not raisingEarth then
  148. raisingEarth = true
  149. while keysDown[key] do
  150. local torsoY = torso.Position.y + 3
  151. local pos = planeY(torso.Position, 0.4 - 4/2)
  152. local dir = planeY(mouse.Hit.lookVector).unit
  153. local frame = CFrame.new(pos, pos + dir) * CFrame.new(r(-10, 10), 0, r(-20, -5))
  154.  
  155. -- Create earth part
  156. local part = createEarth(workspace)
  157. part.Anchored = true
  158. part.Size = Vector3.new(4, 4, 4)
  159. disabled[part] = true
  160.  
  161. -- Raise earth
  162. for i = 1, 4 do i = i/4
  163. part.CFrame = frame * CFrame.new(0, (torsoY - frame.y)*i, 0)
  164. wait(1/30)
  165. if not part.Anchored then
  166. break
  167. end
  168. end
  169.  
  170. disabled[part] = nil
  171. part.Anchored = false
  172.  
  173. wait(1/10)
  174. end
  175. raisingEarth = false
  176.  
  177. -- Push earth
  178. elseif key == "f" and state then
  179. for _, part in pairs(parts) do
  180. if part.Name == "Earth" and part ~= lastTower then
  181. part:ClearAllChildren()
  182. part.Anchored = false
  183.  
  184. -- Add force
  185. local bodyForce = createBody("Force", part)
  186. bodyForce.force = mouse.Hit.lookVector*1.5e4 * part:GetMass()
  187.  
  188. game.Debris:AddItem(bodyForce, 1/30)
  189.  
  190. -- Disable part
  191. disabled[part] = true
  192. delay(1, function()
  193. disabled[part] = nil
  194. end)
  195. end
  196. end
  197.  
  198. -- Break earth
  199. elseif key == "b" and state then
  200. for part in pairs(frames) do
  201. if part.Size == Vector3.new(4, 4, 4) then
  202. for x = -1, 1, 2 do
  203. for y = -1, 1, 2 do
  204. for z = -1, 1, 2 do
  205. local oPart = createEarth(workspace)
  206. oPart.Size = Vector3.new(2, 2, 2)
  207. oPart.CFrame = part.CFrame * CFrame.new(x*1.1, y*1.1, z*1.1)
  208. end
  209. end
  210. end
  211. part:Destroy()
  212. end
  213. end
  214.  
  215. -- Raise tower
  216. elseif key == "r" and state and not raisingTower then
  217. raisingTower = true
  218. lastTower = nil
  219. if torso.Position.y - 5/2 < 20.4 then
  220. local part = createEarth(workspace)
  221. part.Anchored = true
  222. disabled[part] = true
  223.  
  224. for i = 0, 20, 4 do
  225. part.Size = Vector3.new(5, i, 5)
  226. part.CFrame = CFrame.new(torso.Position.x, 0.4 + part.Size.y/2, torso.Position.z)
  227. torso.CFrame = (torso.CFrame - torso.CFrame.p) + Vector3.new(torso.Position.x, part.Position.y + part.Size.y/2 + 5/2, torso.Position.z)
  228. wait(1/30)
  229. end
  230.  
  231. lastTower = part
  232.  
  233. disabled[part] = nil
  234. part.Anchored = false
  235. end
  236. raisingTower = false
  237.  
  238. -- Ground attack
  239. elseif key == "g" and state and not groundAttack then
  240. groundAttack = true
  241. delay(1, function()
  242. groundAttack = false
  243. end)
  244.  
  245. local dir = planeY(mouse.Hit.p - torso.Position).unit
  246. local pos = planeY(torso.Position, 0.4 + 1) + dir*5
  247.  
  248. local ground = {}
  249.  
  250. delay(5, function()
  251. for i = 1, 20 do
  252. for _, part in pairs(ground) do
  253. if part.Anchored then
  254. part.CFrame = part.CFrame + Vector3.new(0, -1/7, 0)
  255. end
  256. end
  257. wait(1/30)
  258. end
  259. for _, part in pairs(ground) do
  260. if part.Anchored then
  261. part:Destroy()
  262. end
  263. end
  264. end)
  265.  
  266. for i = 1, 10 do
  267. local hit, pos2 = rayCast(pos, dir*5, {char})
  268.  
  269. local part = createEarth(workspace)
  270. part.Anchored = true
  271. part.Size = Vector3.new(2, 4, 2)
  272. part.CFrame = CFrame.new(pos2, pos2 + dir) * CFrame.Angles(math.rad(-50), 0, 0) + Vector3.new(0, -0, 0)
  273.  
  274. ground[#ground + 1] = part
  275.  
  276. -- Add force
  277. if hit then
  278. local mass = hit:GetMass()
  279.  
  280. -- Hit player
  281. for _, oPlayer in pairs(game.Players:GetPlayers()) do
  282. if oPlayer.Character and oPlayer.Character:FindFirstChild("Torso") and hit:IsDescendantOf(oPlayer.Character) then
  283. hit = oPlayer.Character.Torso
  284. mass = 16
  285. end
  286. end
  287.  
  288. if hit.Name ~= "Torso" then
  289. hit:ClearAllChildren()
  290. end
  291. hit.Anchored = false
  292.  
  293. -- Add force
  294. local bodyForce = createBody("Force", hit)
  295. bodyForce.force = (dir + Vector3.new(0, 0.2, 0)).unit*1e4 * mass
  296.  
  297. game.Debris:AddItem(bodyForce, 1/30)
  298. break
  299. end
  300.  
  301. pos = pos2
  302. wait(1/20)
  303. end
  304. end
  305. end
  306.  
  307. --- CORE CODE BELOW --- CORE CODE BELOW --- CORE CODE BELOW ---
  308. --- CORE CODE BELOW --- CORE CODE BELOW --- CORE CODE BELOW ---
  309. --- CORE CODE BELOW --- CORE CODE BELOW --- CORE CODE BELOW ---
  310.  
  311. -- Clear old tool
  312. player.Backpack:ClearAllChildren()
  313.  
  314. -- Create tool
  315. local tool = Instance.new("HopperBin")
  316. tool.Parent = player.Backpack
  317. tool.Name = "Earth Bending"
  318.  
  319. -- Tool selected
  320. tool.Selected:connect(function(mouse)
  321. mouse.Icon = "rbxasset://textures\\GunCursor.png"
  322.  
  323. -- Mouse events
  324. mouse.Button1Down:connect(function()
  325. mouseDown = true
  326. end)
  327. mouse.Button1Up:connect(function()
  328. mouseDown = false
  329. end)
  330. mouse.KeyDown:connect(function(key)
  331. keysDown[key:lower()] = true
  332. onKeyChange(mouse, key:lower(), true)
  333. end)
  334. mouse.KeyUp:connect(function(key)
  335. keysDown[key:lower()] = false
  336. onKeyChange(mouse, key:lower(), false)
  337. end)
  338.  
  339. -- Call main
  340. main(mouse)
  341. end)
  342.  
  343. --- LIBRARY BELOW --- LIBRARY BELOW --- LIBRARY BELOW ---
  344. --- LIBRARY BELOW --- LIBRARY BELOW --- LIBRARY BELOW ---
  345. --- LIBRARY BELOW --- LIBRARY BELOW --- LIBRARY BELOW ---
  346.  
  347. -- Ray cast
  348. function rayCast(pos, dir, ignore)
  349. return workspace:FindPartOnRayWithIgnoreList(Ray.new(pos, dir), ignore)
  350. end
  351.  
  352. -- Create body
  353. function createBody(type, path)
  354. local body = Instance.new("Body" .. type)
  355. if type == "Gyro" then
  356. body.maxTorque = Vector3.new(math.huge, math.huge, math.huge)
  357. elseif type ~= "Force" then
  358. body.maxForce = Vector3.new(math.huge, math.huge, math.huge)
  359. end
  360. body.Parent = path
  361. return body
  362. end
  363.  
  364. -- Get parts in region 3
  365. function getPartsInRegion3(region, parts)
  366. repeat
  367. local regParts = workspace:FindPartsInRegion3WithIgnoreList(region, parts, 100)
  368. for i, part in pairs(regParts) do
  369. parts[#parts + 1] = part
  370. end
  371. until #regParts < 100
  372. end
  373.  
  374. -- Random
  375. function r(min, max)
  376. return math.random()*(max - min) + min
  377. end
  378.  
  379. -- Plane y
  380. function planeY(v, y)
  381. return Vector3.new(v.x, y or 0, v.z)
  382. end
  383.  
  384. -- Create earth
  385. function createEarth(path)
  386. local part = createPart("Earth", path)
  387. part.BrickColor = BrickColor.new("Brown")
  388. part.Material = "Slate"
  389. part.Parent = path
  390. part.Parent = char
  391. return part
  392. end
  393.  
  394. -- Create part
  395. function createPart(name, path)
  396. local part = Instance.new("Part")
  397. part.FormFactor = "Symmetric"
  398. part.BottomSurface = "Smooth"
  399. part.TopSurface = "Smooth"
  400. part.Size = Vector3.new(1, 1, 1)
  401. part.Name = name
  402. part.Parent = path
  403. return part
  404. end
  405.  
  406. -- Linear interpolation
  407. function lerp(a, b, t)
  408. return a + (b - a)*t
  409. end
  410.  
  411. -- Spherical interpolation
  412. function slerp(a, b, t)
  413. local dot = a:Dot(b)
  414. if math.abs(dot) > 0.99999 then
  415. return t <= 0.5 and a or b
  416. else
  417. local r = math.acos(dot)
  418. return (a*math.sin((1 - t)*r) + b*math.sin(t*r)) / math.sin(r)
  419. end
  420. end
  421.  
  422. -- Matrix interpolation
  423. function matrixInterpolate(a, b, t)
  424. local ax, ay, az, a00, a01, a02, a10, a11, a12, a20, a21, a22 = a:components()
  425. local bx, by, bz, b00, b01, b02, b10, b11, b12, b20, b21, b22 = b:components()
  426.  
  427. local v0 = lerp(Vector3.new(ax , ay , az ), Vector3.new(bx , by , bz) , t) -- Vector pos
  428. local v1 = slerp(Vector3.new(a00, a01, a02), Vector3.new(b00, b01, b02), t) -- Vector right
  429. local v2 = slerp(Vector3.new(a10, a11, a12), Vector3.new(b10, b11, b12), t) -- Vector up
  430. local v3 = slerp(Vector3.new(a20, a21, a22), Vector3.new(b20, b21, b22), t) -- Vector back
  431.  
  432. return CFrame.new(
  433. v0.x, v0.y, v0.z,
  434. v1.x, v1.y, v1.z,
  435. v2.x, v2.y, v2.z,
  436. v3.x, v3.y, v3.z)
  437. end
  438.  
  439. --[[
  440. while true do
  441. wait(1/30)
  442. for _, player in pairs(game.Players:GetPlayers()) do
  443. pcall(function()
  444. if player.Character.Torso.Position.y < 0 then
  445. player.Character.Torso.Velocity = Vector3.new()
  446. player.Character.Torso.CFrame = CFrame.new(math.random(-100, 100), 20, math.random(-100, 100))
  447. player.Character.Torso.Velocity = Vector3.new()
  448.  
  449. local msg = Instance.new("Message")
  450. msg.Text = player.Name .. " has been killed"
  451. msg.Parent = workspace
  452. game.Debris:AddItem(msg, 3)
  453. end
  454. end) -- mediafire
  455. end
  456. end
  457. --]]
Add Comment
Please, Sign In to add comment