Advertisement
QuantumWarpCode

Computercraft City Generator V3.2

Nov 6th, 2015
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.49 KB | None | 0 0
  1. --made by elopus001
  2. --@QuantumWarpCode
  3. --Version 3.2
  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.    
  198.     wall = wall_blocks[math.random(1, #wall_blocks)]
  199.     ceiling = ceiling_blocks[math.random(1, #ceiling_blocks)]
  200.     floor_block = floor_blocks[math.random(1, #floor_blocks)]
  201.     glass = glass_blocks[math.random(1, #glass_blocks)]
  202.     light = light_blocks[math.random(1, #light_blocks)]
  203.     leave = leave_blocks[math.random(1, #leave_blocks)]
  204.    
  205.     floors = math.random(3, 10)
  206.     floory = 0
  207.     ycounter = 0
  208.    
  209.     fillrectangleE(xshift + lawn + 1, yshift, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, floor_block, wall)
  210.    
  211.     while floory * 5 + ycounter < floors * 5 do
  212.         if ycounter == 3 then
  213.             fillrectangleE(xshift + lawn + 1, yshift + ycounter + floory * 5 + 1, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, ceiling, wall)
  214.             fillrectangle(xshift + 7, yshift + ycounter + floory * 5 + 1, zshift + 7, 2, 2, light)
  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.         elseif ycounter == 4 then
  218.             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)
  219.             if floory * 5 + ycounter + 1 ~= floors * 5 then
  220.                 shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 8, wall)
  221.             end
  222.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 7, "ladder 2")
  223.         else
  224.             fillrectangleHEC(xshift + lawn + 1, yshift + ycounter + floory * 5 + 1, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, glass, wall)
  225.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 8, wall)
  226.             shiftsetblock(xshift +7 , yshift + ycounter + floory * 5 + 1, zshift + 7, "ladder 2")
  227.         end
  228.  
  229.        
  230.         if ycounter == 4 then
  231.             floory = floory + 1
  232.             ycounter = 0
  233.         else
  234.             ycounter = ycounter + 1
  235.         end
  236.     end
  237.    
  238.     fillrectangleH(xshift + lawn + 1, yshift + floors * 5 + 1, zshift + lawn + 1, xlength * 16 - lawn * 2 - 2, zlength * 16 - lawn * 2 - 2, wall)
  239.    
  240.     hedge = math.random(1, 4)
  241.     if hedge == 1 and lawn == 3 then
  242.         fillrectangleH(xshift + lawn - 1, yshift + 1, zshift + lawn - 1, 12, 12, leave)
  243.     end
  244.    
  245.     door = math.random(1, 15)
  246.     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
  247.         fillrectangle(xshift + 7, 0, zshift + 1, 2, lawn, sidewalk_block)
  248.         fillrectangle(xshift + 7, 1, zshift + 1, 2, lawn + 1, "air")
  249.         fillrectangle(xshift + 7, 2, zshift + 1, 2, lawn + 1, "air")
  250.     end
  251.     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
  252.         fillrectangle(xshift + 1, 0, zshift + 7, lawn, 2, sidewalk_block)
  253.         fillrectangle(xshift + 1, 1, zshift + 7, lawn + 1, 2, "air")
  254.         fillrectangle(xshift + 1, 2, zshift + 7, lawn + 1, 2, "air")
  255.     end
  256.     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
  257.         fillrectangle(xshift + 7, 0, zshift + 15 - lawn, 2, lawn, sidewalk_block)
  258.         fillrectangle(xshift + 7, 1, zshift + 14 - lawn, 2, lawn + 1, "air")
  259.         fillrectangle(xshift + 7, 2, zshift + 14 - lawn, 2, lawn + 1, "air")
  260.     end
  261.     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
  262.         fillrectangle(xshift + 15 - lawn, 0, zshift + 7, lawn, 2, sidewalk_block)
  263.         fillrectangle(xshift + 14 - lawn, 1, zshift + 7, lawn + 1, 2, "air")
  264.         fillrectangle(xshift + 14 - lawn, 2, zshift + 7, lawn + 1, 2, "air")
  265.     end
  266. end
  267.  
  268.  
  269.  
  270. print("Running command")
  271.  
  272. if command == "gen" or command == "generate" then
  273.     if #tArgs == 6 then
  274.        
  275.        
  276.         xchunkcounter = 0
  277.         while xchunkcounter < xtotal_chunks  * 1 do --A glitchy fix for an error involving comparing string with number
  278.             zchunkcounter = 0
  279.             while zchunkcounter < ztotal_chunks * 1 do --A glitchy fix for an error involving comparing string with number
  280.                 commands.getBlockInfo(xchunkcounter * 16 + xstart, ystart * 1, zchunkcounter * 16 + zstart) --Force chunk loading
  281.                 zchunkcounter = zchunkcounter + 1
  282.             end
  283.             xchunkcounter = xchunkcounter + 1
  284.         end
  285.        
  286.         sidewalk_block = sidewalk_blocks[math.random(1, #sidewalk_blocks)]
  287.        
  288.         xchunkcounter = 0
  289.         while xchunkcounter < xtotal_chunks  * 1 do --A glitchy fix for an error involving comparing string with number
  290.             zchunkcounter = 0
  291.             while zchunkcounter < ztotal_chunks * 1 do --A glitchy fix for an error involving comparing string with number
  292.                 fillrectangleE(xchunkcounter * 16, 0, zchunkcounter * 16, 16, 16, "grass", sidewalk_block)
  293.                 buildskyscraper(xchunkcounter * 16, 0, zchunkcounter * 16, 1, 1, sidewalk_block)
  294.                 zchunkcounter = zchunkcounter + 1
  295.             end
  296.             xchunkcounter = xchunkcounter + 1
  297.         end
  298.        
  299.        
  300.     else
  301.         print("Invalid arguements")
  302.     end
  303. elseif command == "reset" then
  304.     if #tArgs == 7 then
  305.         fillrectangle(0, 0, 0, 16 * xtotal_chunks, 16 * ztotal_chunks, block_type)
  306.     elseif #tArgs == 6 then
  307.         fillrectangle(0, 0, 0, 16 * xtotal_chunks, 16 * ztotal_chunks, "grass")
  308.     else
  309.         print("Invalid arguements")
  310.     end
  311. else
  312.     print("Invalid command")
  313. end
  314.  
  315. blocklog:write("Finished command".."\n\n")
  316. blocklog:close()
  317. chunklog:write("Finished command".."\n\n")
  318. chunklog:close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement