Template:TerrainBuilder3DRbxScriptSource

-- TerrainBuilder 3D -- Load RbxLibraries local RbxGui = assert(LoadLibrary('RbxGui')) local RbxUtility = assert(LoadLibrary('RbxUtility')) -- local RbxStatus = assert(LoadLibrary('RbxStatus')) local RbxGear = assert(LoadLibrary('RbxGear')) local RbxStamper = assert(LoadLibrary('RbxStamper')) -- Done Loading RbxLibraries

_G.FramesPerSecond = 20

function _G.WaitFrame return wait(1/_G.FramesPerSecond) end

function _G.CrashReport(Error) _G.GuiStatus = _G.CrashStatus _G.CrashString = Error end

function ServerScript

_G.GuiStatus = "Please Wait..."

local World = Workspace:FindFirstChild("World") if not World then World = Instance.new("World",workspace) end

function LoadChunk(Table,ChunkX,ChunkY,ChunkZ) print("Chunk "..tostring(Table)) for YKey, YValue in pairs(Table) do     print("Block Y: ".. YKey, YValue) for XKey, XValue in pairs(Table) do        print("Block X: "..XKey,XValue) for ZKey, ZValue in pairs(Table) do           print("Block Z: "..ZKey,ZValue) print("ID: " .. (Table[YKey][XKey][ZKey]["ID"]) .. " Name: " .. BIDN((Table[YKey][XKey][ZKey]["ID"]))) local BlockItemScript = script.BlockScript:clone local Block = Table[YKey][XKey][ZKey] BlockItemScript.Parent = Block local Part = Instance.new("Part") Part.Archored = true Part.Position = Vector3.new( ((((ChunkX*16)+XKey)-8)*4),((((ChunkY*16)+YKey)-8)*4), ((((ChunkX*16)+ZKey)-8)*4) ) Part.Parent = World end end end end

function NewStone local Grass = { ["ID"] = 1, ["DataValue"] = 0 }  return Grass end

function NewDirt local Grass = { ["ID"] = 2, ["DataValue"] = 0 }  return Grass end

function NewGrass local Grass = { ["ID"] = 2, ["DataValue"] = 15 }  return Grass end

function NewSand local Grass = { ["ID"] = 3, ["DataValue"] = 0 }  return Grass end

function NewWater local Grass = { ["ID"] = 7, ["DataValue"] = 0 }  return Grass end

local TreeSpawnChance = 0.1

-- Generate Chunks -- Prints table contents. function PrintTable(t) for key,value in pairs(t) do     print(key,value) end end local PrintTable = PrintTable

-- Returns the name of the block Id. function BIDN(ID) return TableBlockName[ID] end

-- Prints table contents using a table refrence. function PrintTableVRef(Table,Ref) print("Table "..tostring(Table)) for key,value in pairs(Table) do     print(key, BIDN(value)) end end local PrintTableVRef = PrintTableVRef

-- Print Block function PrintBlock(TableChunk, TableBlock) PrintTableVRef(value, TableBlockName) print("Block "..key) end local PrintBlock = PrintBlock

--Print the chunk function PrintTChunk(Table) print("Chunk "..tostring(Table)) for YKey, YValue in pairs(Table) do     print("Block Y: ".. YKey, YValue) for XKey, XValue in pairs(Table) do        print("Block X: "..XKey,XValue) for ZKey, ZValue in pairs(Table) do           print("Block Z: "..ZKey,ZValue) print("ID: " .. (Table[YKey][XKey][ZKey]["ID"]) .. " Name: " .. BIDN((Table[YKey][XKey][ZKey]["ID"]))) end end end end local PrintTChunk = PrintTChunk

-- Actual Function used to print a chunk function PrintChunk(x, y, z)  PrintTChunk(ChunkTable[y][x][z]) end

-- Returns TableBlock in Chunk using TableChunk, X, Y, and Z. function GetBlockChunk(TableChunk,BX,BY,BZ) return TableChunk[BY][BX][BZ] end

