Advertisement
Stiepen

[COMPUTERCRAFT] Platform/Cube Building script

Aug 13th, 2012
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. --[[
  2. Command usage can be shown by simply executing the script without parameters.
  3. Copyright by Stephan Henrichs, 2012
  4. Licensed under CC BY-NC-SA 3.0
  5. More Information: http://creativecommons.org/licenses/by-nc-sa/3.0/
  6. I'd appreciate to credit me btw :P
  7. ]]--
  8. tArgs = {}
  9. tmpArgs = {...}
  10. function printUsage()
  11.   print("Usage: platform <length> <width> <height> [<ofset_length> <offset_width> <offset_heigh>]")
  12. end
  13.  
  14. -- Testing args
  15. function parseArgs()
  16.   local tmp = tmpArgs
  17.   if tmp[1] == nil or tmp[2] == nil or tmp[3] == nil then
  18.     return false
  19.   else
  20.     tArgs['x'] = tonumber(tmp[1])
  21.     tArgs['z'] = tonumber(tmp[2])
  22.     tArgs['y'] = tonumber(tmp[3])
  23.     if tmp[4] ~= nil and (tmp[5] == nil or tmp[6] == nil) then
  24.       return false
  25.     elseif tmp[4] == nil then
  26.       tArgs['ox'] = 0
  27.       tArgs['oz'] = 0
  28.       tArgs['oy'] = 0
  29.       return true
  30.     else
  31.       tArgs['ox'] = tonumber(tmp[4])
  32.       tArgs['oz'] = tonumber(tmp[5])
  33.       tArgs['oy'] = tonumber(tmp[6])
  34.       return true
  35.     end
  36.   end
  37. end
  38.  
  39. function selectFirstUsableSlot()
  40.   for i1 = 1,16 do
  41.     if turtle.getItemCount(i1) > 0 then
  42.       turtle.select(i1)
  43.       return true
  44.     end
  45.   end
  46.   return false
  47. end
  48.  
  49. function go(len)
  50.   for i5=1, len do
  51.     turtle.forward()
  52.   end
  53. end
  54.  
  55. function buildBlock()
  56.   if selectFirstUsableSlot() then
  57.     turtle.placeDown()
  58.   else
  59.     print("Out of Recources")
  60.     --os.exit()
  61.   end
  62. end
  63.  
  64. function buildRow(last)
  65.   for i2 = 1, tArgs['x'] do
  66.     buildBlock()
  67.     if (i2 == tArgs['x']) then else
  68.       turtle.forward()
  69.     end
  70.   end
  71. end
  72.  
  73. local dir = 0
  74.  
  75. function turn()
  76.   if dir == 1 then
  77.     turtle.turnLeft()
  78.     turtle.forward()
  79.     turtle.turnLeft()
  80.     dir = 0
  81.   else
  82.     turtle.turnRight()
  83.     turtle.forward()
  84.     turtle.turnRight()
  85.     dir = 1
  86.   end
  87. end
  88.  
  89. function buildLayer()
  90.   for i3 = 1, tArgs['z'] do
  91.     buildRow(i3==tArgs['z'])
  92.     if i3 ~= tArgs['z'] then
  93.       turn()
  94.     end
  95.   end
  96.   dir = 0
  97. end
  98.  
  99. function buildPlat()
  100.   for i4 = 1, tArgs['y'] do
  101.     buildLayer()
  102.     if i4 ~= tArgs['y'] then
  103.       turtle.up()
  104.     end
  105.     if tArgs['z'] % 2 == 1 then
  106.       turtle.turnRight()
  107.       turtle.turnRight()
  108.       go(tArgs['x']-1)
  109.     end
  110.     turtle.turnRight()
  111.     go(tArgs['z']-1)
  112.     turtle.turnRight()
  113.   end
  114. end
  115.  
  116. function goToStart()
  117.   local x = tArgs['ox']
  118.   local y = tArgs['oy']
  119.   local z = tArgs['oz']
  120.  
  121.   if x < 0 then
  122.     x = x * -1
  123.     turtle.turnLeft()
  124.     turtle.turnLeft()
  125.     go(x)
  126.     turtle.turnLeft()
  127.     turtle.turnLeft()
  128.   else
  129.     go(x)
  130.   end
  131.   if z < 0 then
  132.     z = z * -1
  133.     turtle.turnLeft()
  134.     go(z)
  135.     turtle.turnRight()
  136.   else
  137.     turtle.turnRight()
  138.     go(z)
  139.     turtle.turnLeft()
  140.   end
  141.   if y < 0 then
  142.     for i6 = 1, y * -1 do
  143.       turtle.down()
  144.     end
  145.   else
  146.     for i6 = 1, y do
  147.       turtle.up()
  148.     end
  149.   end
  150. end
  151.  
  152. if parseArgs() then
  153.   goToStart()
  154.   buildPlat()
  155. else
  156.   printUsage()
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement