knowyourmom12

Untitled

Sep 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.04 KB | None | 0 0
  1. -- Player declarations
  2. local player = game.Players.luxulux
  3. local char = player.Character
  4.  
  5. -- Body parts
  6. local torso = char.Torso
  7.  
  8. -- Tool declarations
  9. local mouseDown = false
  10. local keysDown = {}
  11.  
  12. -- Earth bending declarations
  13. local raisingEarth = false
  14. local raisingTower = false
  15. local groundAttack = false
  16. local lastTower = nil
  17. local disabled = {}
  18. local frames = {}
  19. local parts = {}
  20.  
  21. -- Main
  22. function main(mouse)
  23. while true do wait(1/30)
  24. local look = CFrame.new(torso.Position, torso.Position + mouse.Hit.lookVector)
  25.  
  26. -- Reset parts
  27. parts = {}
  28.  
  29. -- Get parts
  30. for x = -20, 20, 10 do
  31. for y = -20, 20, 10 do
  32. for z = -30, -10, 10 do
  33. local pos = look * Vector3.new(x, y, z)
  34. getPartsInRegion3(
  35. Region3.new(
  36. pos + Vector3.new(1,1,1)*-9,
  37. pos + Vector3.new(1,1,1)* 9
  38. ),
  39. parts
  40. )
  41. end
  42. end
  43. end
  44.  
  45. -- Mouse down
  46. if mouseDown then
  47. -- Create dif and bodies
  48. for _, part in pairs(parts) do
  49. if part.Name == "Earth" and not disabled[part] then
  50. if not frames[part] and part ~= lastTower then
  51. frames[part] = look:toObjectSpace(part.CFrame)
  52.  
  53. part:ClearAllChildren()
  54. part.Anchored = false
  55.  
  56. -- Create bodies
  57. createBody("Position", part)
  58. createBody("Gyro", part)
  59. end
  60. end
  61. end
  62.  
  63. -- Move bodies
  64. for part in pairs(frames) do
  65. local bodyPos = part:FindFirstChild("BodyPosition")
  66. local bodyGyr = part:FindFirstChild("BodyGyro")
  67.  
  68. -- Bodies exist
  69. if bodyPos and bodyGyr then
  70. local dif = look * frames[part]
  71.  
  72. bodyPos.position = dif.p
  73. bodyGyr.cframe = dif
  74. else
  75. frames[part] = nil
  76. end
  77. end
  78. else
  79. for part in pairs(frames) do
  80. if part.Name == "Earth" then
  81. frames[part] = nil
  82.  
  83. part:ClearAllChildren()
  84. end
  85. end
  86. end
  87. end
  88. end
  89.  
  90. -- On key change
  91. function onKeyChange(mouse, key, state)
  92. -- Raise earth
  93. if key == "e" and state and not raisingEarth then
  94. raisingEarth = true
  95. while keysDown[key] do
  96. local torsoY = torso.Position.y + 3
  97. local pos = planeY(torso.Position, 0.4 - 4/2)
  98. local dir = planeY(mouse.Hit.lookVector).unit
  99. local frame = CFrame.new(pos, pos + dir) * CFrame.new(r(-10, 10), 0, r(-20, -5))
  100.  
  101. -- Create earth part
  102. local part = createEarth(workspace)
  103. part.Anchored = true
  104. part.Size = Vector3.new(4, 4, 4)
  105. disabled[part] = true
  106.  
  107. -- Raise earth
  108. for i = 1, 4 do i = i/4
  109. part.CFrame = frame * CFrame.new(0, (torsoY - frame.y)*i, 0)
  110. wait(1/30)
  111. if not part.Anchored then
  112. break
  113. end
  114. end
  115.  
  116. disabled[part] = nil
  117. part.Anchored = false
  118.  
  119. wait(1/10)
  120. end
  121. raisingEarth = false
  122.  
  123. -- Push earth
  124. elseif key == "f" and state then
  125. for _, part in pairs(parts) do
  126. if part.Name == "Earth" and part ~= lastTower then
  127. part:ClearAllChildren()
  128. part.Anchored = false
  129.  
  130. -- Add force
  131. local bodyForce = createBody("Force", part)
  132. bodyForce.force = mouse.Hit.lookVector*1.5e4 * part:GetMass()
  133.  
  134. game.Debris:AddItem(bodyForce, 1/30)
  135.  
  136. -- Disable part
  137. disabled[part] = true
  138. delay(1, function()
  139. disabled[part] = nil
  140. end)
  141. end
  142. end
  143.  
  144. -- Break earth
  145. elseif key == "b" and state then
  146. for part in pairs(frames) do
  147. if part.Size == Vector3.new(4, 4, 4) then
  148. for x = -1, 1, 2 do
  149. for y = -1, 1, 2 do
  150. for z = -1, 1, 2 do
  151. local oPart = createEarth(workspace)
  152. oPart.Size = Vector3.new(2, 2, 2)
  153. oPart.CFrame = part.CFrame * CFrame.new(x*1.1, y*1.1, z*1.1)
  154. end
  155. end
  156. end
  157. part:Destroy()
  158. end
  159. end
  160.  
  161. -- Raise tower
  162. elseif key == "r" and state and not raisingTower then
  163. raisingTower = true
  164. lastTower = nil
  165. if torso.Position.y - 5/2 < 20.4 then
  166. local part = createEarth(workspace)
  167. part.Anchored = true
  168. disabled[part] = true
  169.  
  170. for i = 0, 20, 4 do
  171. part.Size = Vector3.new(5, i, 5)
  172. part.CFrame = CFrame.new(torso.Position.x, 0.4 + part.Size.y/2, torso.Position.z)
  173. torso.CFrame = (torso.CFrame - torso.CFrame.p) + Vector3.new(torso.Position.x, part.Position.y + part.Size.y/2 + 5/2, torso.Position.z)
  174. wait(1/30)
  175. end
  176.  
  177. lastTower = part
  178.  
  179. disabled[part] = nil
  180. part.Anchored = false
  181. end
  182. raisingTower = false
  183.  
  184. -- Ground attack
  185. elseif key == "g" and state and not groundAttack then
  186. groundAttack = true
  187. delay(1, function()
  188. groundAttack = false
  189. end)
  190.  
  191. local dir = planeY(mouse.Hit.p - torso.Position).unit
  192. local pos = planeY(torso.Position, 0.4 + 1) + dir*5
  193.  
  194. local ground = {}
  195.  
  196. delay(5, function()
  197. for i = 1, 20 do
  198. for _, part in pairs(ground) do
  199. if part.Anchored then
  200. part.CFrame = part.CFrame + Vector3.new(0, -1/7, 0)
  201. end
  202. end
  203. wait(1/30)
  204. end
  205. for _, part in pairs(ground) do
  206. if part.Anchored then
  207. part:Destroy()
  208. end
  209. end
  210. end)
  211.  
  212. for i = 1, 10 do
  213. local hit, pos2 = rayCast(pos, dir*5, {char})
  214.  
  215. local part = createEarth(workspace)
  216. part.Anchored = true
  217. part.Size = Vector3.new(2, 4, 2)
  218. part.CFrame = CFrame.new(pos2, pos2 + dir) * CFrame.Angles(math.rad(-50), 0, 0) + Vector3.new(0, -0, 0)
  219.  
  220. ground[#ground + 1] = part
  221.  
  222. -- Add force
  223. if hit then
  224. local mass = hit:GetMass()
  225.  
  226. -- Hit player
  227. for _, oPlayer in pairs(game.Players:GetPlayers()) do
  228. if oPlayer.Character and oPlayer.Character:FindFirstChild("Torso") and hit:IsDescendantOf(oPlayer.Character) then
  229. hit = oPlayer.Character.Torso
  230. mass = 20
  231. end
  232. end
  233.  
  234. if hit.Name ~= "Torso" then
  235. hit:ClearAllChildren()
  236. end
  237. hit.Anchored = false
  238.  
  239. -- Add force
  240. local bodyForce = createBody("Force", hit)
  241. bodyForce.force = (dir + Vector3.new(0, 0.2, 0)).unit*1e4 * mass
  242.  
  243. game.Debris:AddItem(bodyForce, 1/30)
  244. break
  245. end
  246.  
  247. pos = pos2
  248. wait(1/20)
  249. end
  250. end
  251. end
  252.  
  253. --- CORE CODE BELOW --- CORE CODE BELOW --- CORE CODE BELOW ---
  254. --- CORE CODE BELOW --- CORE CODE BELOW --- CORE CODE BELOW ---
  255. --- CORE CODE BELOW --- CORE CODE BELOW --- CORE CODE BELOW ---
  256.  
  257. -- Clear old tool
  258. player.Backpack:ClearAllChildren()
  259.  
  260. -- Create tool
  261. local tool = Instance.new("HopperBin")
  262. tool.Parent = player.Backpack
  263. tool.Name = "Earth Bending"
  264.  
  265. -- Tool selected
  266. tool.Selected:connect(function(mouse)
  267. mouse.Icon = "rbxasset://textures\\GunCursor.png"
  268.  
  269. -- Mouse events
  270. mouse.Button1Down:connect(function()
  271. mouseDown = true
  272. end)
  273. mouse.Button1Up:connect(function()
  274. mouseDown = false
  275. end)
  276. mouse.KeyDown:connect(function(key)
  277. keysDown[key:lower()] = true
  278. onKeyChange(mouse, key:lower(), true)
  279. end)
  280. mouse.KeyUp:connect(function(key)
  281. keysDown[key:lower()] = false
  282. onKeyChange(mouse, key:lower(), false)
  283. end)
  284.  
  285. -- Call main
  286. main(mouse)
  287. end)
  288.  
  289. --- LIBRARY BELOW --- LIBRARY BELOW --- LIBRARY BELOW ---
  290. --- LIBRARY BELOW --- LIBRARY BELOW --- LIBRARY BELOW ---
  291. --- LIBRARY BELOW --- LIBRARY BELOW --- LIBRARY BELOW ---
  292.  
  293. -- Ray cast
  294. function rayCast(pos, dir, ignore)
  295. return workspace:FindPartOnRayWithIgnoreList(Ray.new(pos, dir), ignore)
  296. end
  297.  
  298. -- Create body
  299. function createBody(type, path)
  300. local body = Instance.new("Body" .. type)
  301. if type == "Gyro" then
  302. body.maxTorque = Vector3.new(math.huge, math.huge, math.huge)
  303. elseif type ~= "Force" then
  304. body.maxForce = Vector3.new(math.huge, math.huge, math.huge)
  305. end
  306. body.Parent = path
  307. return body
  308. end
  309.  
  310. -- Get parts in region 3
  311. function getPartsInRegion3(region, parts)
  312. repeat
  313. local regParts = workspace:FindPartsInRegion3WithIgnoreList(region, parts, 100)
  314. for i, part in pairs(regParts) do
  315. parts[#parts + 1] = part
  316. end
  317. until #regParts < 100
  318. end
  319.  
  320. -- Random
  321. function r(min, max)
  322. return math.random()*(max - min) + min
  323. end
  324.  
  325. -- Plane y
  326. function planeY(v, y)
  327. return Vector3.new(v.x, y or 0, v.z)
  328. end
  329.  
  330. -- Create earth
  331. function createEarth(path)
  332. local part = createPart("Earth", path)
  333. part.BrickColor = BrickColor.new("Brown")
  334. part.Material = "Slate"
  335. part.Parent = path
  336. return part
  337. end
  338.  
  339. -- Create part
  340. function createPart(name, path)
  341. local part = Instance.new("Part")
  342. part.FormFactor = "Symmetric"
  343. part.BottomSurface = "Smooth"
  344. part.TopSurface = "Smooth"
  345. part.Size = Vector3.new(1, 1, 1)
  346. part.Name = name
  347. part.Parent = path
  348. return part
  349. end
Add Comment
Please, Sign In to add comment