kLeeNex24

wall

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