Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.71 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.  
  8. local button = toolbar:CreateButton(
  9.     "Tree Brush",
  10.     "",
  11.     "http://www.roblox.com/asset/?id=216846095"
  12. )
  13. local ChangeHistoryService = game:GetService("ChangeHistoryService")
  14. function createGui()
  15.     local ScreenGui = Instance.new("ScreenGui")
  16.     ScreenGui.Parent = workspace
  17.     local Frame1 = Instance.new("Frame")
  18.     Frame1.Name = "Frame1"
  19.     Frame1.Parent = ScreenGui
  20.     Frame1.BackgroundTransparency = 0.5
  21.     Frame1.BackgroundColor3 = Color3.new(1,1,1)
  22.     Frame1.Position = UDim2.new(0,20,0,20)
  23.     Frame1.Size = UDim2.new(0,150,0,250)
  24.     local Frame = Instance.new("Frame")
  25.     Frame.Name = "Frame"
  26.     Frame.Parent = Frame1
  27.     Frame.BackgroundTransparency = 1
  28.     Frame.BackgroundColor3 = Color3.new(1,1,1)
  29.     Frame.Position = UDim2.new(0,10,0,10)
  30.     Frame.Size = UDim2.new(1,-20,1,-20)
  31.     local Size = Instance.new("TextButton")
  32.     Size.Name = "Size1"
  33.     Size.Parent = Frame
  34.     Size.BackgroundTransparency = 1
  35.     Size.BackgroundColor3 = Color3.new(1,1,1)
  36.     Size.Position = UDim2.new(0,0,0,0)
  37.     Size.Size = UDim2.new(1,0,0,10)
  38.     Size.Text = "Size"
  39.     local Size_Slider = Instance.new("TextButton")
  40.     Size_Slider.Name = "Size_Slider"
  41.     Size_Slider.Parent = Frame
  42.     Size_Slider.BackgroundTransparency = 0
  43.     Size_Slider.BackgroundColor3 = Color3.new(0,0,0)
  44.     Size_Slider.Position = UDim2.new(0,0,0,25)
  45.     Size_Slider.Size = UDim2.new(1,0,0,2)
  46.     Size_Slider.Text = ""
  47.     local Button = Instance.new("TextButton")
  48.     Button.Name = "Button"
  49.     Button.Parent = Size_Slider
  50.     Button.BackgroundTransparency = 0
  51.     Button.BackgroundColor3 = Color3.new(1,1,1)
  52.     Button.Position = UDim2.new(0,-8,0,-8)
  53.     Button.Size = UDim2.new(0,16,0,16)
  54.     Button.Text = ""
  55.     local Density = Instance.new("TextButton")
  56.     Density.Name = "Density"
  57.     Density.Parent = Frame
  58.     Density.BackgroundTransparency = 1
  59.     Density.BackgroundColor3 = Color3.new(1,1,1)
  60.     Density.Position = UDim2.new(0,0,0,50)
  61.     Density.Size = UDim2.new(1,0,0,10)
  62.     Density.Text = "Density"
  63.     local Density_Slider = Instance.new("TextButton")
  64.     Density_Slider.Name = "Density_Slider"
  65.     Density_Slider.Parent = Frame
  66.     Density_Slider.BackgroundTransparency = 0
  67.     Density_Slider.BackgroundColor3 = Color3.new(0,0,0)
  68.     Density_Slider.Position = UDim2.new(0,0,0,75)
  69.     Density_Slider.Size = UDim2.new(1,0,0,2)
  70.     Density_Slider.Text = ""
  71.     local Button = Instance.new("TextButton")
  72.     Button.Name = "Button"
  73.     Button.Parent = Density_Slider
  74.     Button.BackgroundTransparency = 0
  75.     Button.BackgroundColor3 = Color3.new(1,1,1)
  76.     Button.Position = UDim2.new(0,-8,0,-8)
  77.     Button.Size = UDim2.new(0,16,0,16)
  78.     Button.Text = ""
  79.     return ScreenGui
  80. end
  81.  
  82. Gui,Size,Density,SValue,DValue,Clicked = nil,nil,nil,nil,nil,false
  83.  
  84. button.Click:connect(function()
  85.     if plugin:IsActivated() then
  86.         plugin:Deactivate()
  87.         Gui:Destroy()
  88.         Sphere.Parent = nil
  89.     else
  90.         plugin:Activate(true) -- Neccessary to listen to mouse input'
  91.         Gui = createGui()
  92.         Gui.Parent = game.CoreGui
  93.         Size = Gui.Frame1.Frame.Size_Slider
  94.         Density = Gui.Frame1.Frame.Density_Slider
  95.         SValue = 50
  96.         DValue = 1
  97.         GuiPress()
  98.         local Trees = workspace:FindFirstChild("Trees")
  99.         if Trees == nil or not Trees:IsA("Folder") then
  100.             local Trees = Instance.new("Folder")
  101.             Trees.Parent = workspace
  102.             Trees.Name = "Trees"
  103.         end
  104.     end
  105. end)
  106.  
  107. -- function
  108.    
  109. function createSphere(Size)
  110.     local Ball = Instance.new("Part")
  111.     Ball.Shape = Enum.PartType.Ball
  112.     Ball.Size = Vector3.new(Size,Size,Size)
  113.     Ball.Anchored = true
  114.     Ball.Transparency = 0.75
  115.     Ball.BrickColor = BrickColor.new("Bright red")
  116.     Ball.TopSurface = Enum.SurfaceType.Smooth
  117.     Ball.BottomSurface = Enum.SurfaceType.Smooth
  118.     return Ball
  119. end
  120.  
  121. -- Setup mouse
  122. local mouse = plugin:GetMouse()
  123. Pressed = false
  124.  
  125. Sphere = createSphere(50)
  126.  
  127. mouse.Button1Down:connect(function() -- Binds function to left click   
  128.     if game.ServerStorage:FindFirstChild("Trees") ~= nil then
  129.         Pressed = true
  130.         Sphere.Parent = workspace.Trees
  131.         mouse.TargetFilter = workspace.Trees
  132.         repeat
  133.             local target = mouse.Target
  134.             local hit = mouse.Hit
  135.             local Touching = Sphere:GetTouchingParts()
  136.            
  137.             Sphere.CFrame = CFrame.new(mouse.Hit.p)
  138.             NumberOfTrees = SValue * (DValue/100)--.5 Tree per stud max, .02 Trees per stud min
  139.             for i = 1,NumberOfTrees do
  140.                 if #Touching < NumberOfTrees then
  141.                     PlaceTree(Sphere.Position)
  142.                 end
  143.             end
  144.            
  145.             wait()
  146.         until Pressed == false
  147.         Sphere.Transparency = 0.95
  148.         ChangeHistoryService:SetWaypoint("Drew Terrain")
  149.     else
  150.         print("Tree folder missing from game.ServerStorage")
  151.     end
  152. end)
  153.  
  154. mouse.Button1Up:connect(function()
  155.     if Clicked then
  156.         Clicked = false
  157.     end
  158.     Pressed = false
  159.     repeat wait()
  160.         Sphere.CFrame = mouse.Hit
  161.     until Pressed or not plugin:IsActivated()
  162. end)
  163.  
  164.  
  165. function PlaceTree(Position)
  166.     local CF = CFrame.new(Position) * CFrame.Angles(0,math.rad(math.random(0,360)),0)
  167.     CF = CF * CFrame.new(math.random(0,Sphere.Size.z/2),0,0)
  168.     Position = CF.p
  169.     local Start = Vector3.new(Position.x,300,Position.z)
  170.     local End   = Vector3.new(Position.x,0,Position.z)
  171.    
  172.     local ray = Ray.new(Start, (End - Start).unit*750)
  173.    
  174.     local part,pos = workspace:FindPartOnRay(ray,workspace.Trees)
  175.     if part ~= nil then
  176.         local T = game.ServerStorage.Trees:GetChildren()
  177.         local t = math.random(1,#T)
  178.         local tree = T[t]:clone()
  179.         local size = math.random(70,120)/100
  180.         tree.Size = tree.Size*size
  181.         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)
  182.         tree.Parent = workspace.Trees
  183.     end
  184. end
  185.  
  186.  
  187.  
  188. function GuiPress()
  189.     Size.Button.MouseButton1Down:connect(function()
  190.         Clicked = true
  191.         repeat
  192.             Size.Button.Position = UDim2.new(0,math.clamp(mouse.x - Size.AbsolutePosition.x - 8,-8,122),0,-8)
  193.             -- -8, 122
  194.             --SValue = math.clamp(math.floor((Size.Button.Position.X.Offset / 130) * 100)/100,.25,1)*200
  195.             SValue = math.floor(math.clamp(((Size.Button.Position.X.Offset + 8)/130)+.05,.05,1) * 1000)
  196.             Sphere.Size = Vector3.new(SValue,SValue,SValue)
  197.             Gui.Frame1.Frame.Size1.Text = "Size: "..SValue
  198.             wait()
  199.         until Clicked == false
  200.     end)
  201.  
  202.     Density.Button.MouseButton1Down:connect(function()
  203.         Clicked = true
  204.         repeat
  205.             Density.Button.Position = UDim2.new(0,math.clamp(mouse.x - Density.AbsolutePosition.x - 8,-8,122),0,-8)
  206.             DValue = math.floor(math.clamp(((Density.Button.Position.X.Offset + 8)/130)+.25,.25,1) * 25)
  207.             Sphere.Transparency = (2 - DValue)/2
  208.             Gui.Frame1.Frame.Density.Text = "Density: ".. DValue
  209.             wait()
  210.         until Clicked == false
  211.     end)
  212.  
  213.     Size.Button.MouseButton1Up:connect(function()
  214.         if Clicked then
  215.             Clicked = false
  216.         end
  217.     end)
  218.  
  219.     Density.Button.MouseButton1Up:connect(function()
  220.         if Clicked then
  221.             Clicked = false
  222.         end
  223.     end)
  224. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement