Advertisement
QuantumWarpCode

Computercraft City Generator V3.1

Nov 6th, 2015
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.51 KB | None | 0 0
  1. --made by elopus001
  2. --@QuantumWarpCode
  3. --Version 3.1
  4.  
  5. print("Initializing arguements")
  6.  
  7. local tArgs = { ... }
  8.  
  9. if #tArgs == 1 then
  10.     command = tArgs[1]
  11. elseif #tArgs == 6 then
  12.     command = tArgs[1]
  13.     xstart = tArgs[2]
  14.     ystart = tArgs[3]
  15.     zstart = tArgs[4]
  16.     xtotal_chunks = tArgs[5]
  17.     ztotal_chunks = tArgs[6]
  18. elseif #tArgs == 7 then
  19.     command = tArgs[1]
  20.     xstart = tArgs[2]
  21.     ystart = tArgs[3]
  22.     zstart = tArgs[4]
  23.     xtotal_chunks = tArgs[5]
  24.     ztotal_chunks = tArgs[6]
  25.     block_type = tArgs[7]
  26. else
  27.     print("citygen <Command> <Corner X> <Height> <Corner Z> <Chunks X> <Chunks Y>")
  28.     return
  29. end
  30.  
  31.  
  32.  
  33. print("Initializing files...")
  34.  
  35. if fs.exists("/blocklog") == true then
  36.     blocklog = io.open("/blocklog", "a")
  37. else
  38.     blocklog = io.open("/blocklog", "w")
  39. end
  40.  
  41. if fs.exists("/chunklog") == true then
  42.     chunklog = io.open("/chunklog", "a")
  43. else
  44.     chunklog = io.open("/chunklog", "w")
  45. end
  46.  
  47.  
  48.  
  49. print("Initializing variables...")
  50.  
  51. --probabilities
  52. --all values must be integers unless otherwise states
  53. sleep_time = 0 --does not have to be an integer
  54.  
  55. --configure
  56. async = false
  57.  
  58. --block types
  59. sidewalk_blocks = {"stone", "cobblestone", "stonebrick", "double_stone_slab"}
  60. wall_blocks = {"stone", "cobblestone", "stonebrick", "iron_block"}
  61. floor_blocks = {"planks", "planks 1", "planks 5", "wool", "wool 9", "wool 14", "wool 15"}
  62. ceiling_blocks ={"planks", "planks 1", "planks 5", "stone", "cobblestone", "stonebrick"}
  63. glass_blocks = {"glass", "stained_glass", "stained_glass 3", "stained_glass 11", "stained_glass 12", "stained_glass 15", "glass_pane", "stained_glass_pane", "stained_glass_pane 3", "stained_glass_pane 11", "stained_glass_pane 12", "stained_glass_pane 15"}
  64. leave_blocks = {"leaves 4", "leaves 5", "leaves 6", "leaves 7", "leaves2 4", "leaves2 5"}
  65. flower_blocks = {"tallgrass 1", "tallgrass 2", "yellow_flower", "red_flower", "red_flower 1", "red_flower 2", "red_flower 3" , "red_flower 4", "red_flower 5", "red_flower 6", "red_flower 7", "red_flower 8"}
  66. light_blocks = {"glowstone"}
  67.  
  68.  
  69.  
  70. print("Initializing functions...")
  71.  
  72. function shiftsetblock(xshift, yshift, zshift, block)
  73.     x = xstart + xshift
  74.     y = ystart + yshift
  75.     z = zstart + zshift
  76.     --blocklog:write("Placing block of "..block.." at "..x.." "..y.." "..z.."\n")
  77.     if async == true then
  78.         commands.execAsync("setblock "..x.." "..y.." "..z.." "..block)
  79.     else
  80.         commands.exec("setblock "..x.." "..y.." "..z.." "..block)
  81.     end
  82.     sleep(sleep_time)
  83. end
  84.  
  85. function fillrectangle(xshift, yshift, zshift, xlength, zlength, block)
  86.     xcounter = 0
  87.     while xcounter < xlength do
  88.         zcounter = 0
  89.             while zcounter < zlength do
  90.                 shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, block)
  91.                 zcounter = zcounter + 1
  92.             end
  93.         xcounter = xcounter + 1
  94.     end
  95. end
  96.  
  97. function fillrectangleE(xshift, yshift, zshift, xlength, zlength, interiorblock, edgeblock)
  98.     xcounter = 0
  99.     while xcounter < xlength do
  100.         zcounter = 0
  101.             while zcounter < zlength do
  102.                 if xcounter == 0 or xcounter == xlength - 1 or zcounter == 0 or zcounter == zlength - 1 then
  103.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, edgeblock)
  104.                 else
  105.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, interiorblock)
  106.                 end
  107.                 zcounter = zcounter + 1
  108.             end
  109.         xcounter = xcounter + 1
  110.     end
  111. end
  112.  
  113. function fillrectangleH(xshift, yshift, zshift, xlength, zlength, block)
  114.     xcounter = 0
  115.     while xcounter < xlength do
  116.         zcounter = 0
  117.             while zcounter < zlength do
  118.                 if xcounter == 0 or xcounter == xlength - 1 or zcounter == 0 or zcounter == zlength - 1 then
  119.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, block)
  120.                 end
  121.                 zcounter = zcounter + 1
  122.             end
  123.         xcounter = xcounter + 1
  124.     end
  125. end
  126.  
  127. function fillrectangleC(xshift, yshift, zshift, xlength, zlength, interiorblock, cornerblock)
  128.     xcounter = 0
  129.     while xcounter < xlength do
  130.         zcounter = 0
  131.             while zcounter < zlength do
  132.                 if (xcounter == 0 or xcounter == xlength - 1) and (zcounter == 0 or zcounter == zlength - 1) then
  133.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, cornerblock)
  134.                 else
  135.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, interiorblock)
  136.                 end
  137.                 zcounter = zcounter + 1
  138.             end
  139.         xcounter = xcounter + 1
  140.     end
  141. end
  142.  
  143. function fillrectangleHC(xshift, yshift, zshift, xlength, zlength, edgeblock, cornerblock)
  144.     xcounter = 0
  145.     while xcounter < xlength do
  146.         zcounter = 0
  147.             while zcounter < zlength do
  148.                 if (xcounter == 0 or xcounter == xlength - 1) and (zcounter == 0 or zcounter == zlength - 1) then
  149.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, cornerblock)
  150.                 elseif xcounter == 0 or xcounter == xlength - 1 or zcounter == 0 or zcounter == zlength - 1 then
  151.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, edgeblock)
  152.                 end
  153.                 zcounter = zcounter + 1
  154.             end
  155.         xcounter = xcounter + 1
  156.     end
  157. end
  158.  
  159. function fillrectangleHEC(xshift, yshift, zshift, xlength, zlength, edgeblock, cornerblock)
  160.     xcounter = 0
  161.     while xcounter < xlength do
  162.         zcounter = 0
  163.             while zcounter < zlength do
  164.                 if (xcounter == 0 or xcounter == xlength - 1) and (zcounter == 0 or zcounter == zlength - 1) then
  165.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, cornerblock)
  166.                 elseif xcounter == 0 or xcounter == xlength - 1 or zcounter == 0 or zcounter == zlength - 1 then
  167.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, edgeblock)
  168.                 end
  169.                 zcounter = zcounter + 1
  170.             end
  171.         xcounter = xcounter + 1
  172.     end
  173. end
  174.  
  175. function fillrectangleEC(xshift, yshift, zshift, xlength, zlength, interiorblock, edgeblock, cornerblock)
  176.     xcounter = 0
  177.     while xcounter < xlength do
  178.         zcounter = 0
  179.             while zcounter < zlength do
  180.                 if (xcounter == 0 or xcounter == xlength - 1) and (zcounter == 0 or zcounter == zlength - 1) then
  181.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, cornerblock)
  182.                 elseif xcounter == 0 or xcounter == xlength - 1 or zcounter == 0 or zcounter == zlength - 1 then
  183.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, edgeblock)
  184.                 else
  185.                     shiftsetblock(xshift + xcounter, yshift, zshift + zcounter, interiorblock)
  186.                 end
  187.                 zcounter = zcounter + 1
  188.             end
  189.         xcounter = xcounter + 1
  190.     end
  191. end
  192.  
  193. --Building functions
  194.  
  195. function buildskyscraper(xshift, yshift, zshift, xlength, zlength, sidewalk_block)
  196.     lawn = math.random(1, 3)
  197.     lawn = 2
  198.    
  199.     wall = wall_blocks[math.random(1, #wall_blocks)]
  200.     ceiling = ceiling_blocks[math.random(1, #ceiling_blocks)]
  201.     floor_block = floor_blocks[math.random(1, #floor_blocks)]
  202.     glass = glass_blocks[math.random(1, #glass_blocks)]
  203.     light = light_blocks[math.random(1, #light_blocks)]
  204.     leave = leave_blocks[math.random(1, #leave_blocks)]
  205.    
  206.     floors = math.random(3, 10)
  207.     floory = 0
  208.     ycounter = 0
  209.     floors = 2
  210.    
  211.     fillrectangleE(xshift + lawn + 1, yshift, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, floor_block, wall)
  212.    
  213.     while floory * 5 + ycounter < floors * 5 do
  214.         if ycounter == 3 then
  215.             fillrectangleE(xshift + lawn + 1, yshift + ycounter + floory * 5 + 1, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, ceiling, wall)
  216.             fillrectangle(xshift + 7, yshift + ycounter + floory * 5 + 1, zshift + 7, 2, 2, light)
  217.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 8, wall)
  218.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 7, "ladder 2")
  219.         elseif ycounter == 4 then
  220.             fillrectangleE(xshift + lawn + 1, yshift + ycounter + floory * 5 + 1, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, floor_block, wall)
  221.             if floory * 5 + ycounter + 1 ~= floors * 5 then
  222.                 shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 8, wall)
  223.             end
  224.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 7, "ladder 2")
  225.         else
  226.             fillrectangleHEC(xshift + lawn + 1, yshift + ycounter + floory * 5 + 1, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, glass, wall)
  227.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 8, wall)
  228.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 7, "ladder 2")
  229.         end
  230.  
  231.        
  232.         if ycounter == 4 then
  233.             floory = floory + 1
  234.             ycounter = 0
  235.         else
  236.             ycounter = ycounter + 1
  237.         end
  238.     end
  239.    
  240.     fillrectangleH(xshift + lawn + 1, yshift + floors * 5 + 1, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, wall)
  241.    
  242.     hedge = math.random(1, 4)
  243.     if hedge == 1 and lawn == 3 then
  244.         fillrectangleH(xshift + lawn - 1, yshift + 1, zshift + lawn - 1, 12, 12, leave)
  245.     end
  246.    
  247.     door = math.random(1, 15)
  248.     if door == 1 or door == 5 or door == 7 or door == 9 or door == 11 or door == 13 or door == 14 or door == 15 then
  249.         fillrectangle(xshift + 7, 0, zshift + 1, 2, lawn, sidewalk_block)
  250.         fillrectangle(xshift + 7, 1, zshift + 1, 2, lawn + 1, "air")
  251.         fillrectangle(xshift + 7, 2, zshift + 1, 2, lawn + 1, "air")
  252.     end
  253.     if door == 2 or door == 5 or door == 8 or door == 10 or door == 11 or door == 12 or door == 14 or door == 15 then
  254.         fillrectangle(xshift + 1, 0, zshift + 7, lawn, 2, sidewalk_block)
  255.         fillrectangle(xshift + 1, 1, zshift + 7, lawn + 1, 2, "air")
  256.         fillrectangle(xshift + 1, 2, zshift + 7, lawn + 1, 2, "air")
  257.     end
  258.     if door == 3 or door == 6 or door == 7 or door == 10 or door == 11 or door == 12 or door == 13 or door == 15 then
  259.         fillrectangle(xshift + 7, 0, zshift + 14 - lawn, 2, lawn, sidewalk_block)
  260.         fillrectangle(xshift + 7, 1, zshift + 14 - lawn, 2, lawn + 1, "air")
  261.         fillrectangle(xshift + 7, 2, zshift + 14 - lawn, 2, lawn + 1, "air")
  262.     end
  263.     if door == 4 or door == 6 or door == 8 or door == 9 or door == 12 or door == 13 or door == 14 or door == 15 then
  264.         fillrectangle(xshift + 14 - lawn, 0, zshift + 7, lawn, 2, sidewalk_block)
  265.         fillrectangle(xshift + 14 - lawn, 1, zshift + 7, lawn + 1, 2, "air")
  266.         fillrectangle(xshift + 14 - lawn, 2, zshift + 7, lawn + 1, 2, "air")
  267.     end
  268. end
  269.  
  270.  
  271.  
  272. print("Running command")
  273.  
  274. if command == "gen" or command == "generate" then
  275.     if #tArgs == 6 then
  276.        
  277.        
  278.         xchunkcounter = 0
  279.         while xchunkcounter < xtotal_chunks  * 1 do --A glitchy fix for an error involving comparing string with number
  280.             zchunkcounter = 0
  281.             while zchunkcounter < ztotal_chunks * 1 do --A glitchy fix for an error involving comparing string with number
  282.                 commands.getBlockInfo(xchunkcounter * 16 + xstart, ystart * 1, zchunkcounter * 16 + zstart) --Force chunk loading
  283.                 zchunkcounter = zchunkcounter + 1
  284.             end
  285.             xchunkcounter = xchunkcounter + 1
  286.         end
  287.        
  288.         sidewalk_block = sidewalk_blocks[math.random(1, #sidewalk_blocks)]
  289.        
  290.         xchunkcounter = 0
  291.         while xchunkcounter < xtotal_chunks  * 1 do --A glitchy fix for an error involving comparing string with number
  292.             zchunkcounter = 0
  293.             while zchunkcounter < ztotal_chunks * 1 do --A glitchy fix for an error involving comparing string with number
  294.                 fillrectangleE(xchunkcounter * 16, 0, zchunkcounter * 16, 16, 16, "grass", sidewalk_block)
  295.                 buildskyscraper(xchunkcounter * 16, 0, zchunkcounter * 16, 1, 1, sidewalk_block)
  296.                 zchunkcounter = zchunkcounter + 1
  297.             end
  298.             xchunkcounter = xchunkcounter + 1
  299.         end
  300.        
  301.        
  302.     else
  303.         print("Invalid arguements")
  304.     end
  305. elseif command == "reset" then
  306.     if #tArgs == 7 then
  307.         fillrectangle(0, 0, 0, 16 * xtotal_chunks, 16 * ztotal_chunks, block_type)
  308.     elseif #tArgs == 6 then
  309.         fillrectangle(0, 0, 0, 16 * xtotal_chunks, 16 * ztotal_chunks, "grass")
  310.     else
  311.         print("Invalid arguements")
  312.     end
  313. else
  314.     print("Invalid command")
  315. end
  316.  
  317. blocklog:write("Finished command".."\n\n")
  318. blocklog:close()
  319. chunklog:write("Finished command".."\n\n")
  320. chunklog:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement