Advertisement
Guest User

PRO

a guest
Aug 19th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.88 KB | None | 0 0
  1. --GENERATOR
  2. --Biomas: grama, deserto
  3.  
  4. changeInVal = 300 -- quanto mais, menos grama tem
  5.  
  6.  
  7. function generate(plr, base, seed)
  8.     print(seed)
  9.     math.randomseed(seed)
  10.    
  11.     local blocks = {}
  12.     local startingBiome = math.random(1,2)
  13.     local currentBlock = nil -- Seta o inicial
  14.     local grassCount = 0
  15.     local sandCount = 0
  16.         currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  17.         currentBlock.Parent = base.Landscape
  18.         currentBlock.Position = base.Colony.Sig.Position
  19.     blocks[0] = currentBlock
  20.     local xVar = 1
  21.     local zVar = 0
  22.     while zVar < 285  do -- geração inicial
  23.         while xVar < 266 do
  24.             if zVar > 0 then
  25.                 startingBiome = math.random(1,changeInVal)
  26.                 local tableXMinus = (xVar + (zVar * 266)) - 1
  27.                 local tableZMinus = (xVar + (zVar * 266)) - 266
  28.                 if xVar == 0 then
  29.                     if blocks[tableZMinus].Name == "Grass" then
  30.                         if startingBiome == 1 then
  31.                             currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  32.                         else
  33.                             currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  34.                            
  35.                         end
  36.                     end
  37.                     if blocks[tableZMinus].Name == "Water" then
  38.                         if startingBiome == 1 then
  39.                             currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  40.                         else
  41.                             currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  42.                            
  43.                         end
  44.                     end                                
  45.                 else
  46.                     if blocks[tableXMinus].Name == blocks[tableZMinus].Name then
  47.                         if blocks[tableXMinus].Name == "Grass" then
  48.                             if startingBiome == 1 then
  49.                                 currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  50.                             else
  51.                                 currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  52.                             end
  53.                         end
  54.                         if blocks[tableXMinus].Name == "Water" then
  55.                             if startingBiome == 1 then
  56.                                 currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  57.                             else
  58.                                 currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  59.                             end
  60.                         end
  61.                     else
  62.                         startingBiome = math.random(1,100)
  63.                          if startingBiome < 50 then
  64.                         currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  65.                         end
  66.                         if startingBiome > 50 then
  67.                             currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  68.                         end
  69.                         if startingBiome == 50 then
  70.                             currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  71.                         end
  72.                     end
  73.                 end
  74.             else
  75.                 startingBiome = math.random(1, changeInVal)
  76.                 local mathHandler = (xVar + (zVar * 266)) - 1
  77.                 if blocks[mathHandler].Name == "Grass" then
  78.                     if startingBiome == 1 then
  79.                         currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  80.                     else
  81.                         currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  82.                     end
  83.                 end
  84.                 if blocks[mathHandler].Name == "Water" then
  85.                     if startingBiome == 1 then
  86.                         currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  87.                     else
  88.                         currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  89.                     end
  90.                 end
  91.             end
  92.             currentBlock.Parent = base.Landscape
  93.             if currentBlock.Name == "Grass" then
  94.             currentBlock.Position = base.Colony.Sig.Position - Vector3.new(xVar, 0, zVar) + Vector3.new(0, 0.2, 0)
  95.             else
  96.                 currentBlock.Position = base.Colony.Sig.Position - Vector3.new(xVar, 0, zVar)
  97.             end
  98.             local tableToEdit = xVar + (zVar * 266)
  99.             blocks[tableToEdit] = currentBlock
  100.             if currentBlock.Name == "Grass" then
  101.                 grassCount = grassCount + 1
  102.             end
  103.             if currentBlock.Name == "Water" then
  104.                 sandCount = sandCount + 1
  105.             end
  106.             xVar = xVar + 1
  107.         end
  108.         xVar = 0
  109.         zVar = zVar + 1
  110.         wait(0.01)
  111.     end
  112.     zVar = 0
  113.     xVar = 0
  114.     while xVar < 266 do
  115.         blocks[285 * 266 + xVar] = plr
  116.         xVar = xVar + 1
  117.     end
  118.     xVar = 0
  119.     --fixes #1
  120.     while zVar < 285  do
  121.         while xVar < 266 do
  122.             if xVar > 0 and xVar < 266 then
  123.                 if zVar > 0 and zVar < 285 then
  124.                     local tableXMinus = (xVar + (zVar * 266)) - 1
  125.                     local tableZMinus = (xVar + (zVar * 266)) - 266
  126.                     local tableXPlus = (xVar + (zVar * 266)) + 1
  127.                     local tableZPlus = (xVar + (zVar * 266)) + 266
  128.                     local tableNow = xVar + (zVar * 266)
  129.                     if blocks[tableNow].Name == "Grass" then
  130.                         if blocks[tableXMinus].Name == "Water" and blocks[tableXPlus].Name == "Water" and blocks[tableZMinus].Name == "Water" and blocks[tableZPlus].Name == "Water" then
  131.                             blocks[tableNow]:Destroy()
  132.                             currentBlock = game.ReplicatedStorage.Blocks.Water:Clone()
  133.                             currentBlock.Parent = base.Landscape
  134.                             currentBlock.Position = base.Colony.Sig.Position - Vector3.new(xVar, 0, zVar)
  135.                             local tableToEdit = xVar + (zVar * 266)
  136.                             blocks[tableToEdit] = currentBlock
  137.                         end
  138.                     else
  139.                         if blocks[tableXMinus].Name == "Grass" and blocks[tableXPlus].Name == "Grass" and blocks[tableZMinus].Name == "Grass" and blocks[tableZPlus].Name == "Grass" then
  140.                             blocks[tableNow]:Destroy()
  141.                             currentBlock = game.ReplicatedStorage.Blocks.Grass:Clone()
  142.                             currentBlock.Parent = base.Landscape
  143.                             currentBlock.Position = base.Colony.Sig.Position - Vector3.new(xVar, 0, zVar) + Vector3.new(0, 0.2, 0)
  144.                             local tableToEdit = xVar + (zVar * 266)
  145.                             blocks[tableToEdit] = currentBlock
  146.                         end
  147.                     end
  148.                     if xVar > 0 and xVar < 266 then
  149.                     if zVar > 0 and zVar < 285 then
  150.                     if blocks[tableXMinus].Name == "Water" or blocks[tableZMinus].Name == "Water" or blocks[tableXPlus].Name == "Water" or blocks[tableZPlus].Name == "Water" then
  151.                         if blocks[tableNow].Name == "Grass" then
  152.                         blocks[tableNow]:Destroy()
  153.                         currentBlock = game.ReplicatedStorage.Blocks.Sand:Clone()
  154.                         currentBlock.Parent = base.Landscape
  155.                         currentBlock.Position = base.Colony.Sig.Position - Vector3.new(xVar, 0, zVar) + Vector3.new(0, 0.1, 0)
  156.                         blocks[tableNow] = currentBlock
  157.                         end
  158.                         end
  159.                     end
  160.                     end
  161.                 end
  162.                 if xVar == 0 or xVar == 266 or zVar == 285 then
  163.                     if blocks[xVar + (zVar * 266)].Name == "Grass" then
  164.                         blocks[xVar + (zVar * 266)]:Destroy()
  165.                         currentBlock = game.ReplicatedStorage.Blocks.Sand:Clone()
  166.                         currentBlock.Parent = base.Landscape
  167.                         currentBlock.Position = base.Colony.Sig.Position - Vector3.new(xVar, 0, zVar) + Vector3.new(0, 0.1, 0)
  168.                         blocks[xVar + (zVar * 266)] = currentBlock
  169.                        
  170.                     end
  171.                 end
  172.             end
  173.             xVar = xVar + 1
  174.         end
  175.         zVar = zVar + 1
  176.             wait(0.01)
  177.             xVar = 0
  178.     end
  179.     xVar = 0
  180.     zVar = 0
  181.     local done = false
  182.     local first = true
  183.     while not done do
  184.         if blocks[xVar + (zVar * 266)].Name == "Grass" then
  185.                 blocks[xVar + (zVar * 266)]:Destroy()
  186.                 currentBlock = game.ReplicatedStorage.Blocks.Sand:Clone()
  187.                 currentBlock.Parent = base.Landscape
  188.                 currentBlock.Position = base.Colony.Sig.Position - Vector3.new(xVar, 0.1, zVar)
  189.                 blocks[xVar + (zVar * 266)] = currentBlock
  190.         end
  191.         if first and xVar == 266 then
  192.             first = false
  193.             xVar = 0
  194.             zVar = 284
  195.         end
  196.         if not first then
  197.             if xVar == 266 then
  198.                 done = true
  199.                
  200.             end
  201.         end
  202.         xVar = xVar + 1
  203.     end
  204.     print("Gerado!")
  205. end
  206.  
  207. game.ReplicatedStorage.Events.GenerateTerrain.Event:Connect(generate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement