Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.87 KB | None | 0 0
  1. local hasLoaded = plugin:GetSetting("pluginHasLoaded")
  2. if not hasLoaded then
  3.     plugin:SetSetting("pluginHasLoaded", true)
  4. end
  5.  
  6. local toolbar = plugin:CreateToolbar("Tree Brush")
  7. local button = toolbar:CreateButton(
  8.     "Tree Brush",
  9.     "",
  10.     "http://www.roblox.com/asset/?id=216846095"
  11. )
  12.  
  13. local materials = {
  14.     Enum.Material.Ground;
  15.     Enum.Material.Grass;
  16.     Enum.Material.LeafyGrass;
  17.     Enum.Material.Snow;
  18. }
  19.  
  20.  
  21. --ya boi zcole
  22.  
  23.  
  24. local ChangeHistoryService = game:GetService("ChangeHistoryService")
  25.  
  26. function createGui()
  27.     local ScreenGui = Instance.new("ScreenGui")
  28.     ScreenGui.Parent = workspace
  29.     local Frame1 = Instance.new("Frame")
  30.     Frame1.Name = "Frame1"
  31.     Frame1.Parent = ScreenGui
  32.     Frame1.BackgroundTransparency = 0.5
  33.     Frame1.BackgroundColor3 = Color3.new(1,1,1)
  34.     Frame1.Position = UDim2.new(0,20,0,20)
  35.     Frame1.Size = UDim2.new(0,150,0,200)
  36.     local Frame = Instance.new("Frame")
  37.     Frame.Name = "Frame"
  38.     Frame.Parent = Frame1
  39.     Frame.BackgroundTransparency = 1
  40.     Frame.BackgroundColor3 = Color3.new(1,1,1)
  41.     Frame.Position = UDim2.new(0,10,0,10)
  42.     Frame.Size = UDim2.new(1,-20,1,-20)
  43.     local Size = Instance.new("TextButton")
  44.     Size.Name = "Size1"
  45.     Size.Parent = Frame
  46.     Size.BackgroundTransparency = 1
  47.     Size.BackgroundColor3 = Color3.new(1,1,1)
  48.     Size.Position = UDim2.new(0,0,0,0)
  49.     Size.Size = UDim2.new(1,0,0,10)
  50.     Size.Text = "Size"
  51.     local Size_Slider = Instance.new("TextButton")
  52.     Size_Slider.Name = "Size_Slider"
  53.     Size_Slider.Parent = Frame
  54.     Size_Slider.BackgroundTransparency = 0
  55.     Size_Slider.BackgroundColor3 = Color3.new(0,0,0)
  56.     Size_Slider.Position = UDim2.new(0,0,0,25)
  57.     Size_Slider.Size = UDim2.new(1,0,0,2)
  58.     Size_Slider.Text = ""
  59.     local Button = Instance.new("TextButton")
  60.     Button.Name = "Button"
  61.     Button.Parent = Size_Slider
  62.     Button.BackgroundTransparency = 0
  63.     Button.BackgroundColor3 = Color3.new(1,1,1)
  64.     Button.Position = UDim2.new(0,-8,0,-8)
  65.     Button.Size = UDim2.new(0,16,0,16)
  66.     Button.Text = ""
  67.     local Density = Instance.new("TextButton")
  68.     Density.Name = "Density"
  69.     Density.Parent = Frame
  70.     Density.BackgroundTransparency = 1
  71.     Density.BackgroundColor3 = Color3.new(1,1,1)
  72.     Density.Position = UDim2.new(0,0,0,50)
  73.     Density.Size = UDim2.new(1,0,0,10)
  74.     Density.Text = "Density"
  75.     local Density_Slider = Instance.new("TextButton")
  76.     Density_Slider.Name = "Density_Slider"
  77.     Density_Slider.Parent = Frame
  78.     Density_Slider.BackgroundTransparency = 0
  79.     Density_Slider.BackgroundColor3 = Color3.new(0,0,0)
  80.     Density_Slider.Position = UDim2.new(0,0,0,75)
  81.     Density_Slider.Size = UDim2.new(1,0,0,2)
  82.     Density_Slider.Text = ""
  83.     local Button = Instance.new("TextButton")
  84.     Button.Name = "Button"
  85.     Button.Parent = Density_Slider
  86.     Button.BackgroundTransparency = 0
  87.     Button.BackgroundColor3 = Color3.new(1,1,1)
  88.     Button.Position = UDim2.new(0,-8,0,-8)
  89.     Button.Size = UDim2.new(0,16,0,16)
  90.     Button.Text = ""
  91.     local Label1 = Instance.new("TextLabel")
  92.     Label1.Name = "TitleLabel"
  93.     Label1.Parent = Frame
  94.     Label1.BackgroundTransparency = 1
  95.     Label1.BackgroundColor3 = Color3.new(1,1,1)
  96.     Label1.Position = UDim2.new(0,0,0,100)
  97.     Label1.Size = UDim2.new(1,0,0,10)
  98.     Label1.Text = "Autogen: Finished!"
  99.     local Label2 = Instance.new("TextLabel")
  100.     Label2.Parent = Frame
  101.     Label2.BackgroundTransparency = 1
  102.     Label2.BackgroundColor3 = Color3.new(1,1,1)
  103.     Label2.Position = UDim2.new(0,0,0,120)
  104.     Label2.Size = UDim2.new(1,0,0,10)
  105.     Label2.Text = "Size X      |      Size Y"
  106.     local SizeX = Instance.new("TextBox")
  107.     SizeX.Name = "SizeX"
  108.     SizeX.Parent = Frame
  109.     SizeX.BackgroundTransparency = 0
  110.     SizeX.BackgroundColor3 = Color3.new(1,1,1)
  111.     SizeX.Position = UDim2.new(0,5,0,140)
  112.     SizeX.Size = UDim2.new(.5,-10,0,15)
  113.     SizeX.Text = "0"
  114.     local SizeY = Instance.new("TextBox")
  115.     SizeY.Name = "SizeY"
  116.     SizeY.Parent = Frame
  117.     SizeY.BackgroundTransparency = 0
  118.     SizeY.BackgroundColor3 = Color3.new(1,1,1)
  119.     SizeY.Position = UDim2.new(.5,5,0,140)
  120.     SizeY.Size = UDim2.new(.5,-10,0,15)
  121.     SizeY.Text = "0"
  122.     local Generate = Instance.new("TextButton")
  123.     Generate.Name = "Generate"
  124.     Generate.Parent = Frame
  125.     Generate.BackgroundTransparency = 0
  126.     Generate.BackgroundColor3 = Color3.new(1,1,1)
  127.     Generate.Position = UDim2.new(0.125,0,0,160)
  128.     Generate.Size = UDim2.new(0.75,0,0,20)
  129.     Generate.Text = "Generate"
  130.     return ScreenGui,Size_Slider,Density_Slider,Generate,SizeX,SizeY
  131. end
  132.  
  133. Gui,Size,Density,SValue,DValue,Clicked,Gen,MaxX,MaxY,Generating,ChunkSize = nil,nil,nil,nil,nil,false,nil,nil,nil,false,160
  134.  
  135. button.Click:connect(function()
  136.     if plugin:IsActivated() then
  137.         plugin:Deactivate()
  138.         Gui:Destroy()
  139.         Sphere.Parent = nil
  140.     else
  141.         plugin:Activate(true) -- Neccessary to listen to mouse input
  142.         if Gui then Gui:Destroy() end
  143.         Gui,Size,Density,Gen,MaxX,MaxY = createGui()
  144.         Gui.Parent = game.CoreGui
  145.         SValue = 50
  146.         DValue = 1
  147.         GuiPress()
  148.         local Trees = workspace:FindFirstChild("Trees")
  149.         if Trees == nil or not Trees:IsA("Folder") then
  150.             local Trees = Instance.new("Folder")
  151.             Trees.Parent = workspace
  152.             Trees.Name = "Trees"
  153.         end
  154.     end
  155. end)
  156.    
  157. function createSphere(Size)
  158.     local Ball = Instance.new("Part")
  159.     Ball.Shape = Enum.PartType.Ball
  160.     Ball.Size = Vector3.new(Size,Size,Size)
  161.     Ball.Anchored = true
  162.     Ball.CanCollide = false
  163.     Ball.Transparency = 0.75
  164.     Ball.BrickColor = BrickColor.new("Bright red")
  165.     Ball.TopSurface = Enum.SurfaceType.Smooth
  166.     Ball.BottomSurface = Enum.SurfaceType.Smooth
  167.     return Ball
  168. end
  169.  
  170. -- Setup mouse
  171. local mouse = plugin:GetMouse()
  172. Pressed = false
  173.  
  174. Sphere = createSphere(50)
  175.  
  176. mouse.Button1Down:connect(function()   
  177.     if game.ServerStorage:FindFirstChild("Trees") ~= nil then
  178.         Pressed = true
  179.         Sphere.Parent = workspace.Trees
  180.         mouse.TargetFilter = workspace.Trees
  181.         Sphere.Transparency = 1-((DValue/25)*.75)
  182.         repeat
  183.             local target = mouse.Target
  184.             local hit = mouse.Hit
  185.             local Touching = Sphere:GetTouchingParts()
  186.            
  187.             Sphere.CFrame = CFrame.new(mouse.Hit.p)
  188.             local NumberOfTrees = SValue * (DValue/100)
  189.             for i = 1,NumberOfTrees do
  190.                 if #Touching < NumberOfTrees then
  191.                     PlaceTree(Sphere.Position)
  192.                 end
  193.             end
  194.            
  195.             wait()
  196.         until Pressed == false
  197.         Sphere.Transparency = 0.95
  198.         ChangeHistoryService:SetWaypoint("Drew Terrain")
  199.     else
  200.         print("Tree folder missing from game.ServerStorage")
  201.     end
  202. end)
  203.  
  204. mouse.Button1Up:connect(function()
  205.     if Clicked then
  206.         Clicked = false
  207.     end
  208.     Pressed = false
  209.     repeat wait()
  210.         Sphere.CFrame = mouse.Hit
  211.     until Pressed or not plugin:IsActivated()
  212. end)
  213.  
  214.  
  215. function PlaceTree(Position)
  216.     local CF = CFrame.new(Position) * CFrame.Angles(0,math.rad(math.random(0,360)),0)
  217.     CF = CF * CFrame.new(math.random(0,Sphere.Size.z/2),0,0)
  218.     Position = CF.p
  219.     local Start = Vector3.new(Position.x,300,Position.z)
  220.     local End   = Vector3.new(Position.x,0,Position.z)
  221.    
  222.     local ray = Ray.new(Start, (End - Start).unit*750)
  223.    
  224.     local part,pos,a,mat = workspace:FindPartOnRay(ray,workspace.Trees)
  225.     if part ~= nil and part == workspace.Terrain and verifyMat(mat) then
  226.         local T = game.ServerStorage.Trees:GetChildren()
  227.         local t = math.random(1,#T)
  228.         local tree = T[t]:clone()
  229.         local size = math.random(70,120)/100
  230.         tree.Size = tree.Size*size
  231.         tree.CFrame = CFrame.new(pos.x,pos.y,pos.z)*CFrame.Angles(0,math.rad(math.random(0,359)),0)*CFrame.new(0,tree.Size.Y/2-0.4,0)
  232.         tree.Parent = workspace.Trees
  233.     end
  234. end
  235.  
  236. function verifyMat(val)
  237.     for _,v in pairs(materials) do
  238.         if v == val then
  239.             return true
  240.         end
  241.     end
  242.     return false
  243. end
  244.  
  245. function generateTrees(X,Y,D)
  246.     if game.ServerStorage:FindFirstChild("Trees") == nil then print("Tree folder missing from game.ServerStorage") return end
  247.     Generating = true
  248.     local RemX,RemY = X%ChunkSize,Y%ChunkSize
  249.     local ChunksX,ChunksY = (X-RemX)/ChunkSize,(Y-RemY)/ChunkSize
  250.     local tot = (ChunksX+1)*(ChunksY+1)
  251.     local cur = 0
  252.     for x = 1,ChunksX + (RemX > 0 and 1 or 0) do
  253.         for y = 1,ChunksY + (RemY > 0 and 1 or 0) do
  254.             if plugin:IsActivated() ~= true then ChangeHistoryService:SetWaypoint("Generated Trees") Generating = false return end
  255.             local lcy,lcx = ChunkSize,ChunkSize
  256.             if y > ChunksY then lcy = RemY end
  257.             if x > ChunksX then lcx = RemX end
  258.             local size = ((lcy/ChunkSize)+(lcx/ChunkSize))/2
  259.             local Position = Vector3.new(((-X/2) + (x-1)*ChunkSize)+(lcx/2), 500, ((-Y/2) + (y-1)*ChunkSize)+(lcy/2))
  260.             for i = 1,math.floor(D * size) do
  261.                 PlaceTree(Vector3.new(Position.x + math.random(-lcx/2,lcx/2),Position.y + .5,Position.z + math.random(-lcy/2,lcy/2)))
  262.             end
  263.             cur=cur+1
  264.         end
  265.         Gui.Frame1.Frame.TitleLabel.Text = ("Autogen: " .. (math.floor((cur / tot) * 100)/100) .. "%")
  266.         wait()
  267.     end
  268.     Gui.Frame1.Frame.TitleLabel.Text = "Autogen: Finished!"
  269.     ChangeHistoryService:SetWaypoint("Generated Trees")
  270.     Generating = false
  271. end
  272.  
  273. function GuiPress()
  274.     Size.Button.MouseButton1Down:connect(function()
  275.         Clicked = true
  276.         repeat
  277.             Size.Button.Position = UDim2.new(0,math.clamp(mouse.x - Size.AbsolutePosition.x - 8,-8,122),0,-8)
  278.             SValue = math.floor(math.clamp(((Size.Button.Position.X.Offset + 8)/130)+.05,.05,1) * 1000)
  279.             Sphere.Size = Vector3.new(SValue,SValue,SValue)
  280.             Gui.Frame1.Frame.Size1.Text = "Size: "..SValue
  281.             wait()
  282.         until Clicked == false
  283.     end)
  284.  
  285.     Density.Button.MouseButton1Down:connect(function()
  286.         Clicked = true
  287.         repeat
  288.             Density.Button.Position = UDim2.new(0,math.clamp(mouse.x - Density.AbsolutePosition.x - 8,-8,122),0,-8)
  289.             DValue = math.floor(math.clamp(((Density.Button.Position.X.Offset + 8)/130)+.25,.1,1) * 25)
  290.             Gui.Frame1.Frame.Density.Text = "Density: ".. DValue
  291.             wait()
  292.         until Clicked == false
  293.     end)
  294.  
  295.     Size.Button.MouseButton1Up:connect(function()
  296.         if Clicked then
  297.             Clicked = false
  298.         end
  299.     end)
  300.  
  301.     Density.Button.MouseButton1Up:connect(function()
  302.         if Clicked then
  303.             Clicked = false
  304.         end
  305.     end)
  306.    
  307.     Gen.MouseButton1Down:connect(function()
  308.         if Generating ~= true and tonumber(MaxX.Text) and tonumber(MaxY.Text) and tonumber(MaxX.Text) > 0 and tonumber(MaxX.Text) <= 10000 and tonumber(MaxY.Text) > 0 and tonumber(MaxY.Text) <= 10000 then
  309.             generateTrees(tonumber(MaxX.Text),tonumber(MaxY.Text),DValue)
  310.         end
  311.     end)
  312.  
  313. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement