Guest User

Wall by Big SHiny Toys

a guest
Sep 21st, 2012
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. local tArgs = {...}
  2. local iSlot = 1
  3. local bDebug = false
  4. local function printUsage()
  5.     print("Wall <Distance> <hight>")
  6. end
  7. local function refuel()
  8.     local slotSelX,slotSelY = 1,1
  9.     print("use [Up Dwon Left Right] keys to seleft fuel slot")
  10.     print([[Press "r" refuel or "c" to continue]])
  11.     while true do
  12.         local e,e1,e2,e3 = os.pullEvent()
  13.         if e == "key" then
  14.             if e1 == 200 then -- up turtle.select(e1-1)     local slotSelX = 1  local slotSelY = 1
  15.                 slotSelY = slotSelY -1
  16.                 if slotSelY < 1 then
  17.                     slotSelY = 4
  18.                 end
  19.             elseif e1 == 208 then -- down
  20.                 slotSelY = slotSelY +1
  21.                 if slotSelY > 4 then
  22.                     slotSelY = 1
  23.                 end
  24.             elseif e1 == 203 then -- left
  25.                 slotSelX = slotSelX -1
  26.                 if slotSelX < 1 then
  27.                     slotSelX = 4
  28.                 end
  29.             elseif e1 == 205 then -- right
  30.                 slotSelX = slotSelX +1
  31.                 if slotSelX > 4 then
  32.                     slotSelX = 1
  33.                 end
  34.             elseif e1 == 19 then -- r
  35.                 turtle.refuel(1)
  36.             elseif e1 == 46 then -- c
  37.                 break
  38.             end
  39.         end
  40.         turtle.select(slotSelX+(slotSelY*4)-4)
  41.     end
  42.     return
  43. end
  44. local function funtUP()
  45.     while not turtle.up() do
  46.         if turtle.getFuelLevel() > 1 then
  47.         sleep(1)
  48.         else
  49.             print("Turtle fuel Levle : "..turtle.getFuelLevel())
  50.             refuel()
  51.         end
  52.     end
  53. end
  54.  
  55. local function funtForward()
  56.     while not turtle.forward() do
  57.         if turtle.getFuelLevel() > 1 then
  58.         sleep(1)
  59.         else
  60.             print("Turtle fuel Levle : "..turtle.getFuelLevel())
  61.             refuel()
  62.         end
  63.     end
  64. end
  65.  
  66. local function checkFor()
  67.     for i = 16,1,-1 do
  68.         local iTotal = turtle.getItemCount(i)
  69.         if bDebug then
  70.             write(tostring(iTotal).." ")
  71.         end
  72.         if iTotal > 0 then
  73.             iSlot = i
  74.             turtle.select(iSlot)
  75.             turtle.placeDown()
  76.             return true
  77.         end
  78.     end
  79.     return false
  80. end
  81.  
  82. local function fplace()
  83.     local found = false
  84.     turtle.select(iSlot)
  85.     if turtle.getItemCount(iSlot) > 0 then
  86.         turtle.placeDown()
  87.         return true
  88.     else
  89.         if not checkFor() then
  90.         print([[No Items in turtle fill turtle and press "c" to continue]])
  91.         while true do
  92.             local e,e1 = os.pullEvent("char")
  93.             if e == "char" and e1 == "c" then
  94.                 if checkFor() then
  95.                     return
  96.                 else
  97.                     print("\nNo blocks added")
  98.                 end
  99.             end
  100.         end
  101.         else
  102.             return
  103.         end
  104.     end
  105. end
  106.  
  107. local function buildWall(inputlength,inputhight)
  108.         funtUP()
  109.         fplace()
  110.     for p = 1,inputhight do
  111.         for x = 1,inputlength-1 do
  112.             funtForward()
  113.             fplace()
  114.         end
  115.         if p ~= inputhight then
  116.         funtUP()
  117.         fplace()
  118.         turtle.turnLeft()
  119.         turtle.turnLeft()
  120.         end
  121.     end
  122. end
  123.  
  124. if #tArgs == 3 then
  125.     if tArgs[3] == "test" then
  126.         bDebug = true
  127.     end
  128.     table.remove(tArgs,3)
  129. end
  130.  
  131. if #tArgs ~= 2 then
  132.     printUsage()
  133. else
  134.     local iDistance,iHight = tonumber(tArgs[1]),tonumber(tArgs[2])
  135.     if iDistance == nil or iHight == nil then
  136.         printUsage()
  137.     else
  138.     print("Turtle fuel Levle : "..turtle.getFuelLevel())
  139.     buildWall(iDistance,iHight)
  140.     print("\nFinished wall")
  141.     end
  142. end
Add Comment
Please, Sign In to add comment