Advertisement
LeslieCraft

Minecraft, computercraft Follow the red wool

Jun 25th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.41 KB | None | 0 0
  1. --[[
  2. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  3. If U have a question, write under the YT video.
  4.  
  5. ---Y O U T U B E--- video: https://www.youtube.com/watch?v=7xZGikxhSY4
  6.  
  7. My channel, please subscribe: https://www.youtube.com/c/DelfaverMatteo_Games
  8. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  9. ]]--
  10.  
  11. --[[       Variables        ]]--
  12.  
  13. FollowBlockID = 4 -- cobblestone
  14.  
  15. --[[       Functions        ]]--
  16.  
  17.  
  18. function prt(what, types)
  19.     if what == nil then
  20.         print("prt() what is nil")
  21.         return false
  22.     end
  23.    
  24.     if types == nil then
  25.         print("prt() types is nil")
  26.         return false
  27.     end
  28.  
  29.     if types == "debug" then
  30.         Log(what)
  31.         print("Debug: " .. what)
  32.     elseif types == "msg" then
  33.         print(what)
  34.     elseif types == "error" then
  35.         print("ERROR: " .. what)
  36.     end
  37.     return true
  38. end
  39.  
  40. function install()
  41.     if not fs.exists("Database") then
  42.         fs.makeDir("database")
  43.         local file = fs.open("database/road.log", "w")
  44.         file.close()
  45.         return false
  46.     else
  47.         return true
  48.     end
  49. end
  50.  
  51. function Log(what)
  52.     what = tostring(what)
  53.     file = fs.open("database/turtlelog.txt", "a")
  54.     -- file.writeLine(http.get("http://swisspcguru.esy.es/time.php").readAll() .. ": " .. what)
  55.     file.writeLine(what)
  56.     file.close()
  57. end
  58.  
  59. function SaveRoad(what)
  60.     if not fs.exitis("database/road.log") then
  61.         prt("SaveRoad() | database/road.log not fond, start install()", "debug")
  62.         return install()
  63.     else
  64.         prt("SaveRoad() | database/road.log fond, start save road", "debug")
  65.     end
  66. end
  67.  
  68. function fuel()
  69.     fueling = false
  70.     for i = 1, 16 do
  71.       turtle.select(i)
  72.       if turtle.refuel(0) then
  73.         local halfStack = math.ceil(turtle.getItemCount(i)/2)
  74.         if turtle.refuel(halfStack) then fueling = true end
  75.       end
  76.     end
  77.     if fueling then
  78.         prt("fuel() | fueled", "debug")
  79.         return true
  80.     else
  81.         prt("fuel() | not fueled", "debug")
  82.         return false
  83.     end
  84. end
  85.  
  86. function move()
  87.     while FindRoad() do end
  88. end
  89. function FindRoad()
  90.     local success, data = turtle.inspectDown()
  91.     prt(tostring(succes) .. " name: " .. data.name .. " | metadata: " .. data.metadata, "debug")
  92.     if success then
  93.         prt("FindRoad() | success", "debug")
  94.         if data.name == "minecraft:wool" and data.metadata == 14 then
  95.             if turtle.forward() then
  96.                 prt("FindRoad() | turtle.getFuelLevel(): " .. turtle.getFuelLevel(), "debug")
  97.                 if turtle.getFuelLevel() <= 10 then
  98.                     prt("FindRoad() | turtle.getFuelLevel() <= 10" .. turtle.getFuelLevel(), "debug")
  99.                     if fuel() then
  100.                         prt("FindRoad() | fuel() is true", "debug")
  101.                         return FindRoad()
  102.                     else
  103.                         --nem tudott tankolni
  104.                         prt("I don't fueling", "msg")
  105.                         read()
  106.                         return false
  107.                     end
  108.                 end
  109.                 prt("FindRoad() | turtle.forward() true", "debug")
  110.                 success, data = turtle.inspectDown()
  111.                 prt("FindRoad() | turtle.forward() data.name: " .. data.name, "debug")
  112.             else
  113.                 prt("FindRoad() | turtle.forward() false", "debug")
  114.                 if turtle.getFuelLevel() <= 10 then
  115.                     prt("FindRoad() | turtle.getFuelLevel() <= 10" .. turtle.getFuelLevel(), "debug")
  116.                     if fuel() then
  117.                         prt("FindRoad() | fuel() is true", "debug")
  118.                         return FindRoad()
  119.                     else
  120.                         --nem tudott tankolni
  121.                         prt("I don't fueling", "msg")
  122.                         read()
  123.                         return false
  124.                     end
  125.                 else
  126.                     --nem tud mozogni
  127.                     return false
  128.                 end
  129.             end
  130.         else
  131.             if not SearchRoad() then
  132.                 --Road end
  133.                 prt("I found the route end", "msg")
  134.                 read()
  135.                 return
  136.             end
  137.         end
  138.         return true
  139.     else
  140.         return false
  141.         -- Nincs alatta block
  142.     end
  143. end
  144.  
  145. function SearchRoad()
  146.     turtle.back()
  147.     turtle.turnLeft()
  148.     turtle.forward()
  149.     local success, data = turtle.inspectDown()
  150.     prt(tostring(succes) .. " name: " .. data.name .. " | metadata: " .. data.metadata, "debug")
  151.     if success then
  152.         if data.name == "minecraft:wool" and data.metadata == 14 then
  153.             prt("1st search is pass", "debug")
  154.             return FindRoad()
  155.         else
  156.             for i = 1, 2 do
  157.                 turtle.turnLeft()
  158.             end
  159.             turtle.forward()
  160.             local success, data = turtle.inspectDown()
  161.             prt(tostring(succes) .. " name: " .. data.name .. " | metadata: " .. data.metadata, "debug")
  162.             if success then
  163.                 if data.name == "minecraft:wool" and data.metadata == 14 then
  164.                     return FindRoad()
  165.                 else
  166.                     turtle.back()
  167.                     turtle.turnRight()
  168.                     return FindRoad() --loopba visszamegy
  169.                 end
  170.             else
  171.                 --nincs alatta block
  172.             end
  173.         end
  174.     else
  175.         --nincs alatta block
  176.     end
  177. end
  178.  
  179. install()
  180. move()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement