Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local conf = function(obj, ...)
- for _, property in ipairs({...}) do
- obj[property[1]] = property[2]
- end
- return obj
- end
- local grid = 100;
- local size = 10;
- local ticks = 0;
- local minHill, maxHill = 50, 150
- local terrain = Instance.new("Model", Workspace);
- local parts = {}
- --create grid of parts
- for x = -0.5 * (grid * size), 0.5 * (grid * size), size do
- for z = -0.5 * (grid * size), 0.5 * (grid * size), size do
- ticks = ticks + 1
- if ticks % 200 == 0 then
- wait()
- end
- table.insert(parts, conf(
- Instance.new("Part", terrain),
- {"FormFactor", Enum.FormFactor.Custom},
- {"Position", Vector3.new(x, 0, z)},
- {"Size", Vector3.new(size, 10, size)},
- {"Anchored", true},
- {"TopSurface", Enum.SurfaceType.Smooth}
- ))
- end
- end
- local ticks = 0
- --create hills. update: hills now stack, creating mountains
- for i = 1, grid do
- ticks = ticks + 1
- if ticks % 2 == 0 then
- wait()
- end
- local rand = parts[math.random(#parts)]
- local radius = math.random(minHill, maxHill)
- for _, part in ipairs(parts) do
- if (rand.Position - part.Position).magnitude < radius then
- part.Size = part.Size + Vector3.new(0, radius - (rand.Position - part.Position).magnitude, 0)
- end
- end
- end
- --normalize
- local high, low = 0, 2^16
- --find lowest and highest grid points (can't use unpack with math.max or math.min, table is too big)
- for _, part in ipairs(parts) do
- if part.Size.Y < low then
- low = part.Size.Y
- elseif part.Size.Y > high then
- high = part.Size.Y
- end
- end
- --normalize parts based on lowest and highest points
- for _, part in ipairs(parts) do
- part.Size = Vector3.new(size, (grid * 2) * (part.Size.Y - low) / (high - low), size)
- if part.Size.Y <= 0.3 then
- part.BrickColor = BrickColor.new("Bright blue")
- else
- part.BrickColor = BrickColor.new("Camo")
- part.Material = Enum.Material.Grass
- end
- end
- --make trees
- local m = Instance.new("Model", Workspace)
- m.Name = "Trees"
- for i = 1, grid do
- local plant;
- local start = tick()
- repeat
- plant = parts[math.random(#parts)]
- if (tick() - start > 2) then
- finish = true
- break
- end
- until plant.BrickColor == BrickColor.new("Camo")
- if finish then
- break
- end
- local trunk = Instance.new("Part", m)
- local branch = Instance.new("Part", m)
- local colors = {"Bright red", "Bright orange", "Bright yellow", "Bright green"}
- conf(
- trunk,
- {"Size", Vector3.new(size/5, size, size/5)},
- {"Position", plant.Position},
- {"Anchored", true},
- {"TopSurface", "Smooth"},
- {"BrickColor", BrickColor.new("Brown")},
- {"Material", "Wood"}
- )
- conf(
- branch,
- {"Size", Vector3.new(size, size, size)},
- {"Position", trunk.Position},
- {"Anchored", true},
- {"TopSurface", "Smooth"},
- {"BottomSurface", "Smooth"},
- {"Shape", "Ball"},
- {"Material", "Grass"},
- {"BrickColor", BrickColor.new(colors[math.random(#colors)])}
- )
- end
- game.Players.CharacterAutoLoads = true
- for _, player in ipairs(game.Players:GetPlayers()) do
- player:LoadCharacter()
- end
Advertisement
Add Comment
Please, Sign In to add comment