OxianRobloxianYT

earth

Feb 24th, 2018
131
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. math.randomseed(tick() * math.random())
  2.  
  3. map = {}
  4.  
  5. gradualCreation = true
  6.  
  7. size = 500
  8. frequency = 1
  9. raiseFactor = math.random()/4
  10.  
  11. chunkBreadth = 20
  12. maxHeight = 150
  13.  
  14. waterLevel = 10
  15. sand = 1
  16. grass = 5
  17. earth = 3
  18. bland = 4
  19.  
  20. holder = Instance.new("Model", workspace)
  21. holder.Name = "map_holder"
  22.  
  23. ranges = {
  24. [sand] = {
  25. color = "Cashmere",
  26. range = 0.2,
  27. },
  28. [grass] = {
  29. color = "Camo",
  30. range = 0.3
  31. },
  32. [earth] = {
  33. color = "Dirt brown",
  34. range = 0.5
  35. },
  36. [bland] = {
  37. color = "Dark stone grey",
  38. range = 1
  39. };
  40. }
  41.  
  42. function getColorFromRange(h)
  43. local overall = 0
  44. for _, field in ipairs(ranges) do
  45. overall = overall + field.range
  46. if h <= overall then
  47. return field.color
  48. end
  49. end
  50. return ranges[#ranges].color
  51. end
  52.  
  53. function get_noise(x, y)
  54. local nx = frequency * x/size - 0.5
  55. local ny = frequency * y/size - 0.5
  56. return math.pow(math.abs(
  57. math.noise(nx, ny) +
  58. math.noise(2 * nx, 2 * ny) * 0.5 +
  59. math.noise(4 * nx, 4 * ny) * 0.25
  60. ), 1 - raiseFactor)
  61. end
  62.  
  63. function placeChunk(atpx, atpy, atpz, color, name)
  64. local p = Instance.new("Part", holder)
  65. p.TopSurface, p.BottomSurface = "Smooth", "Smooth"
  66. p.Anchored = true
  67. p.BrickColor = BrickColor.new(color)
  68. p.Size = Vector3.new(chunkBreadth, 50, chunkBreadth)
  69. p.CFrame = CFrame.new(atpx, atpy, atpz)
  70. end
  71.  
  72. for x = 1, size do
  73. for z = 1, size do
  74. local h = get_noise(x, z)
  75. if h > waterLevel then
  76. placeChunk(
  77. x * chunkBreadth - (size * chunkBreadth)/2,
  78. 10 + h * maxHeight,
  79. z * chunkBreadth - (size * chunkBreadth)/2,
  80. getColorFromRange(h),
  81. string.format("chunk_%s_%s", x, z)
  82. )
  83. if gradualCreation then
  84. coroutine.yield()
  85. end
  86. end
  87. end
  88. end
  89.  
  90. for i, player in pairs(game.Players:GetChildren()) do
  91. player.Character.Torso.CFrame = CFrame.new(-100, 150, 0)
  92. end
RAW Paste Data