Advertisement
QuantumWarpCode

Computercraft City Generator V3

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