Advertisement
Shyvha

[WIP] Roblox Canyon and Dunes Infinite Generator

Jul 28th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.09 KB | None | 0 0
  1. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  2. -- Shyvha and @CloneTrooper1019, 2015
  3. -- Infinite Smooth Terrain Generator :3
  4. -- PS: I'm sorry that I didnt asked CloneTrooper1019 to edit the scripts, I might do it A S A P ! :wink:
  5. -- PPS: You can disable cavesRarity by putting 0 , it sometimes looks weird :/
  6. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  7. -- CONFIGURATION:
  8. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  9.  
  10. baseHeight = 4
  11. -- ^ The main height factor for the terrain.
  12.  
  13. mountainHeight = 3
  14. -- ^ How tall should mountains be relative to the baseHeight of the terrain
  15.  
  16. mountainMaterialWeight = 0.01
  17. -- ^ The chance that a mountain terrain chunk will generate using slate rather than rock
  18. --    Should be a number between 0 and 1
  19. --    0 = only rock, 1 = only slate, 0.5 = half n half
  20. cavesRarity = .2
  21. -- Holes in the terrain
  22.  
  23. chunkScale = 3
  24. -- ^ The grid scale for terrain generation.
  25.  
  26. renderDist = 45
  27. -- ^ The length/width of chunks in voxels that should be around the player at all times
  28.  
  29. xScale = 50
  30. -- ^ How much we should strech the X scale of the generation noise
  31.  
  32. zScale = 50
  33. -- ^ How much we should strech the Z scale of the generation noise
  34.  
  35. waterLevel = -0.5
  36. -- ^ Determines if we should generate ponds if the height level goes below this
  37. --    Should be a number between -1 and 1
  38. --    -1 = no water, 0 = all grass levels are filled with water, 1 = The entire map is flooded with water (Except for tall mountains)
  39.  
  40. seed = math.random()
  41. -- ^ Seed for determining the height map of the terrain.
  42. --    By default its random.
  43.  
  44. baseHeight2 = 10
  45. -- ^ The main height factor for the terrain.
  46.  
  47. mountainHeight2 = 12
  48. -- ^ How tall should mountains be relative to the baseHeight of the terrain
  49.  
  50. mountainMaterialWeight2 = 0.2
  51. -- ^ The chance that a mountain terrain chunk will generate using slate rather than rock
  52. --    Should be a number between 0 and 1
  53. --    0 = only rock, 1 = only slate, 0.5 = half n half
  54. canyonMaterialDensity2 = 0.1
  55. -- ^ The limestone rarity
  56. -- 0 = No Limestone at all , 1 = Only limestone (NOT RECOMMANDED) , 0.2 = small bumps (Realist)
  57. -- Note that limestone is not very different from sand, but it adds some realism
  58. chunkScale2 = 3
  59. -- ^ The grid scale for terrain generation.
  60.  
  61. renderDist2 = 45
  62. -- ^ The length/width of chunks in voxels that should be around the player at all times
  63.  
  64. xScale2 = 30
  65. -- ^ How much we should strech the X scale of the generation noise
  66.  
  67. zScale2 = 30
  68. -- ^ How much we should strech the Z scale of the generation noise
  69.  
  70. waterLevel2 = -0.9
  71. -- ^ Determines if we should generate ponds if the height level goes below this
  72. --    Should be a number between -1 and 1
  73. --    -1 = no water, 0 = all grass levels are filled with water, 1 = The entire map is flooded with water (Except for tall mountains)
  74.  
  75. seed2 = math.random()
  76. -- ^ Seed for determining the height map of the terrain.
  77. --    By default its random.
  78.  
  79. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  80. repeat
  81. while wait(10) do
  82. local chunks = {}
  83.  
  84. function chunkExists(chunkX,chunkZ)
  85.     if not chunks[chunkX] then
  86.         chunks[chunkX] = {}
  87.     end
  88.     return chunks[chunkX][chunkZ]
  89. end
  90.  
  91. function fillSmoothBlock(x,z,begY,endY,material)
  92.     local location = CFrame.new(x*4+2, (begY+endY)*4/2, z*4+2)
  93.     local fill = Vector3.new(4, (endY-begY)*4, 4)
  94.     workspace.Terrain:FillBlock(location,fill,material)
  95. end
  96.  
  97. function mountLayer(x,heightY,z,material)
  98.     -- Fill in Lakes/Ponds
  99.     local waterFill = baseHeight * waterLevel
  100.     if heightY < waterFill then
  101.         material = Enum.Material.Sandstone -- Make the material sand.
  102.         fillSmoothBlock(x,z,heightY-1,waterFill,Enum.Material.Water) -- Fill some water in.
  103.     end
  104.     -- Fill in the main terrain.
  105.     fillSmoothBlock(x,z,-baseHeight,heightY,material)
  106. end
  107.  
  108. function makeChunk(chunkX,chunkZ)
  109.     local rootPos = Vector3.new(chunkX*chunkScale,0,chunkZ*chunkScale)
  110.     chunks[chunkX][chunkZ] = true -- Acknowledge the chunk's existance.
  111.     for x = 0,chunkScale-1 do
  112.         for z = 0,chunkScale-1 do
  113.             local cx = (chunkX*chunkScale) + x
  114.             local cz = (chunkZ*chunkScale) + z
  115.             local noise = math.noise(seed,cx/xScale,cz/zScale)
  116.             local isMountain = (noise > 0)
  117.             local material,materialScale do
  118.                 if not isMountain then
  119.                     material = Enum.Material.Sand
  120.                     materialScale = 1
  121.                 else
  122.                     materialScale = mountainHeight
  123.                     if math.random() > mountainMaterialWeight then
  124.                         material = Enum.Material.Limestone
  125.                     else
  126.                         if math.random() > cavesRarity then
  127.                             material = Enum.Material.Air
  128.                         else
  129.                             material = Enum.Material.Sandstone
  130.                         end
  131.                     end
  132.                 end
  133.             end
  134.             local cy = noise*baseHeight*materialScale
  135.             mountLayer(cx,cy,cz,material)
  136.         end
  137.     end
  138. end
  139.  
  140. function doAreaFill(location)
  141.     local chunkX,chunkZ = math.floor(location.X/4/chunkScale),math.floor(location.Z/4/chunkScale)
  142.     local range = math.max(1,renderDist/chunkScale)
  143.     for x = -range,range do
  144.         for z = -range,range do
  145.             local cx,cz = chunkX + x,chunkZ + z
  146.             if not chunkExists(cx,cz) then
  147.                 makeChunk(cx,cz)
  148.             end
  149.         end
  150.     end
  151. end
  152.  
  153. while true do
  154.     for _,v in pairs(game.Players:GetPlayers()) do
  155.         spawn(function ()
  156.             local char = v.Character
  157.             if char then
  158.                 local torso = char:findFirstChild("Torso")
  159.                 if torso then
  160.                     doAreaFill(torso.Position)
  161.                 end
  162.             end
  163.         end)
  164.     end
  165.     wait(1)
  166. end
  167. break
  168. end
  169.  
  170. while wait(20) do
  171.  
  172.  
  173. local chunks = {}
  174.  
  175. function chunkExists(chunkX,chunkZ)
  176.         if not chunks[chunkX] then
  177.                 chunks[chunkX] = {}
  178.         end
  179.         return chunks[chunkX][chunkZ]
  180. end
  181.  
  182. function fillSmoothBlock(x,z,begY,endY,material)
  183.         local location = CFrame.new(x*4+2, (begY+endY)*4/2, z*4+2)
  184.         local fill = Vector3.new(4, (endY-begY)*4, 4)
  185.         workspace.Terrain:FillBlock(location,fill,material)
  186. end
  187.  
  188. function mountLayer(x,heightY,z,material)
  189.         -- Fill in Lakes/Ponds
  190.         local waterFill = baseHeight2 * waterLevel2
  191.         if heightY < waterFill then
  192.                 material = Enum.Material.Sand -- Make the material sand.
  193.                 fillSmoothBlock(x,z,heightY-2,waterFill,Enum.Material.Water) -- Fill some water in.
  194.         end
  195.         -- Fill in the main terrain.
  196.         fillSmoothBlock(x,z,-baseHeight2,heightY,material)
  197. end
  198.  
  199. function makeChunk(chunkX,chunkZ)
  200.         local rootPos = Vector3.new(chunkX*chunkScale2,0,chunkZ*chunkScale2)
  201.         chunks[chunkX][chunkZ] = true -- Acknowledge the chunk's existance.
  202.         for x = 0,chunkScale2-1 do
  203.                 for z = 0,chunkScale2-1 do
  204.                         local cx = (chunkX*chunkScale2) + x
  205.                         local cz = (chunkZ*chunkScale2) + z
  206.                         local noise = math.noise(seed2,cx/xScale2,cz/zScale2)
  207.                         local isMountain = (noise > 0)
  208.                         local material,materialScale do
  209.                                 if not isMountain then
  210.                                         material = Enum.Material.Sand
  211.                                         materialScale = 1
  212.                                 else
  213.                                         materialScale = mountainHeight
  214.                                         if math.random() > mountainMaterialWeight2 then
  215.                                                 material = Enum.Material.Sandstone
  216.                                         else
  217.                                             if math.random() > canyonMaterialDensity2 then
  218.                                                 material = Enum.Material.Limestone
  219.                                             else
  220.                                                 material = Enum.Material.Rock
  221.                                             end
  222.                                         end
  223.                                 end
  224.                         end
  225.                         local cy = noise*baseHeight2*materialScale
  226.                         mountLayer(cx,cy,cz,material)
  227.                 end
  228.         end
  229. end
  230.  
  231. function doAreaFill(location)
  232.         local chunkX,chunkZ = math.floor(location.X/4/chunkScale2),math.floor(location.Z/4/chunkScale2)
  233.         local range = math.max(1,renderDist/chunkScale2)
  234.         for x = -range,range do
  235.                 for z = -range,range do
  236.                         local cx,cz = chunkX + x,chunkZ + z
  237.                         if not chunkExists(cx,cz) then
  238.                                 makeChunk(cx,cz)
  239.                         end
  240.                 end
  241.         end    
  242. end
  243. end
  244.  
  245. while true do
  246.         for _,v in pairs(game.Players:GetPlayers()) do
  247.                 spawn(function ()
  248.                         local char = v.Character
  249.                         if char then
  250.                                 local torso = char:findFirstChild("Torso")
  251.                                 if torso then
  252.                                         doAreaFill(torso.Position)
  253.                                 end
  254.                         end
  255.                 end)
  256.         end
  257.         wait(1)
  258. end
  259. until false
  260. ---------------------------------------------------------------------------------------------------------------------------------------
  261.  
  262. --Thanks for CloneTrooper1019 for the main script
  263. --I'm working on the "end" of the "while wait(120)"
  264. --if you have a solution message me on roblox (Follow me , then message me the answer and where to close it, i'll find the place with ---ctrl+f.
  265. --Keep Persevering.
  266. --WIP
  267.  
  268. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement