Advertisement
Delros12

Survival 303-Styled Terrain Generator

May 26th, 2018
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.74 KB | None | 0 0
  1. local LastPosition = CFrame.new(-70, 0, -40)
  2. local x, y, z = -3, -9, -3
  3. local x1, y1, z1 = 3, -7, 3
  4. local x2, y2, z2 = x, y, z
  5. local t1 = true
  6. while t1 do
  7.     for i = 1, 10 do
  8.         if y2 > y1 then t1 = false break end
  9.         if z2 > z1 then z2 = z y2 = y2 + 1 end
  10.         local part = Instance.new("Part", workspace)
  11.         part.CanCollide = false
  12.         part.Size = Vector3.new(2000, 5, 2000)
  13.         part.CFrame = CFrame.new(x2*part.Size.X, y2*-part.Size.Y+1.5, z2*part.Size.Z)
  14.         part.Anchored = true
  15.         part.Transparency = 0.2
  16.         part.Reflectance = 0.6
  17.         part.BrickColor = BrickColor.new("Deep blue")
  18.         part.BackSurface = "SmoothNoOutlines"
  19.         part.FrontSurface = "SmoothNoOutlines"
  20.         part.BottomSurface = "SmoothNoOutlines"
  21.         part.TopSurface = "SmoothNoOutlines"
  22.         part.RightSurface = "SmoothNoOutlines"
  23.         part.LeftSurface = "SmoothNoOutlines"
  24.         part.Material = "SmoothPlastic"
  25.         if x2 > x1 then x2 = x z2 = z2 + 1 end
  26.         x2 = x2 + 1
  27.     end
  28.     wait()
  29. end
  30. local Hills = {
  31.     --Hill1 = {
  32.     --  Position = CFrame.new(-200, 0, -100);
  33.     --  Range = 100;
  34.     --  Height = 10;
  35.     --  Color = BrickColor.new("Medium stone gray");
  36.     --  TreeSpawn = false
  37.     --};
  38. --[[
  39.     Hill2 = {
  40.         Position = Vector3.new(-200, 0, 200);
  41.         Range = 250;
  42.         Height = 10;
  43.         Color = BrickColor.new("Forest green");
  44.     };
  45.     Hill3 = {
  46.         Position = Vector3.new(-200, 0, -200);
  47.         Range = 200;
  48.         Height = 10;
  49.         Color = BrickColor.new("Forest green");
  50.     };
  51.     Hill4 = {
  52.         Position = Vector3.new(200, 0, -200);
  53.         Range = 150;
  54.         Height = 10;
  55.         Color = BrickColor.new("Forest green");
  56.     }]]
  57. }
  58. local treemodel = Instance.new("Model", game.Lighting)
  59. local p = Instance.new("Part", treemodel)
  60. local treethickness = math.random(2, 6)
  61. p.BrickColor = BrickColor.new("Dark orange")
  62. p.Size = Vector3.new(treethickness, math.random(4, 20), treethickness)
  63. p.CFrame = CFrame.new(0, 0, 0)
  64. p.Anchored = true
  65. p.Name = "stump"
  66. local p1 = Instance.new("Part", treemodel)
  67. local leavesize = math.random(4, 30)
  68. p1.BrickColor = BrickColor.new("Bright green")
  69. p1.Size = Vector3.new(treethickness + leavesize, leavesize/8, treethickness + leavesize)
  70. p1.CFrame = CFrame.new(0, p.Size.Y/2 + p1.Size.Y/2, 0)
  71. p1.Anchored = true
  72. p1.Name = "bottom_leave"
  73. local p2 = Instance.new("Part", treemodel)
  74. p2.BrickColor = BrickColor.new("Bright green")
  75. p2.Size = Vector3.new(treethickness + leavesize/2, leavesize/8, treethickness + leavesize/2)
  76. p2.CFrame = CFrame.new(0, p.Size.Y/2 + p1.Size.Y + p2.Size.Y/2, 0)
  77. p2.Anchored = true
  78. p2.Name = "top_leave"
  79. local totaltreeheight = p.Size.Y + p1.Size.Y + p2.Size.Y
  80. function minimedrandom(n1min, n1, n2min, n2)
  81.     local t = true
  82.     local r = 0
  83.     while t do
  84.         r = math.random(n1, n2)
  85.         if r < n1min and r < 0 then
  86.             t = false
  87.         end
  88.         if r > n2min and r > 0 then
  89.             t = false
  90.         end
  91.     end
  92.     return r
  93. end
  94. function block1insideblock2(s1, v1, s2, v2) --idk how to call this pff
  95.     local block1 = {
  96.         Size = s1;
  97.         Position = v1
  98.     }
  99.     local block2 = {
  100.         Size = s2;
  101.         Position = v2
  102.     }
  103.     --check if block1 is inside block2
  104.     if block1.Position == nil then error("Position at argument #1 is nil") end
  105.     if block2.Position == nil then error("Position at argument #3 is nil") end
  106.     if block1.Size == nil then error("Size at argument #2 is nil") end
  107.     if block2.Size == nil then error("Size at argument #4 is nil") end
  108.     if  block1.Position.X >= block2.Position.X - block2.Size.X and
  109.         block1.Position.X <= block2.Position.X + block2.Size.X and
  110.         block1.Position.Z >= block2.Position.Z - block2.Size.Z and
  111.         block1.Position.Z <= block2.Position.Z + block2.Size.Z
  112.         then
  113.         return true
  114.     end
  115.     return false
  116. end
  117. local tp = true
  118. local parts = {}
  119. for i = 1, math.random(50, 100) do
  120.     local newhill = {
  121.             Position = CFrame.new(math.random(-3000, 3000), 0, math.random(-3000, 3000));
  122.             Range = math.random(100, 300);
  123.             Height = math.random(1, 6);
  124.             Color = BrickColor.new("Dark green");
  125.             DirtColor = BrickColor.new("Rust");
  126.             StoneColor = BrickColor.new("Dark stone grey");
  127.             TreeSpawn = true;
  128.             StoneLand = false
  129.     }
  130.     if math.random(1, newhill.Height + 1) == 1 then
  131.         newhill.StoneLand = true
  132.         newhill.TreeSpawn = false
  133.         newhill.Color = newhill.StoneColor
  134.         newhill.DirtColor = newhill.StoneColor
  135.     end
  136.     table.insert(Hills, 0, newhill)
  137. end
  138. local max = 1000
  139. local chunks = 0
  140. function MagXZ(x, z)
  141.     return x + z
  142. end
  143. while wait() do
  144.     function generateblock()
  145.         local P
  146.         if tp == true then
  147.             P = Instance.new("SpawnLocation", workspace)
  148.         else
  149.             P = Instance.new("Part", workspace)
  150.         end
  151.         P.Size = Vector3.new(minimedrandom(-80, -30, 30, 80), 1, minimedrandom(-80, -30, 30, 80))
  152.         P.CFrame = CFrame.new(math.random(-1, 1)*P.Size.X + LastPosition.X, 50, math.random(-1, 1)*P.Size.Z + LastPosition.Z)
  153.         P.Name = "GPart"
  154.         --[[for _,p in pairs(parts) do
  155.             print(p.Position.X .. ", " .. p.Position.Y .. ", " .. p.Position.Z)
  156.             local check = true
  157.             if p.Position == nil and p.Size == nil then print("nope nil") check = false end
  158.             if check then
  159.                 if block1insideblock2(p.Size, p.Position, P.Size, P.Position) then
  160.                     print("A block was way too much inside another block and was deleted.")
  161.                     P:Destroy()
  162.                     return
  163.                 end
  164.             end
  165.         end]]
  166.         --if P:GetConnectedParts() then
  167.         --  if P:GetConnectedParts()[1].Name ~= "GPart" then
  168.         --      P:Destroy()
  169.         --      return
  170.         --  end
  171.         --end
  172.         if math.abs(MagXZ(P.Position.X, P.Position.Z) - MagXZ(LastPosition.X, LastPosition.Z)) >= (P.Size.X + P.Size.Z) then
  173.             P:Destroy()
  174.             return
  175.         end
  176.         local oldpos = P.CFrame
  177.         local height = 1
  178.         local treescanspawn = true
  179.         local dirtcolor = BrickColor.new("Rust")
  180.         P.BrickColor = BrickColor.new("Dark green")
  181.         for _,h in pairs(Hills) do
  182.             local closeness = -(P.CFrame.p - h.Position.p).magnitude + h.Range
  183.             --local height2 = (Vector3.new(h.Position.X - P.Position.X, 0, h.Position.Z - P.Position.Z).Magnitude/15) - 20
  184.             --if height2 < 0 then height2 = 0 end
  185.             if h.Range > closeness and closeness > 0 then
  186.                 height = math.min(h.Height, height) + closeness
  187.                 P.BrickColor = h.Color
  188.                 dirtcolor = h.DirtColor
  189.                 if h.TreeSpawn == false then
  190.                     treescanspawn = false
  191.                 end
  192.                 --print("SUCCESS closeness:" .. closeness)
  193.             else
  194.                 --warn("FAIL closeness:" .. closeness)
  195.             end
  196.         end
  197.         height = height + 100-math.noise(P.CFrame.p.X/10, 6421.1761, P.CFrame.p.Z/10)*30
  198.         print(height)
  199.         --print(height)
  200.         --Add dirt
  201.         local PD = Instance.new("Part", workspace)
  202.         PD.Size = Vector3.new(P.Size.X - (math.random(1, 50)/100), height - 4, P.Size.Z - (math.random(1, 50)/100))
  203.         PD.CFrame = CFrame.new(P.Position.X, 50, P.Position.Z)
  204.         PD.BrickColor = dirtcolor
  205.         PD.Anchored = true
  206.         PD.Name = "Dirt"
  207.         --Add grass on top
  208.         P.Size = Vector3.new(P.Size.X, 3, P.Size.Z)
  209.         P.CFrame = CFrame.new(oldpos.X, oldpos.Y + ((height-4)/2), oldpos.Z)
  210.         P.Anchored = true
  211.         P.Name = "Grass"
  212.         --Add sand
  213.         local PS = Instance.new("Part", workspace)
  214.         PS.Size = Vector3.new(P.Size.X + 4, 100, P.Size.Z + 4)
  215.         PS.CFrame = CFrame.new(P.Position.X, -0.5, P.Position.Z)
  216.         PS.BrickColor = BrickColor.new("Cool yellow")
  217.         PS.Anchored = true
  218.         PS.Name = "Sand"
  219.         --Add underbase
  220.         local PB = Instance.new("Part", workspace)
  221.         PB.Size = Vector3.new(PS.Size.X + 4, PS.Size.Y - 2, PS.Size.Z + 4)
  222.         PB.CFrame = CFrame.new(PS.Position.X, -0.5, PS.Position.Z)
  223.         PB.BrickColor = BrickColor.new("Dark stone grey")
  224.         PB.Anchored = true
  225.         PB.Name = "UnderBase"
  226.         if tp == true then
  227.             tp = false
  228.             for _,p in pairs(workspace:GetChildren()) do
  229.                 if game.Players:FindFirstChild(p.Name) then
  230.                     p:MoveTo(Vector3.new(P.Position.X + math.random(-P.Size.X/2, P.Size.X/2), P.Position.Y + 5, P.Position.Z + math.random(-P.Size.Z/2, P.Size.Z/2)))
  231.                 end
  232.             end
  233.         end
  234.         if treescanspawn == true and math.random(1, 6) == 6 then
  235.             for i = 1, math.random(1, 4) do
  236.                 local tree = treemodel:Clone()
  237.                 tree.Parent = workspace
  238.                 tree.stump.CFrame = CFrame.new(P.Position.X + math.random(-P.Size.X/2, P.Size.X/2), P.Position.Y + P.Size.Y/2 + tree.stump.Size.Y/2, P.Position.Z + math.random(-P.Size.Z/2, P.Size.Z/2))
  239.                 tree.bottom_leave.CFrame = CFrame.new(tree.stump.Position.X, tree.stump.Position.Y + tree.stump.Size.Y/2 + tree.bottom_leave.Size.Y/2, tree.stump.Position.Z)
  240.                 tree.top_leave.CFrame = CFrame.new(tree.stump.Position.X, tree.bottom_leave.Position.Y + tree.bottom_leave.Size.Y/2 + tree.top_leave.Size.Y/2, tree.stump.Position.Z)
  241.                 tree.stump.Parent = workspace
  242.                 tree.bottom_leave.Parent = workspace
  243.                 tree.top_leave.Parent = workspace
  244.                 tree:Destroy()
  245.             end
  246.         end
  247.         table.insert(parts, 0, {
  248.             P.Size;
  249.             P.Position
  250.         })
  251.         --print(P.Position.Z .. ", " .. P.Position.Y .. ", " .. P.Position.Z)
  252.         LastPosition = P.Position
  253.         print(math.noise(LastPosition.X - P.Position.X/100, LastPosition.Y - P.Position.Y/100, LastPosition.Z - P.Position.Z/100))
  254.     end
  255.     generateblock()
  256.     if chunks >= max then break end
  257.     chunks = chunks + 1
  258. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement