160 lines
7.0 KiB
Plaintext
160 lines
7.0 KiB
Plaintext
--!strict
|
|
-- Builds a seeded 520x520 arena from connected 40-stud city modules.
|
|
|
|
local Workspace = game:GetService("Workspace")
|
|
local ServerStorage = game:GetService("ServerStorage")
|
|
local SIZE = 520
|
|
local GRID_RADIUS = 6
|
|
local STEP = 40
|
|
local CENTER = Vector3.new(0, 0, -420)
|
|
local rng = Random.new(DateTime.now().UnixTimestampMillis % 2147483647)
|
|
local pool = ServerStorage:WaitForChild("GameZonePrefabs")
|
|
while pool:GetAttribute("Ready") ~= true do
|
|
task.wait()
|
|
end
|
|
|
|
local old = Workspace:FindFirstChild("GameZone")
|
|
if old then old:Destroy() end
|
|
local zone = Instance.new("Folder")
|
|
zone.Name = "GameZone"
|
|
zone:SetAttribute("Size", SIZE)
|
|
zone:SetAttribute("GridCells", GRID_RADIUS * 2 + 1)
|
|
zone:SetAttribute("Seed", rng:NextInteger(1, 2147483646))
|
|
zone:SetAttribute("Ready", false)
|
|
zone.Parent = Workspace
|
|
|
|
local function block(name: string, size: Vector3, position: Vector3, color: Color3, material: Enum.Material): Part
|
|
local p = Instance.new("Part")
|
|
p.Name, p.Size, p.Position = name, size, position
|
|
p.Anchored, p.CanCollide, p.Color, p.Material = true, true, color, material
|
|
p.Parent = zone
|
|
return p
|
|
end
|
|
|
|
local function cloneAt(kind: string, name: string, position: Vector3, yaw: number?): Model?
|
|
local source = pool:FindFirstChild(kind)
|
|
if not source or not source:IsA("Model") then return nil end
|
|
local model = source:Clone()
|
|
model.Name = name
|
|
model:PivotTo(CFrame.new(position) * CFrame.Angles(0, yaw or 0, 0))
|
|
for _, item in model:GetDescendants() do
|
|
if item:IsA("BasePart") and item:GetAttribute("PrefabRoot") then item:Destroy() end
|
|
end
|
|
model.Parent = zone
|
|
return model
|
|
end
|
|
|
|
local function addInkOutline(model: Model)
|
|
for _, source in model:GetDescendants() do
|
|
if source:IsA("BasePart") and source.Name ~= "Root" and source.Size.Magnitude >= 12 then
|
|
local outline = Instance.new("Part")
|
|
outline.Name = "PencilEdge"
|
|
outline.Size = source.Size + Vector3.new(0.08, 0.08, 0.08)
|
|
outline.CFrame = source.CFrame
|
|
outline.Anchored, outline.CanCollide, outline.CanQuery, outline.CanTouch = true, false, false, false
|
|
outline.Transparency = 1
|
|
outline.Parent = model
|
|
local box = Instance.new("SelectionBox")
|
|
box.Name, box.Adornee = "PencilLine", outline
|
|
box.Color3, box.LineThickness, box.SurfaceTransparency = Color3.fromRGB(48, 47, 67), 0.012, 1
|
|
box.Parent = model
|
|
end
|
|
end
|
|
end
|
|
|
|
local edge = SIZE / 2
|
|
local boundary = Color3.fromRGB(86, 91, 99)
|
|
block("North Skyline Wall", Vector3.new(SIZE, 42, 4), CENTER + Vector3.new(0, 21, -edge), boundary, Enum.Material.Concrete)
|
|
block("West Skyline Wall", Vector3.new(4, 42, SIZE), CENTER + Vector3.new(-edge, 21, 0), boundary, Enum.Material.Concrete)
|
|
block("East Skyline Wall", Vector3.new(4, 42, SIZE), CENTER + Vector3.new(edge, 21, 0), boundary, Enum.Material.Concrete)
|
|
-- Keep the south boulevard open as the one clear portal entrance.
|
|
block("South Skyline West", Vector3.new(edge - 24, 42, 4), CENTER + Vector3.new(-edge / 2 - 12, 21, edge), boundary, Enum.Material.Concrete)
|
|
block("South Skyline East", Vector3.new(edge - 24, 42, 4), CENTER + Vector3.new(edge / 2 + 12, 21, edge), boundary, Enum.Material.Concrete)
|
|
|
|
local function onMainStreet(value: number): boolean
|
|
return value == -3 or value == 0 or value == 3
|
|
end
|
|
|
|
local houseKinds = { "HouseWarm", "HouseBlue", "HouseTerracotta" }
|
|
local lotKinds = { "House", "House", "House", "Courtyard", "Alley", "OpenLot" }
|
|
local roadCells = 0
|
|
local houseCount = 0
|
|
local bridgeCells: { [number]: { [number]: boolean } } = { [-3] = { [-1] = true }, [3] = { [1] = true } }
|
|
|
|
for row = -GRID_RADIUS, GRID_RADIUS do
|
|
for col = -GRID_RADIUS, GRID_RADIUS do
|
|
local isStreet = onMainStreet(row) or onMainStreet(col)
|
|
local position = CENTER + Vector3.new(col * STEP, 0, row * STEP)
|
|
if isStreet then
|
|
roadCells += 1
|
|
if row == 0 and col == 0 then
|
|
cloneAt("Plaza", "Central Fountain Plaza", position)
|
|
elseif onMainStreet(row) and onMainStreet(col) then
|
|
cloneAt("RoadIntersection", ("Intersection_%d_%d"):format(row, col), position)
|
|
else
|
|
local vertical = onMainStreet(col)
|
|
local yaw = if vertical then math.rad(90) else 0
|
|
local bridgeRow = bridgeCells[col]
|
|
if bridgeRow and bridgeRow[row] then
|
|
local bridge = cloneAt("Skybridge", ("RooftopBridge_%d_%d"):format(row, col), position)
|
|
if bridge then bridge:PivotTo(CFrame.new(position + Vector3.new(0, 17.7, 0))) end
|
|
end
|
|
cloneAt("RoadStraight", ("Street_%d_%d"):format(row, col), position, yaw)
|
|
end
|
|
else
|
|
-- A connected street grid surrounds compact blocks; controlled variation keeps every server's districts distinct.
|
|
block(("DistrictPaving_%d_%d"):format(row, col), Vector3.new(39.7, 0.2, 39.7), position + Vector3.new(0, -0.25, 0), Color3.fromRGB(222, 202, 190), Enum.Material.Concrete)
|
|
local pick = rng:NextInteger(1, #lotKinds)
|
|
local lotType = lotKinds[pick]
|
|
local kind = if lotType == "House" then houseKinds[rng:NextInteger(1, #houseKinds)] else lotType
|
|
if math.abs(row) == 5 or math.abs(col) == 5 then
|
|
kind = if rng:NextNumber() < 0.72 then houseKinds[rng:NextInteger(1, #houseKinds)] else "Courtyard"
|
|
end
|
|
local yaw = if kind == "Alley" and rng:NextNumber() < 0.5 then math.rad(90) else 0
|
|
local tile = cloneAt(kind, ("Block_%s_%d_%d"):format(kind, row, col), position, yaw)
|
|
if tile then
|
|
tile:SetAttribute("GridX", col)
|
|
tile:SetAttribute("GridZ", row)
|
|
tile:SetAttribute("TileKind", kind)
|
|
if kind:match("^House") then
|
|
houseCount += 1
|
|
addInkOutline(tile)
|
|
end
|
|
end
|
|
if kind == "Courtyard" or kind == "OpenLot" then
|
|
for _, offset in { {-14, -14}, {14, -14}, {-14, 14}, {14, 14} } do
|
|
if rng:NextNumber() < 0.72 then
|
|
local propName = if rng:NextNumber() < 0.72 then "Tree" else "StreetLamp"
|
|
cloneAt(propName, ("%s_%d_%d_%d"):format(propName, row, col, rng:NextInteger(1, 99)), position + Vector3.new(offset[1], 0, offset[2]))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
task.wait()
|
|
end
|
|
|
|
-- Entry arch frames the south boulevard and stays clear of the portal's landing point.
|
|
local archBase = CENTER + Vector3.new(0, 0, edge - 24)
|
|
block("Entry Arch Left", Vector3.new(5, 24, 7), archBase + Vector3.new(-19, 12, 0), Color3.fromRGB(178, 184, 220), Enum.Material.Concrete)
|
|
block("Entry Arch Right", Vector3.new(5, 24, 7), archBase + Vector3.new(19, 12, 0), Color3.fromRGB(178, 184, 220), Enum.Material.Concrete)
|
|
block("Entry Arch Header", Vector3.new(43, 5, 8), archBase + Vector3.new(0, 25, 0), Color3.fromRGB(178, 184, 220), Enum.Material.Concrete)
|
|
block("Entry Arch Ink", Vector3.new(45, 0.25, 0.35), archBase + Vector3.new(0, 27.7, 4.1), Color3.fromRGB(48, 47, 67), Enum.Material.SmoothPlastic)
|
|
|
|
local botSpawns = Workspace:FindFirstChild("BotSpawns")
|
|
local spawnCells = { {0, -5}, {0, -2}, {0, 2}, {0, 5}, {-5, 0}, {5, 0}, {-3, 2}, {3, -2} }
|
|
if botSpawns and botSpawns:IsA("Folder") then
|
|
for index, marker in botSpawns:GetChildren() do
|
|
if marker:IsA("BasePart") then
|
|
local cell = spawnCells[((index - 1) % #spawnCells) + 1]
|
|
marker.CFrame = CFrame.new(CENTER + Vector3.new(cell[1] * STEP, 2, cell[2] * STEP))
|
|
marker:SetAttribute("Zone", "Game")
|
|
end
|
|
end
|
|
end
|
|
|
|
zone:SetAttribute("RoadCells", roadCells)
|
|
zone:SetAttribute("HouseCount", houseCount)
|
|
zone:SetAttribute("Ready", true)
|
|
|