Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Underground Warefare [REMASTERED]
- --]]
- --// Services
- local players = game:GetService("Players")
- local runService = game:GetService("RunService")
- local httpService = game:GetService("HttpService")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- --// Constants
- local databases = replicatedStorage:WaitForChild("Databases")
- local remotes = replicatedStorage:WaitForChild("Remotes")
- --// Variables
- local mapSize = 70
- local mapHeight = 6
- local blockSize = 10
- local newBlockBalancing = {
- Soil = 45,
- Stone = 10,
- Iron = 2,
- }
- --// Modules
- local playerModule = require(script:WaitForChild("PlayerModule"))
- local dataModule = require(script:WaitForChild("DataModule"))
- local gameModesModule = require(databases:WaitForChild("GameModes"))
- --// Init
- players.PlayerAdded:Connect(playerModule.onPlayerJoin)
- players.PlayerRemoving:Connect(playerModule.onPlayerLeave)
- pcall(dataModule.queueSet)
- --// Map Generation
- local function generateMap()
- local grid = {}
- print("Creating map")
- local mapComponents = workspace:FindFirstChild("GeneratedMap") or Instance.new("Folder")
- mapComponents.Name = "GeneratedMap"
- mapComponents.Parent = workspace
- mapComponents:ClearAllChildren()
- for h = 1, mapHeight do
- grid[h] = {}
- --runService.Heartbeat:Wait()
- for l = 1, mapSize + (mapSize/3) do
- grid[h][l] = {}
- for w = 1, mapSize do
- grid[h][l][w] = {}
- local newBlock = Instance.new("Part")
- newBlock.Anchored = true
- newBlock.Size = Vector3.new(blockSize, blockSize, blockSize)
- table.insert(grid[h][l][w], newBlock)
- if (h == mapHeight) then
- -- NOTE: We know it's a top layer
- newBlock.Size = Vector3.new(blockSize, 1, blockSize)
- newBlock.CFrame = CFrame.new(l * newBlock.Size.X,((h * blockSize) - blockSize/2) + .5, w * newBlock.Size.Z)
- newBlock.Material = Enum.Material.Grass
- newBlock.Color = Color3.fromRGB(106, 127, 63)
- newBlock.Name = "Grass"
- elseif (h == 1) then
- -- NOTE: We know it's a bottom layer
- newBlock.Size = Vector3.new(blockSize, 1, blockSize)
- newBlock.CFrame = CFrame.new(l * newBlock.Size.X,((h * blockSize) + blockSize/2) - .5, w * newBlock.Size.Z)
- newBlock.Material = Enum.Material.Slate
- newBlock.BrickColor = BrickColor.new("Dark stone grey")
- newBlock.Name = "Bedrock"
- else
- newBlock.CFrame = CFrame.new(l * newBlock.Size.X, h * newBlock.Size.Y, w * newBlock.Size.Z)
- local randomNumber = math.random(1, newBlockBalancing.Stone * (h-1))
- newBlock.Material = (randomNumber <= newBlockBalancing.Iron and Enum.Material.Metal or (randomNumber > newBlockBalancing.Iron and randomNumber <= newBlockBalancing.Stone) and Enum.Material.Slate or Enum.Material.Grass)
- newBlock.BrickColor = (newBlock.Material == Enum.Material.Grass and BrickColor.new("Brown") or newBlock.Material == Enum.Material.Metal and BrickColor.new("Fawn brown") or BrickColor.new("Medium stone grey"))
- newBlock.Name = (newBlock.Material == Enum.Material.Grass and "Soil" or newBlock.Material == Enum.Material.Metal and "Ore" or "Stone")
- end
- newBlock.Parent = mapComponents
- end
- end
- end
- local spawnPoint = Instance.new('SpawnLocation')
- spawnPoint.Anchored = true
- spawnPoint.CFrame = CFrame.new((mapSize*blockSize)/2, ((mapHeight * blockSize) - blockSize/2) + .5, (mapSize*blockSize)/2)
- spawnPoint.Parent = mapComponents
- print("Map Generated")
- end
- --// Game Loop
- while (true) do
- if (#players:GetPlayers() >= 2 or runService:IsStudio()) then
- print("Picking gamemode")
- local gameMode = gameModesModule[math.random(1, #gameModesModule)]
- generateMap()
- end
- wait(300)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement