Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local hasLoaded = plugin:GetSetting("pluginHasLoaded")
- if not hasLoaded then
- plugin:SetSetting("pluginHasLoaded", true)
- end
- local toolbar = plugin:CreateToolbar("Tree Brush")
- local button = toolbar:CreateButton(
- "Tree Brush",
- "",
- "http://www.roblox.com/asset/?id=216846095"
- )
- local materials = {
- Enum.Material.Ground;
- Enum.Material.Grass;
- Enum.Material.LeafyGrass;
- Enum.Material.Snow;
- }
- --ya boi zcole
- local ChangeHistoryService = game:GetService("ChangeHistoryService")
- function createGui()
- local ScreenGui = Instance.new("ScreenGui")
- ScreenGui.Parent = workspace
- local Frame1 = Instance.new("Frame")
- Frame1.Name = "Frame1"
- Frame1.Parent = ScreenGui
- Frame1.BackgroundTransparency = 0.5
- Frame1.BackgroundColor3 = Color3.new(1,1,1)
- Frame1.Position = UDim2.new(0,20,0,20)
- Frame1.Size = UDim2.new(0,150,0,200)
- local Frame = Instance.new("Frame")
- Frame.Name = "Frame"
- Frame.Parent = Frame1
- Frame.BackgroundTransparency = 1
- Frame.BackgroundColor3 = Color3.new(1,1,1)
- Frame.Position = UDim2.new(0,10,0,10)
- Frame.Size = UDim2.new(1,-20,1,-20)
- local Size = Instance.new("TextButton")
- Size.Name = "Size1"
- Size.Parent = Frame
- Size.BackgroundTransparency = 1
- Size.BackgroundColor3 = Color3.new(1,1,1)
- Size.Position = UDim2.new(0,0,0,0)
- Size.Size = UDim2.new(1,0,0,10)
- Size.Text = "Size"
- local Size_Slider = Instance.new("TextButton")
- Size_Slider.Name = "Size_Slider"
- Size_Slider.Parent = Frame
- Size_Slider.BackgroundTransparency = 0
- Size_Slider.BackgroundColor3 = Color3.new(0,0,0)
- Size_Slider.Position = UDim2.new(0,0,0,25)
- Size_Slider.Size = UDim2.new(1,0,0,2)
- Size_Slider.Text = ""
- local Button = Instance.new("TextButton")
- Button.Name = "Button"
- Button.Parent = Size_Slider
- Button.BackgroundTransparency = 0
- Button.BackgroundColor3 = Color3.new(1,1,1)
- Button.Position = UDim2.new(0,-8,0,-8)
- Button.Size = UDim2.new(0,16,0,16)
- Button.Text = ""
- local Density = Instance.new("TextButton")
- Density.Name = "Density"
- Density.Parent = Frame
- Density.BackgroundTransparency = 1
- Density.BackgroundColor3 = Color3.new(1,1,1)
- Density.Position = UDim2.new(0,0,0,50)
- Density.Size = UDim2.new(1,0,0,10)
- Density.Text = "Density"
- local Density_Slider = Instance.new("TextButton")
- Density_Slider.Name = "Density_Slider"
- Density_Slider.Parent = Frame
- Density_Slider.BackgroundTransparency = 0
- Density_Slider.BackgroundColor3 = Color3.new(0,0,0)
- Density_Slider.Position = UDim2.new(0,0,0,75)
- Density_Slider.Size = UDim2.new(1,0,0,2)
- Density_Slider.Text = ""
- local Button = Instance.new("TextButton")
- Button.Name = "Button"
- Button.Parent = Density_Slider
- Button.BackgroundTransparency = 0
- Button.BackgroundColor3 = Color3.new(1,1,1)
- Button.Position = UDim2.new(0,-8,0,-8)
- Button.Size = UDim2.new(0,16,0,16)
- Button.Text = ""
- local Label1 = Instance.new("TextLabel")
- Label1.Name = "TitleLabel"
- Label1.Parent = Frame
- Label1.BackgroundTransparency = 1
- Label1.BackgroundColor3 = Color3.new(1,1,1)
- Label1.Position = UDim2.new(0,0,0,100)
- Label1.Size = UDim2.new(1,0,0,10)
- Label1.Text = "Autogen: Finished!"
- local Label2 = Instance.new("TextLabel")
- Label2.Parent = Frame
- Label2.BackgroundTransparency = 1
- Label2.BackgroundColor3 = Color3.new(1,1,1)
- Label2.Position = UDim2.new(0,0,0,120)
- Label2.Size = UDim2.new(1,0,0,10)
- Label2.Text = "Size X | Size Y"
- local SizeX = Instance.new("TextBox")
- SizeX.Name = "SizeX"
- SizeX.Parent = Frame
- SizeX.BackgroundTransparency = 0
- SizeX.BackgroundColor3 = Color3.new(1,1,1)
- SizeX.Position = UDim2.new(0,5,0,140)
- SizeX.Size = UDim2.new(.5,-10,0,15)
- SizeX.Text = "0"
- local SizeY = Instance.new("TextBox")
- SizeY.Name = "SizeY"
- SizeY.Parent = Frame
- SizeY.BackgroundTransparency = 0
- SizeY.BackgroundColor3 = Color3.new(1,1,1)
- SizeY.Position = UDim2.new(.5,5,0,140)
- SizeY.Size = UDim2.new(.5,-10,0,15)
- SizeY.Text = "0"
- local Generate = Instance.new("TextButton")
- Generate.Name = "Generate"
- Generate.Parent = Frame
- Generate.BackgroundTransparency = 0
- Generate.BackgroundColor3 = Color3.new(1,1,1)
- Generate.Position = UDim2.new(0.125,0,0,160)
- Generate.Size = UDim2.new(0.75,0,0,20)
- Generate.Text = "Generate"
- return ScreenGui,Size_Slider,Density_Slider,Generate,SizeX,SizeY
- end
- Gui,Size,Density,SValue,DValue,Clicked,Gen,MaxX,MaxY,Generating,ChunkSize = nil,nil,nil,nil,nil,false,nil,nil,nil,false,160
- button.Click:connect(function()
- if plugin:IsActivated() then
- plugin:Deactivate()
- Gui:Destroy()
- Sphere.Parent = nil
- else
- plugin:Activate(true) -- Neccessary to listen to mouse input
- if Gui then Gui:Destroy() end
- Gui,Size,Density,Gen,MaxX,MaxY = createGui()
- Gui.Parent = game.CoreGui
- SValue = 50
- DValue = 1
- GuiPress()
- local Trees = workspace:FindFirstChild("Trees")
- if Trees == nil or not Trees:IsA("Folder") then
- local Trees = Instance.new("Folder")
- Trees.Parent = workspace
- Trees.Name = "Trees"
- end
- end
- end)
- function createSphere(Size)
- local Ball = Instance.new("Part")
- Ball.Shape = Enum.PartType.Ball
- Ball.Size = Vector3.new(Size,Size,Size)
- Ball.Anchored = true
- Ball.CanCollide = false
- Ball.Transparency = 0.75
- Ball.BrickColor = BrickColor.new("Bright red")
- Ball.TopSurface = Enum.SurfaceType.Smooth
- Ball.BottomSurface = Enum.SurfaceType.Smooth
- return Ball
- end
- -- Setup mouse
- local mouse = plugin:GetMouse()
- Pressed = false
- Sphere = createSphere(50)
- mouse.Button1Down:connect(function()
- if game.ServerStorage:FindFirstChild("Trees") ~= nil then
- Pressed = true
- Sphere.Parent = workspace.Trees
- mouse.TargetFilter = workspace.Trees
- Sphere.Transparency = 1-((DValue/25)*.75)
- repeat
- local target = mouse.Target
- local hit = mouse.Hit
- local Touching = Sphere:GetTouchingParts()
- Sphere.CFrame = CFrame.new(mouse.Hit.p)
- local NumberOfTrees = SValue * (DValue/100)
- for i = 1,NumberOfTrees do
- if #Touching < NumberOfTrees then
- PlaceTree(Sphere.Position)
- end
- end
- wait()
- until Pressed == false
- Sphere.Transparency = 0.95
- ChangeHistoryService:SetWaypoint("Drew Terrain")
- else
- print("Tree folder missing from game.ServerStorage")
- end
- end)
- mouse.Button1Up:connect(function()
- if Clicked then
- Clicked = false
- end
- Pressed = false
- repeat wait()
- Sphere.CFrame = mouse.Hit
- until Pressed or not plugin:IsActivated()
- end)
- function PlaceTree(Position)
- local CF = CFrame.new(Position) * CFrame.Angles(0,math.rad(math.random(0,360)),0)
- CF = CF * CFrame.new(math.random(0,Sphere.Size.z/2),0,0)
- Position = CF.p
- local Start = Vector3.new(Position.x,300,Position.z)
- local End = Vector3.new(Position.x,0,Position.z)
- local ray = Ray.new(Start, (End - Start).unit*750)
- local part,pos,a,mat = workspace:FindPartOnRay(ray,workspace.Trees)
- if part ~= nil and part == workspace.Terrain and verifyMat(mat) then
- local T = game.ServerStorage.Trees:GetChildren()
- local t = math.random(1,#T)
- local tree = T[t]:clone()
- local size = math.random(70,120)/100
- tree.Size = tree.Size*size
- 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)
- tree.Parent = workspace.Trees
- end
- end
- function verifyMat(val)
- for _,v in pairs(materials) do
- if v == val then
- return true
- end
- end
- return false
- end
- function generateTrees(X,Y,D)
- if game.ServerStorage:FindFirstChild("Trees") == nil then print("Tree folder missing from game.ServerStorage") return end
- Generating = true
- local RemX,RemY = X%ChunkSize,Y%ChunkSize
- local ChunksX,ChunksY = (X-RemX)/ChunkSize,(Y-RemY)/ChunkSize
- local tot = (ChunksX+1)*(ChunksY+1)
- local cur = 0
- for x = 1,ChunksX + (RemX > 0 and 1 or 0) do
- for y = 1,ChunksY + (RemY > 0 and 1 or 0) do
- if plugin:IsActivated() ~= true then ChangeHistoryService:SetWaypoint("Generated Trees") Generating = false return end
- local lcy,lcx = ChunkSize,ChunkSize
- if y > ChunksY then lcy = RemY end
- if x > ChunksX then lcx = RemX end
- local size = ((lcy/ChunkSize)+(lcx/ChunkSize))/2
- local Position = Vector3.new(((-X/2) + (x-1)*ChunkSize)+(lcx/2), 500, ((-Y/2) + (y-1)*ChunkSize)+(lcy/2))
- for i = 1,math.floor(D * size) do
- PlaceTree(Vector3.new(Position.x + math.random(-lcx/2,lcx/2),Position.y + .5,Position.z + math.random(-lcy/2,lcy/2)))
- end
- cur=cur+1
- end
- Gui.Frame1.Frame.TitleLabel.Text = ("Autogen: " .. (math.floor((cur / tot) * 100)/100) .. "%")
- wait()
- end
- Gui.Frame1.Frame.TitleLabel.Text = "Autogen: Finished!"
- ChangeHistoryService:SetWaypoint("Generated Trees")
- Generating = false
- end
- function GuiPress()
- Size.Button.MouseButton1Down:connect(function()
- Clicked = true
- repeat
- Size.Button.Position = UDim2.new(0,math.clamp(mouse.x - Size.AbsolutePosition.x - 8,-8,122),0,-8)
- SValue = math.floor(math.clamp(((Size.Button.Position.X.Offset + 8)/130)+.05,.05,1) * 1000)
- Sphere.Size = Vector3.new(SValue,SValue,SValue)
- Gui.Frame1.Frame.Size1.Text = "Size: "..SValue
- wait()
- until Clicked == false
- end)
- Density.Button.MouseButton1Down:connect(function()
- Clicked = true
- repeat
- Density.Button.Position = UDim2.new(0,math.clamp(mouse.x - Density.AbsolutePosition.x - 8,-8,122),0,-8)
- DValue = math.floor(math.clamp(((Density.Button.Position.X.Offset + 8)/130)+.25,.1,1) * 25)
- Gui.Frame1.Frame.Density.Text = "Density: ".. DValue
- wait()
- until Clicked == false
- end)
- Size.Button.MouseButton1Up:connect(function()
- if Clicked then
- Clicked = false
- end
- end)
- Density.Button.MouseButton1Up:connect(function()
- if Clicked then
- Clicked = false
- end
- end)
- Gen.MouseButton1Down:connect(function()
- 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
- generateTrees(tonumber(MaxX.Text),tonumber(MaxY.Text),DValue)
- end
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement