Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.03 KB | None | 0 0
  1. streaming = false
  2. CityName = "Framingham"
  3. CityState = nil
  4. TerrainSize = 25
  5. CitySize = 10;
  6. Climate = 39 --1 to 100 cold hot
  7. Brightness = 2
  8. Flat = false
  9. WaterLevel = 10
  10. ElevationChange = math.random(1,3)
  11. Interstate = true
  12. MaxY = 40 + WaterLevel
  13.  
  14. GroundColor = "Medium green"
  15. GroundMaterial = "Grass"
  16. TreeColor = "Camo"
  17. function SetUpClimate()
  18.     local AllClimates = {
  19.         "Snowy",
  20.         "Temperate",
  21.         "Tropical",
  22.         "Desert",
  23.         "Plains",
  24.     }
  25.     local SelectedClimate = math.random(1,#AllClimates)
  26.     SelectedClimate = AllClimates[SelectedClimate]
  27.     print("Generating a ".. SelectedClimate.. " climate");
  28.     if SelectedClimate == "Snowy" then
  29.         GroundColor = "White"
  30.         GroundMaterial = "Sand"
  31.         game.Lighting.FogColor = Vector3.new(255,255,255)
  32.         game.Lighting.FogEnd = 1000;
  33.     end
  34.    
  35.     if SelectedClimate == "Snowy" then
  36.         GroundColor = "White"
  37.         GroundMaterial = "Sand"
  38.     end
  39. end
  40. function SetUpGameCorrectly()
  41. --  script.Imports.Vehicles.Parent = game.Lighting;
  42.     script.Sky.Parent = game.Lighting;
  43.     script.ServerEvents.Parent = game.ServerScriptService;
  44.     script.Events.Chop.Parent = game.ReplicatedStorage;
  45.     script.InventoryGiver.Parent = game.ServerScriptService;
  46.     game.Lighting.Brightness = Brightness
  47.     game.Lighting.FogStart = 100
  48.     print("Make sure FE is Enabled")
  49.     game.Workspace.Gravity = 196.2;
  50.     if streaming == true then
  51.         game.Workspace.StreamingEnabled = true;
  52.     else
  53.         game.Workspace.StreamingEnabled = false;
  54.     end
  55.     if game.Workspace.Baseplate then
  56.         game.Workspace.Baseplate:Destroy()
  57.     end
  58. end
  59.  
  60. function MakeFolders(name)
  61.     local newFolder = Instance.new("Folder");
  62.     newFolder.Parent = workspace;
  63.     newFolder.Name = name;
  64. end
  65.  
  66. SetUpGameCorrectly()
  67. MakeFolders("Trees");
  68. MakeFolders("TerrainG");
  69. MakeFolders("Roads");
  70. MakeFolders("Props");
  71. MaxFog = 0; --Init
  72. row = 0; --Init
  73. countUp = 0; -- init
  74. previous = 4 -- init
  75. CountUpArray = {}; -- init
  76. TreesC = math.random(1,5)
  77. TreeCounter = 0; -- Init
  78. RandomStage = 0; --Init
  79. InterstateRow = nil; -- init
  80. if Interstate == true then
  81.     InterstateRow = math.random(3,TerrainSize-4)
  82.     if InterstateRow % 2 == 0 then
  83.         InterstateRow = InterstateRow + 0
  84.     else
  85.         InterstateRow = InterstateRow + 1
  86.     end
  87.     print("Row "..InterstateRow.. " was selected for the interstate!")
  88. end
  89. function GenerateTerrain()
  90.     while row < TerrainSize do
  91.         while countUp < TerrainSize do
  92.             wait(0.01)
  93.             local TerrainPeice = Instance.new("Part");
  94.             TerrainPeice.Anchored = true;
  95.             TerrainPeice.Transparency = 0;
  96.             TerrainPeice.CanCollide = true;
  97.             TerrainPeice.Size = Vector3.new(64,40,64)
  98.             TerrainPeice.Name = "Ground"
  99.             if previous <= WaterLevel and not math.random(1,100) == 1 then
  100.                 previous = WaterLevel
  101.             else
  102.                 previous = previous + math.random(-4*ElevationChange,4*ElevationChange)
  103.                 if previous > MaxY then
  104.                     previous = MaxY
  105.                 end
  106.             end
  107.             previous = math.floor(previous)
  108.             if CountUpArray[countUp] then
  109.                 if CountUpArray[countUp]+4> previous then
  110.                     if CountUpArray[countUp] <= WaterLevel and not math.random(1,100)== 1 then
  111.                         previous = WaterLevel
  112.                     else
  113.                         previous = (previous + CountUpArray[countUp])/2
  114.                     end
  115.                 end
  116.                 if CountUpArray[countUp]-4 < previous then
  117.                     if CountUpArray[countUp] <= WaterLevel and not math.random(1,100) == 1 then
  118.                         previous = WaterLevel
  119.                     else
  120.                         previous = (CountUpArray[countUp] + previous)/2
  121.                     end
  122.                 end
  123.                 if row + 5 >= InterstateRow and row-5 <= InterstateRow then
  124.                     if CountUpArray[countUp] > WaterLevel + 2 then
  125.                         previous = previous - (previous/5)
  126.                     end
  127.                     if previous <= WaterLevel then
  128.                         previous = WaterLevel + 1
  129.                     end
  130.                 end
  131.             end
  132.             if Flat == true then
  133.                 TerrainPeice.Position = Vector3.new(64*countUp,4,64*row)
  134.             else
  135.                 if row == InterstateRow or row == InterstateRow + 1 then
  136.                     TerrainPeice.Name = "InterstateGround"
  137.                     TerrainPeice.Position = Vector3.new(64*countUp,WaterLevel + 1,64*row)
  138.                 else
  139.                 TerrainPeice.Position = Vector3.new(64*countUp,previous,64*row)
  140.                 end
  141.             end
  142.             if true then
  143.                 TerrainPeice.Material = GroundMaterial
  144.                 TerrainPeice.BrickColor = BrickColor.new(GroundColor)
  145.                 TerrainPeice.Name = "Grass"
  146.                 if row == InterstateRow or row == InterstateRow + 1 then
  147.                     TerrainPeice.Name = "InterstateGround";
  148.                     previous = WaterLevel + 1;
  149.                     TerrainPeice.Position = Vector3.new(64*countUp,WaterLevel + 1,64*row)
  150.                     if row == InterstateRow then
  151.                         local Road = script.Imports.Road.InterstateSegment:Clone()
  152.                         Road:SetPrimaryPartCFrame(TerrainPeice.CFrame * CFrame.Angles(0, math.rad(90), 0)*CFrame.new(-32,20,0))
  153.                         Road.Parent = game.Workspace.Roads;
  154.                     end
  155.                 end
  156.                 MaxFog = 1400;
  157.                 if previous <= WaterLevel then
  158.                     TerrainPeice.Material = "Foil"
  159.                     TerrainPeice.BrickColor = BrickColor.new("Cyan")
  160.                     TerrainPeice.CanCollide = false;
  161.                     TerrainPeice.Position = Vector3.new(TerrainPeice.Position.X,WaterLevel,TerrainPeice.Position.Z)
  162.                 else
  163.                     if TerrainPeice.Position.Y > WaterLevel + 2 then
  164.                         local newTree = script.Imports.Tree.OakTree:Clone()
  165.                         local randomX = math.random(-30,30)
  166.                         local randomZ = math.random(-30,30)
  167.                         local randomX1 = math.random(-30,30)
  168.                         local randomZ1 = math.random(-30,30)
  169.                         --print(randomX);
  170.                         if RandomStage == 0 then
  171.                             newTree:SetPrimaryPartCFrame((TerrainPeice.CFrame)*CFrame.new(randomX,5+math.random(1,10),randomZ))
  172.                             RandomStage = RandomStage + 1
  173.                         end
  174.                         if RandomStage == 1 then
  175.                             newTree:SetPrimaryPartCFrame((TerrainPeice.CFrame)*CFrame.new(randomX1,5+math.random(1,10),randomZ1))
  176.                             RandomStage = 0
  177.                         end
  178.                         newTree.Parent = game.Workspace.Trees
  179.                     end
  180.                 end
  181.             end
  182.             if TerrainPeice.Name == "InterstateGround" then
  183.                 TerrainPeice.Material = "Pebble";
  184.                 TerrainPeice.BrickColor = BrickColor.new("Fossil");
  185.             end
  186.             previous = TerrainPeice.Position.Y;
  187.             TerrainPeice.Parent = game.Workspace:WaitForChild("TerrainG");
  188.             CountUpArray[countUp] = TerrainPeice.Position.Y;
  189.             countUp = countUp + 1;
  190.         end
  191.         print("Building terrain.. "..math.floor((row/TerrainSize)*100).."%");
  192.         row = row + 1;
  193.         countUp = 0;
  194.     end
  195. end
  196. GenerateTerrain();
  197. Sel = Instance.new("Part")
  198. Sel.Name = "Selection";
  199. Sel.Size = Vector3.new(64,720,64);
  200. Sel.BrickColor = BrickColor.new("Really red")
  201. Sel.Material = "Plastic";
  202. Sel.Parent = game.Workspace
  203. Sel.Position = Vector3.new(0,WaterLevel,InterstateRow*64)
  204. Sel.Anchored = true
  205. Sel.CanCollide = true;
  206. --:GetTouchingParts()
  207. mathstore1 = 0
  208. mathstore2 = 0
  209. mathstore3 = 0
  210. function InteractSel(action)
  211.     --[[   ACTIONS
  212.         /PlaceRoadRot0
  213.         /PlaceRoadRot90
  214.         /RadioTower
  215.         /PlaceInt4WNT
  216.         /MainRoadX
  217.     ]]
  218.     local count = 1
  219.     if action == "PlaceRoadRot0" then
  220.         --
  221.         local newRoad = script.Imports.Road.RoadSegment:Clone();
  222.         newRoad.Parent = game.Workspace.Roads;
  223.         Sel.Orientation = Vector3.new(0,0,0);
  224.         local SelCfr = Sel.CFrame
  225.         print(SelCfr)
  226.         newRoad:SetPrimaryPartCFrame(SelCfr*CFrame.new(0,21,0))
  227.         --
  228.         local TouchingParts = game.Workspace.Selection:GetTouchingParts();
  229.         local NumT = #TouchingParts
  230.         print(NumT)
  231.         while count < NumT+1 do
  232.             print("CountUp")
  233.             if TouchingParts[count].Name == "Grass" then
  234.                 local PartSelected = TouchingParts[count]
  235.                 local PartSP = PartSelected.Position
  236.                 PartSelected.Position = Vector3.new(PartSP.X,WaterLevel+1,PartSP.Z)
  237.                 PartSelected.Name = "UsedLand"
  238.             end
  239.             if TouchingParts[count].Name == "TrunkDetector" then
  240.                 local SelectedTree = TouchingParts[count]
  241.                 SelectedTree.Parent.Parent:Destroy();
  242.             end
  243.             count = count + 1;
  244.         end
  245.         count = 1
  246.     end
  247.    
  248.     ----------------------------------------------------------------------------------------
  249.    
  250.     if action == "MainRoadX" then
  251.         --
  252.         Sel.Position = Vector3.new(Sel.Position.X+32,Sel.Position.Y,Sel.Position.Z+32)
  253.         Sel.Size = Vector3.new(Sel.Size.X+64,Sel.Size.Y,Sel.Size.Z+64)
  254.         local newRoad = script.Imports.Road.MajorRoad1:Clone();
  255.         newRoad.Parent = game.Workspace.Roads;
  256.         Sel.Orientation = Vector3.new(0,0,0);
  257.         local SelCfr = Sel.CFrame
  258.         newRoad:SetPrimaryPartCFrame(SelCfr*CFrame.new(0,21,0))
  259.         --
  260.         local TouchingParts = game.Workspace.Selection:GetTouchingParts();
  261.         local NumT = #TouchingParts
  262.         while count < NumT+1 do
  263.             if TouchingParts[count].Name == "Grass" then
  264.                 local PartSelected = TouchingParts[count]
  265.                 local PartSP = PartSelected.Position
  266.                 local Level = Sel.Position.Y;
  267.                 PartSelected.Position = Vector3.new(PartSP.X,WaterLevel+1,PartSP.Z)
  268.                 PartSelected.Name = "UsedLand"
  269.             end
  270.             if TouchingParts[count].Name == "TrunkDetector" then
  271.                 local SelectedTree = TouchingParts[count]
  272.                 SelectedTree.Parent.Parent:Destroy();
  273.             end
  274.             if TouchingParts[count].Name == "Road" then
  275.                 TouchingParts[count].Parent:Destroy();
  276.                 newRoad:Destroy();
  277.                 local Intersection = script.Imports.Road.InterstateMain4TL:Clone()
  278.                 Intersection.Parent = game.Workspace.Roads;
  279.                 Intersection:SetPrimaryPartCFrame(SelCfr * CFrame.new(0,21,0));
  280.             end
  281.             count = count + 1;
  282.         end
  283.         count = 1
  284.         Sel.Size = Vector3.new(Sel.Size.X-64,Sel.Size.Y,Sel.Size.Z-64)
  285.         Sel.Position = Vector3.new(Sel.Position.X-32,Sel.Position.Y,Sel.Position.Z-32)
  286.     end
  287.    
  288.     ----------------------------------------------------------------------------------------
  289.    
  290.     count = 1
  291.     if action == "PlaceRoadRot90" then
  292.         --
  293.         local newRoad = script.Imports.Road.RoadSegment:Clone();
  294.         newRoad.Parent = game.Workspace.Roads;
  295.         Sel.Orientation = Vector3.new(0,90,0);
  296.         local SelCfr = Sel.CFrame
  297.         newRoad:SetPrimaryPartCFrame(SelCfr*CFrame.new(0,21,0))
  298.         --
  299.         local TouchingParts = game.Workspace.Selection:GetTouchingParts();
  300.         local NumT = #TouchingParts
  301.         while count < NumT+1 do
  302.             if TouchingParts[count].Name == "Grass" then
  303.                 local PartSelected = TouchingParts[count]
  304.                 local PartSP = PartSelected.Position
  305.                 PartSelected.Position = Vector3.new(PartSP.X,WaterLevel+1,PartSP.Z)
  306.                 PartSelected.Name = "UsedLand"
  307.             end
  308.             if TouchingParts[count].Name == "TrunkDetector" then
  309.                 local SelectedTree = TouchingParts[count]
  310.                 SelectedTree.Parent.Parent:Destroy();
  311.             end
  312.             count = count + 1;
  313.         end
  314.         count = 1
  315.     end
  316.  
  317.     if action == "PlaceInt4WNT" then
  318.         --
  319.         local newRoad = script.Imports.Road.FourINTNP:Clone();
  320.         newRoad.Parent = game.Workspace.Roads;
  321.         Sel.Orientation = Vector3.new(0,90,0);
  322.         local SelCfr = Sel.CFrame
  323.         newRoad:SetPrimaryPartCFrame(SelCfr*CFrame.new(0,21,0))
  324.         --
  325.         local TouchingParts = game.Workspace.Selection:GetTouchingParts();
  326.         local NumT = #TouchingParts
  327.         while count < NumT+1 do
  328.             if TouchingParts[count].Name == "Grass" then
  329.                 local PartSelected = TouchingParts[count]
  330.                 local PartSP = PartSelected.Position
  331.                 PartSelected.Position = Vector3.new(PartSP.X,WaterLevel+1,PartSP.Z)
  332.                 PartSelected.Name = "UsedLand"
  333.             end
  334.             if TouchingParts[count].Name == "TrunkDetector" then
  335.                 local SelectedTree = TouchingParts[count]
  336.                 SelectedTree.Parent.Parent:Destroy();
  337.             end
  338.             count = count + 1;
  339.         end
  340.         count = 1
  341.     end
  342.    
  343.     if action == "MoveZ+" then
  344.         Sel.Position = Vector3.new(Sel.Position.X,Sel.Position.Y,Sel.Position.Z+64);
  345.         wait(0.1)
  346.     end
  347.     if action == "MoveZ-" then
  348.         Sel.Position = Vector3.new(Sel.Position.X,Sel.Position.Y,Sel.Position.Z-64);
  349.         wait(0.1)
  350.     end
  351.     if action == "MoveX+" then
  352.         Sel.Position = Vector3.new(Sel.Position.X+64,Sel.Position.Y,Sel.Position.Z);
  353.         wait(0.1)
  354.     end
  355.     if action == "MoveX-" then
  356.         Sel.Position = Vector3.new(Sel.Position.X-64,Sel.Position.Y,Sel.Position.Z);
  357.         wait(0.1)
  358.     end
  359.     if action == "RadioTower" then
  360.         print(Sel.Position)
  361.         print("Spawning RadioTower")
  362.         local TouchingThings = Sel:GetTouchingParts()
  363.         local TouchingCount = #TouchingThings
  364.         while TouchingCount > 0 do
  365.             TouchingThings[TouchingCount].Material = "Concrete";
  366.             TouchingThings[TouchingCount].BrickColor = BrickColor.new("Ghost grey");
  367.             local selType = math.random(1,3)
  368.             wait(1)
  369.             if selType == 1 then
  370.                 local tower = script.Imports.Props.RadioTower1:Clone()
  371.                 tower.Parent = game.Workspace.Props
  372.                 tower:SetPrimaryPartCFrame(Sel.CFrame)
  373.             end
  374.             if selType == 2 then
  375.                 print("2 T")
  376.                 local tower = script.Imports.Props.RadioTower2:Clone()
  377.                 tower.Parent = game.Workspace.Props
  378.                 tower:SetPrimaryPartCFrame(Sel.CFrame)
  379.             end
  380.             if selType == 3 then
  381.                 print("3 T")
  382.                 local tower = script.Imports.Props.RadioTower3:Clone()
  383.                 tower.Parent = game.Workspace.Props
  384.                 tower:SetPrimaryPartCFrame(Sel.CFrame)
  385.             end
  386.             TouchingCount = TouchingCount - 1
  387.         end
  388.     end
  389. end
  390. function GenerateRoadGrid(LengthZ,HeightX,Corner1,Corner2,Corner3,Corner4)
  391.     local counter = LengthZ
  392.     while counter > 0 do
  393.         InteractSel("MoveZ-")
  394.         InteractSel("PlaceRoadRot0");
  395.         counter = counter - 1
  396.     end
  397.     InteractSel("MoveZ-")
  398.     if Corner1 == "4NT" then
  399.         InteractSel("PlaceInt4WNT")
  400.     end
  401.     counter = HeightX
  402.     while counter > 0 do
  403.         InteractSel("MoveX-")
  404.         InteractSel("PlaceRoadRot90")
  405.         counter = counter - 1;
  406.     end
  407.     InteractSel("MoveX-")
  408.     if Corner1 == "4NT" then
  409.         InteractSel("PlaceInt4WNT")
  410.     end
  411.     counter = LengthZ
  412.     while counter > 0 do
  413.         InteractSel("MoveZ+")
  414.         InteractSel("PlaceRoadRot0");
  415.         counter = counter - 1
  416.     end
  417.     InteractSel("MoveZ+")
  418.     if Corner1 == "4NT" then
  419.         InteractSel("PlaceInt4WNT")
  420.     end
  421.     counter = HeightX
  422.     while counter > 0 do
  423.         InteractSel("MoveX+")
  424.         InteractSel("PlaceRoadRot90")
  425.         counter = counter - 1;
  426.     end
  427.     InteractSel("MoveX+")
  428.     if Corner1 == "4NT" then
  429.         InteractSel("PlaceInt4WNT")
  430.     end  
  431. end
  432. function GenerateRoads()
  433.     local MainRoads = math.random(1,(math.floor(TerrainSize/10)))
  434.     local count = 0
  435.     while MainRoads > 0 do
  436.         Sel.Position = Vector3.new(64*math.random(1,(TerrainSize - 2)),Sel.Position.Y,0)
  437.         if math.random(1,2) == 1 then
  438.             print("Spawning Road X")
  439.             while count < TerrainSize/2 do
  440.                 InteractSel("MainRoadX")
  441.                 InteractSel("MoveZ+")
  442.                 InteractSel("MoveZ+")
  443.                 count = count + 1
  444.             end
  445.             Sel.Position = Vector3.new(Sel.Position.X,WaterLevel,Sel.Position.Z)
  446.             count = 0
  447.             wait(1)
  448.         else
  449.             print("Spawning Road X")
  450.             while count < TerrainSize/2 do
  451.                 InteractSel("MainRoadX")
  452.                 InteractSel("MoveZ+")
  453.                 InteractSel("MoveZ+")
  454.                 count = count + 1
  455.             end
  456.             count = 0
  457.             wait(1)
  458.         end
  459.         MainRoads = MainRoads - 1
  460.         wait(1);
  461.     end
  462.     InteractSel("MoveX+");
  463.     InteractSel("MoveX+");
  464.     InteractSel("MoveX+");
  465.     InteractSel("MoveX+");
  466.     InteractSel("MoveZ+");
  467.     InteractSel("MoveZ+");
  468.     InteractSel("MoveZ+");
  469.     GenerateRoadGrid(5,3,"4NT","4NT","4NT","4NT")
  470. end
  471.    
  472. mathstore2 = 0
  473. FindX = math.random(1,TerrainSize)
  474. FindZ = math.random(1,TerrainSize)
  475. function GenerateCity()
  476.     GenerateRoads()
  477.     local NumRadioTowers = math.random(1,math.floor(TerrainSize/10))
  478.     while NumRadioTowers > 0 do
  479.         NumRadioTowers = NumRadioTowers - 1
  480.         while FindX == mathstore1 do
  481.             FindX = math.random(1,TerrainSize-1)
  482.         end
  483.         while FindZ == mathstore2 do
  484.             FindZ = math.random(1,TerrainSize-1)
  485.         end
  486.         mathstore1 = FindX
  487.         mathstore2 = FindZ
  488.         Sel.Position = Vector3.new(FindX*64,WaterLevel+1,FindZ*64);
  489.         InteractSel("RadioTower");
  490.     end
  491. end
  492. GenerateCity()
  493. game.Workspace.Selection:Destroy();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement