Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local storage = game:GetService("ServerStorage")
- local trees = storage["Trees"]
- math.randomseed(tick())
- local Base = Instance.new("Part")
- Base.Name = "Trunk"
- Base.formFactor = "Custom"
- Base.TopSurface = 0
- Base.BottomSurface = 0
- Base.Anchored = true
- local Leaves = Base:Clone()
- Leaves.Name = "Leaves"
- Leaves.CanCollide = false
- local leafmesh = Instance.new("BlockMesh")
- leafmesh.Parent = Leaves
- function dot(c1,c2)
- local m = CFrame.Angles(math.pi/2,0,0)
- return (c1*m).lookVector:Dot((c2*m).lookVector)
- end
- local leaf_mult = {
- Vector3.new(.40,.40,.40);
- Vector3.new(.40,.40,.40);
- Vector3.new(.40,.40,.40);
- Vector3.new(.40,.40,.40);
- }
- local function Branch(base,c, material, colour)
- if c <= 0 then
- local leaves = Leaves:Clone()
- leaves.BrickColor = colour
- leaves.Material = Enum.Material[material]
- local vol = (base.Size.x + base.Size.y + base.Size.z)
- leaves.Mesh.Scale = leaf_mult[math.random(1, #leaf_mult)] * math.random(vol/3*10, vol/3*12) / 10
- leaves.Size = leaves.Mesh.Scale*4
- leaves.CFrame = base.CFrame * CFrame.new(0, base.Size.y/2, 0)
- leaves.Parent = base.Parent
- else
- local pos = base.CFrame*CFrame.new(0, base.Size/2, 0)
- local height = base.Size.y
- local width = base.Size.x
- local nb = math.random(2, 2)
- local r = math.random(45, 135)
- local da = math.random(20+55/c, 40+40/c)
- local ba = math.random(-da/3, da/3)
- for i=0,nb-1 do
- wait()
- local branch = base:Clone()
- branch.Name = "Branch"
- local h = height*math.random(95,115)/100
- local new = branch.CFrame * CFrame.new(0,height/2,0) * CFrame.Angles(0,0,math.rad(ba))
- new = new * CFrame.Angles(0, i*(math.pi*2/nb)+r, math.rad(da/2)) * CFrame.new(0, h/2, 0)
- local w = dot(new, branch.CFrame) * width * 0.9
- branch.Size = Vector3.new(w, h, w)
- branch.CFrame = new
- branch.Parent = base.Parent
- Branch(branch, c-1, material, colour)
- end
- end
- wait()
- end
- local function generate_tree(location, complexity, width, height, material_1, material_2, colour_1, colour_2)
- local tree = Instance.new("Model")
- tree.Name = "Tree"
- tree.archivable = false
- tree.Parent = workspace
- local base = Base:Clone()
- base.Parent = tree
- base.Size = Vector3.new(width, height, width)
- base.CFrame = CFrame.new(location) * CFrame.new(0,height/2,0) * CFrame.Angles(0, math.rad(math.random(1,360)), 0)
- base.BrickColor = colour_1
- base.Material = Enum.Material[material_1]
- Branch(base, complexity, material_2, colour_2)
- local health = Instance.new("IntValue", tree)
- health.Name = "HP"
- health.Value = script.Parent.Health.Value
- local treeType = Instance.new("StringValue", tree)
- treeType.Name = "TreeType"
- treeType.Value = script.Parent.TreeType.Value
- local regenerationPosition = Instance.new("Vector3Value", tree)
- regenerationPosition.Name = "Position"
- regenerationPosition.Value = script.Parent.Position
- return tree
- end
- game.Workspace.ChildRemoved:connect(function(child)
- if child:IsA("Model") and (string.lower(child.Name) == "tree") then
- local newTree = trees[child.TreeType.Value]:Clone()
- local c, w, h = math.max(1, newTree.Complexity.Value), math.max(1, newTree.Width.Value), math.max(1, newTree.Height.Value)
- generate_tree(child.Position.Value-Vector3.new(0, newTree.Size.Y, 0), c, w, h, newTree.MaterialB.Value, newTree.MaterialL.Value, newTree.TrunkColour.Value, newTree.LeafColour.Value)
- end
- end)
- local starter_trees = game.Workspace.Starter_Trees
- for i,v in pairs(starter_trees:GetChildren()) do
- spawn(function()
- local c, w, h = math.max(1, v.Complexity.Value), math.max(1, v.Width.Value), math.max(1, v.Height.Value)
- generate_tree(v.CFrame.p-Vector3.new(0, v.Size.Y, 0), c, w, h, v.MaterialB.Value, v.MaterialL.Value, v.TrunkColour.Value, v.LeafColour.Value)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement