Advertisement
NeonMayhem

Hexagonal map generator

Mar 29th, 2023
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | Source Code | 0 0
  1. local ServerStorage = game.ServerStorage
  2. local CentrePoint = Vector3.new(30, 0, 25.98)
  3. local Tile = ServerStorage.Templates.Tile
  4. local TileGui = script.TileNumber
  5. local Tiles = workspace.Tiles
  6. local RowsTable = {}
  7. local TileCount = 0
  8. local IsEven = 0
  9. local Width = 15
  10. Tiles.Width.Value = Width
  11. local n = (Width-1)/2+1
  12.  
  13. for i = 1, n do
  14.     table.insert(RowsTable, n-1+i)
  15. end
  16. for i = 1, n-1 do
  17.     table.insert(RowsTable, Width-i)
  18. end
  19.  
  20. for y = 1, Width do
  21.     local a = math.abs(math.floor(Width/2)+1-y)/2
  22.     for x = 1 + math.floor(a), Width-math.ceil(a) do
  23.         TileCount += 1
  24.  
  25.         IsEven = (Width-1)/4 == math.floor((Width-1)/4) and (y+1)%2 or y%2
  26.  
  27.         local Tile = Tile:Clone()
  28.         Tile.Name = "Tile"..TileCount
  29.         Tile.Position = CentrePoint + Vector3.new(y*45, 0, x*51.96 + IsEven*25.98)
  30.         Tile.Parent = Tiles
  31.  
  32.         if TileCount == 1 then
  33.             Tile.Color = Color3.fromRGB(0, 32, 96)
  34.             local CornerMarker = script.CornerMarker:Clone()
  35.             CornerMarker.Value = "Blue"
  36.             CornerMarker.Parent = Tiles["Tile"..TileCount]
  37.            
  38.         elseif TileCount == n then
  39.             Tile.Color = Color3.fromRGB(44, 101, 29)
  40.             local CornerMarker = script.CornerMarker:Clone()
  41.             CornerMarker.Value = "Green"
  42.             CornerMarker.Parent = Tiles["Tile"..TileCount]
  43.            
  44.         else
  45.             local RowValues = 0
  46.  
  47.             for i = 1, Width do
  48.                 table.insert(RowsTable, n-1+i)
  49.                 RowValues += RowsTable[i]
  50.  
  51.                 if i == n and TileCount == RowValues then
  52.                     Tile.Color = Color3.fromRGB(236, 41, 109)
  53.                     local CornerMarker = script.CornerMarker:Clone()
  54.                     CornerMarker.Value = "Pink"
  55.                     CornerMarker.Parent = Tiles["Tile"..TileCount]
  56.                    
  57.                 elseif i == n and TileCount == RowValues - n+1 then
  58.                     Tile.Color = Color3.fromRGB(91, 93, 105)
  59.                     local CentreMarker = script.CornerMarker:Clone()
  60.                     CentreMarker.Name = "CentreMarker"
  61.                     CentreMarker.Parent = Tiles["Tile"..TileCount]
  62.                    
  63.                 elseif i == n and TileCount == RowValues-Width+1 then
  64.                     Tile.Color = Color3.fromRGB(89, 34, 89)
  65.                     local CornerMarker = script.CornerMarker:Clone()
  66.                     CornerMarker.Value = "Purple"
  67.                     CornerMarker.Parent = Tiles["Tile"..TileCount]
  68.                    
  69.                 elseif i == Width and TileCount == RowValues-n+1 then
  70.                     Tile.Color = Color3.fromRGB(125, 0, 0)
  71.                     local CornerMarker = script.CornerMarker:Clone()
  72.                     CornerMarker.Value = "Red"
  73.                     CornerMarker.Parent = Tiles["Tile"..TileCount]
  74.                    
  75.                 elseif i == Width and TileCount == RowValues then
  76.                     Tile.Color = Color3.fromRGB(200, 137, 0)
  77.                     local CornerMarker = script.CornerMarker:Clone()
  78.                     CornerMarker.Value = "Yellow"
  79.                     CornerMarker.Parent = Tiles["Tile"..TileCount]
  80.                 end
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86. script.Completed.Value = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement