Advertisement
RikuTheKiller

Untitled

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