TableBlockName= { [00] = "Air", [01] = "Stone", [02] = "Dirt", [03] = "Sand", [04] = "ComputerBlock", [05] = "Iron Ore", [06] = "Iron Block", [07] = "Water", [08] = "Tree Log", [09] = "Wooden Planks", [10] = "Tree", [11] = "Leaves", [12] = "Block 12", [13] = "Block 13", [14] = "Block 14", [15] = "Block 15", [16] = "Block 16", [17] = "Block 17", [18] = "Block 18", [19] = "Block 19", [20] = "Block 20", [21] = "Block 21", [22] = "Block 22", [23] = "Block 23", [24] = "Block 24", [25] = "Block 25", [26] = "Block 26", [27] = "Block 27", [28] = "Block 28", [29] = "Block 29", [30] = "Block 30", [31] = "Block 31" } local TableBlockName = TableBlockName

-- Textures TableBlockTexture = { [0] = { ["left"] = 10000000, ["right"] = 10000000, ["front"] = 10000000, ["back"] = 10000000, ["top"] = 10000000, ["bottom"] = 10000000 },  [1] = { ["left"] = 10000000, ["right"] = 10000000, ["front"] = 10000000, ["back"] = 10000000, ["top"] = 10000000, ["bottom"] = 10000000 } } local TableBlockTexture = TableBlockTexture

GuiAssets = { 10000000,              10000000,               10000000,               10000000 } local GuiAssets = GuiAssets

-- Data Persistence local DPHost = script.DPHost local DPPlayer = script.DPPlayer

-- player:SaveString('data', RbxUtility.EncodeJSON(mydata))

_G.GuiStatus = "Chunk Functions"

--- -- Chunk Test -- ---

-- X=Width, Y=Height, Z=Depth

TableMap = { } _G.TableMap = TableMap local TableMap=TableMap

-- ChunkTable TableMap.ChunkTable = { } ChunkTable = TableMap.ChunkTable

-- Creates a Chunk function NewChunk(x, y, z)  -- Chunk Y Pos ChunkTable[y] = { }  -- Chunk X Pos ChunkTable[y][x] = { }  -- Chunk Z Pos ChunkTable[y][x][z] = { }  local TableChunk = ChunkTable[y][x][z] return TableChunk end

-- Print Chunk Text PrintChunk(0, 1, 0)

function GenerateChunk(X,Y,Z) Tag = NewChunk(0, 1, 0) Tag[0] = { }  Tag[0][0] = { }  Tag[0][0][0] = { ["ID"] = 1, ["DataValue"] = 0 }  local size = Vector3.new(16, -- Number of tiles along the width                         16, -- Number of steps of heightmap                         16) -- Number of tiles along the length for x = 1, size.x do     for z = 1, size.z do         local Highty = math.random(size.y)         local TreeSpawn = 0 if math.random < TreeSpawnChance then TreeSpawn = math.random(4,5) end for y = 1, size.y do           if Y <= 3 then -- Beach if (y > Highty - 3) and (y <= Highty) then Tag[y][x][z] = NewSand elseif (y < Highty - 3) then Tag[y][x][z] = NewStone else Tag[y][x][z] = NewWater end else -- Normal Height if y == Highty then Tag[y][x][z] = NewGrass elseif y < TreeSpawn + Highty and y > Highty then Tag[y][x][z] = NewTreeLog elseif (y > Highty - 3) and (y < Highty) then Tag[y][x][z] = NewDirt elseif (y < Highty - 3) then Tag[y][x][z] = NewStone end end end end end end

_G.GuiStatus = "Waiting for ComputerServer" -- Wait for ComputerServer to finish setting up. while _G["ComputerServerReady"] == nil do  wait(1) end

_G.GuiStatus = "Generating Terrain"

_G.GuiStatus = "Ready for Player" game.Players.PlayerAdded:connect(function(player)	player:WaitForDataReady	-- create leaderboard	local ls = Instance.new("IntValue")	ls.Name = "leaderstats"	ls.Parent = player	--create the score stat	local score = Instance.new("IntValue")	score.Name = "Score"	score.Parent = ls       score.Value = nil end)

end

_G.Crashed, _G.ErrorReport = pcall(ServerScript)

if _G.Crashed == false then _G.CrashReport(_G.ErrorReport) end

--