timia2109

TurtleControll

Apr 14th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 30.36 KB | None | 0 0
  1. AppVersion = 3.0
  2. AppName = "TurtleControll"
  3. Slot = 1
  4. cc = 1
  5. paramAlt = 0
  6. SettingPlace = 'TurtleControll.data'
  7. Names4App = {"TC","tc","Controller","turtleer","TurtleCommander","upd8r","u8"}
  8. Apps4Apps = {0,0,0,0,0,'upd8r.lua','upd8r.lua'}
  9.  
  10. CTRLMode = false
  11. Rednet = false
  12.  
  13. if term.isColor() == true then
  14.     term.setBackgroundColor(colors.blue)
  15. end
  16.  
  17. if fs.exists(SettingPlace) == true then
  18.     loadSettings()
  19. else
  20.     Settings = {["Lable"] = 1}
  21. end
  22.  
  23. turtle.select(Slot)
  24. TurtleID = Settings["Lable"]
  25.  
  26. if TurtleID == 1 then
  27.     turtleN = os.getComputerID()
  28. elseif TurtleID == 2 then
  29.     turtleN = os.getComputerLabel()
  30. else
  31.     turtleN = 'turtle'
  32. end
  33.  
  34. function saveSettings()
  35.     file = fs.open(SettingPlace,"w")
  36.     file.write(textutils.serialize(Settings))
  37.     file.close()
  38. end
  39.  
  40. function loadSettings()
  41.     file = fs.open(SettingPlace,"r")
  42.     Settings = textutils.unserialize(file.readAll())
  43.     file.close()
  44. end
  45.  
  46. function rednet()
  47.     while true do
  48.         input = nil
  49.         rednet.open("right")
  50.         local id,message = rednet.receive()
  51.         local input = textutils.unserialize(message)
  52.         if input["checksum"] == AppName then
  53.             if input["mode"] == "key" then
  54.                 doNr(input["do"])
  55.             elseif input["mode"] == "terminal" then
  56.                 terminal(input["do"])
  57.             end
  58.         else
  59.             rednet()
  60.         end
  61.     end
  62. end
  63.    
  64. function makeColor(qwert,trewq)
  65.     if term.isColor() == true then
  66.         if qwert == nil then
  67.             qwert = colors.white
  68.         end
  69.         term.setTextColor(qwert)
  70.         if trewq ~= nil then
  71.             term.setBackgroundColor(trewq)
  72.         end
  73.     end
  74. end
  75.  
  76. function settings()
  77.     term.clear()
  78.     term.setCursorPos(1,1)
  79.     print("The Setting Area are still on developing")
  80.     print()
  81.     print("1 = Name of turtle in Terminal =>", TurtleID)
  82.     print()
  83.     print() -- 5
  84.     print()
  85.     print()
  86.     print()
  87.     print()
  88.     print("e|Exit = exit Settings")
  89.     write("Edit Point = ") --19
  90.     point = read()
  91.     if point == '1' then
  92.         term.clear()
  93.         term.setCursorPos(1,1)
  94.         print("Name of the Turtle in terminal +top +run")
  95.         print("0 = turtle")
  96.         print("1 = ID (",os.getComputerID(),")")
  97.         print("2 = Label (",os.getComputerLabel(),")")
  98.         print()
  99.         print("e = exit settings")
  100.         write("Set to =>") setto = read()
  101.         if setto == 'e' then
  102.             --NIL
  103.         else
  104.             Settings['Lable'] = setto
  105.             saveSettings()
  106.             settings()
  107.         end
  108.     else    end
  109. end    
  110.  
  111. function input(pPre)
  112.     if pPre == nil then
  113.         tInput = nil
  114.         tInput = {}
  115.     else
  116.         tInput = pPre
  117.     end
  118.     local inputString = read()
  119.     for match in string.gmatch(inputString, "(%S+)") do
  120.         table.insert(tInput, match)
  121.     end
  122.     return tInput
  123. end
  124.  
  125. function install()
  126.     a = fs.open("startup","w")
  127.     strings = 'shell.setAlias('
  128.     for i=1,#Names4App do
  129.         x = Names4App[i]
  130.         y = Apps4Apps[i]
  131.         if y == 0 then
  132.             y = 'TurtleControll.lua'
  133.         end
  134.         a.writeLine(strings..'"'..x..'","'..y..'")')
  135.     end
  136.     a.close()
  137.     dev()
  138.     print("installed!")
  139. end
  140.  
  141. function tfBack(Input)
  142.     if Input == "true" or Input == "t" or Input == "1" then
  143.         return true
  144.     elseif Input == "false" or Input == "f" or Input == "0" then
  145.         return false
  146.     else print("Try true or false")
  147.         local qwas = read()
  148.         tfBack(qwas)
  149.     end
  150. end
  151.  
  152. function doNr(param)
  153.     if(param == 200) then turtle.forward() dev() if turtle.detect() then print("Detecting something") end print("Forward") --up
  154.     elseif (param == 208) then turtle.back() dev() print("Backward") --down
  155.     elseif (param == 203) then turtle.turnLeft() dev() print("Turn Left") --left
  156.     elseif (param == 205) then turtle.turnRight() dev() print("Turn Right") --right
  157.     elseif (param == 2) then turtle.place() dev() print("Place Block") --1
  158.     elseif (param == 3) then turtle.dig() dev() print("Dig") --2
  159.     elseif (param == 4) then turtle.attack() dev() print("Attack") --3
  160.     elseif (param == 5) then turtle.craft() dev() print("Craft") --4
  161.     elseif (param == 6) then turtle.drop() dev() print("Drop Items") --5
  162.     elseif (param == 7) then turtle.suck() dev() print("Suck Items") --6
  163.     elseif (param == 8) then turtle.digUp() dev() print("Dig up") --7
  164.     elseif (param == 9) then turtle.digDown() dev() print("Dig Down") --8
  165.     elseif (param == 10) then microTerminal("get") dev() --9
  166.     elseif (param == 11) then microTerminal("put") dev() --0
  167.     elseif (param == 25) then dev() fell(false) --p
  168.     elseif (param == 24) then fell(true) --o
  169.     elseif (param == 23) then --i ist leer
  170.     elseif (param == 25 or param == 157) then if CTRLMode == true then CTRLMode = false dev() else CTRLMode = true dev() end --CTRL L
  171.     elseif (param == 17) then if CTRLMode == true then detect(2) else turtle.up() dev() if turtle.detectUp() then print("Detecting something") end end print("Up") --w
  172.     elseif (param == 31) then if CTRLMode == true then detect(3) else turtle.down() dev() if turtle.detectDown() then print("Detecting something") end end print("Down") --s
  173.     elseif (param == 16) then turtle.placeUp() dev() print("Place Block Up") --q
  174.     elseif (param == 35) then help() --h
  175.     elseif (param == 22) then update() --u
  176.     elseif (param == 48) then microTerminal("BlockPlacer") --b
  177.     elseif (param == 49) then microTerminal("BlockPlacer") --n         
  178.     elseif (param == 38) then microTerminal("ladder") --l
  179.     elseif (param == 33) then microTerminal("field") --f
  180.     elseif (param == keys.r) then makeColor(colors.red) write("App@",turtleN," > ") makeColor() run = read() shell.run(run) dev()--r
  181.     elseif (param == keys.e) then shell.exit() --e
  182.     elseif (param == keys.v) then microTerminal("BlockRemover") dev()
  183.     elseif (param == keys.y) then drop() --y
  184.     elseif (param == keys.x) then suck() --X
  185.     elseif (param == 30) then turtle.placeDown() dev()print("Place Block Down") --a
  186.     elseif (param == 20) then terminal() --t
  187.     elseif (param == keys.d) then write("Go forward to detect") detect(1)
  188.     elseif (param == keys.enter) then turtle.dig() dev() print("Dig") --enter
  189.     elseif (param == 52) then
  190.         if Slot >= 16 then
  191.             dev() print("No more Slots left") --.
  192.         else
  193.             Slot=Slot+1 turtle.select(Slot) dev() print("Now using slot ", Slot) --.
  194.         end
  195.     elseif (param == 51) then if Slot <= 1 then dev() print("No more slots left") --,
  196.         else Slot=Slot-1 dev() turtle.select(Slot) print("Now using slot " ..Slot) end
  197.     end
  198. end
  199.  
  200. function Main()
  201. while true do
  202.     local sEvent, param = os.pullEvent("key")
  203.         if(sEvent == "key") then
  204.             if paramAlt == param then
  205.                 cc = cc+1
  206.                 print(cc," times")
  207.             else
  208.                 if cc ~= 1 then
  209.                     cc = 1
  210.                 end
  211.             end
  212.             paramAlt = param+0
  213.             doNr(param)
  214.         end
  215.     end
  216. end
  217.  
  218. function dev()
  219.     term.clear()
  220.     term.setCursorPos(1,1)
  221.     makeColor()
  222.     print(AppName," AppVersion: ",AppVersion)
  223.     print("Releash ",TimeRel)
  224.     print("action@",turtleN)
  225.     if (CTRLMode == true) then
  226.         makeColor(colors.red)
  227.         print("Detect Mode")
  228.         makeColor()
  229.     else
  230.         makeColor(colors.green)
  231.         print("Normal Mode")
  232.         makeColor()
  233.     end
  234. end
  235.  
  236. function terminalerr(pError,pZw)
  237.     local errors = {
  238.         ["home"] = "home <x> <y> <z>",
  239.         ["goTo"] = "goTo <xTo> <yTo> <zTo> <xNow> <yNow> <zNow>",
  240.         ["rail"] = "rail <lenght> (0 for flat ground) (0 for skipt info)",
  241.         ["gpAlias"] = "gpAlias <Name> <Side = 1|2|3> <ChestNr>",
  242.         ["get"] = "get <Side = 1|2|3> <ChestNr> (<Slot>)",
  243.         ["put"] = "put <Side = 1|2|3> <ChestNr> (<Slot>)",
  244.         ["plant"] = "plant <lenght> <Slot Tree> <Slot Dirt|false>",
  245.         ["fell"] = "fell <lenght>",
  246.         ["SuperMiner"] = "SuperMiner <Dest> (<trochslot or 0>) (<false>)",
  247.         ["buildChest"] = "buildChest <high>",
  248.         ["field"] = "field <lenght> <drop slot 1[true|false]>",
  249.         ["ladder"] = "ladder <deep> <[Number|detect|Slot]> <come back [true|false]",
  250.         ["BlockRemover"] = "BlockRemover <forward> <right> <down>",
  251.         ["BlockPlacer"] = "BlockPlacer <forward> <right> <up>",
  252.         ["MultiField"] = "MultiField <Fields> <Length of field> <Plant [true|false]",
  253.     }
  254.  
  255.     makeColor(colors.red)
  256.     print(errors[pError])
  257.     if pZw == nil then
  258.         makeColor()
  259.         write(pError.." ")
  260.         local temp = input()
  261.         terminal(temp)
  262.     end
  263. end
  264.  
  265. function microTerminal(pOne)
  266.     print("Need more information")
  267.     terminalerr(pOne,0)
  268.     write(pOne.." ")
  269.     terminal(input({pOne}))
  270. end
  271.  
  272. function terminal(preset)
  273.     if preset == nil or preset[1] ~= "more" then
  274.         term.clear()
  275.         term.setCursorPos(1,1)
  276.         write("TurtleControll Terminal")
  277.         term.setCursorPos(1,2)
  278.         makeColor(colors.red)
  279.         write("terminal@",turtleN," > ")
  280.         makeColor()
  281.     end
  282.     if preset == nil then
  283.         local tInput = input()
  284.     else
  285.         local tInput = preset
  286.     end
  287.    
  288.     if tInput[2] == "d" then
  289.         tInput[2] = "detect"
  290.     end
  291.    
  292.     if tInput[1] == 'more' then
  293.         cl()
  294.         write(tInput[2])
  295.         input({tInput[2]})
  296.     end
  297.  
  298.     if (tInput[1] == "forward" or tInput[1] == "f") then
  299.         if (tInput[2] == "detect") then
  300.             if (tInput[3] ~= nil) then
  301.                 detect(1,tonumber(tInput[3]))
  302.             else
  303.                 detect(1)
  304.             end
  305.         else
  306.             a = tonumber(tInput[2])
  307.             while a > 0 do
  308.                 dev(true)
  309.                 print(a," left")
  310.                 turtle.forward() a = a-1
  311.             end
  312.             dev(true)
  313.             print("Finish")
  314.         end
  315.     elseif (tInput[1] == "up" or tInput[1] == "u") then
  316.         if (tInput[2] == "detect") then
  317.             if (tInput[3] ~= nil) then
  318.                 detect(2,tonumber(tInput[3]))
  319.             else
  320.                 detect(2)
  321.             end
  322.         else
  323.             a = tonumber(tInput[2])
  324.             while a > 0 do
  325.                 dev(true)
  326.                 print(a," left")
  327.                 turtle.up() a = a-1
  328.             end
  329.             dev(true)
  330.             print("Finish")
  331.         end
  332.     elseif (tInput[1] == "down" or tInput[1] == "d") then
  333.         if (tInput[2] == "detect") then
  334.             if (tInput[3] ~= nil) then
  335.                 detect(3,tonumber(tInput[3]))
  336.             else
  337.                 detect(3)
  338.             end
  339.         else
  340.             a = tonumber(tInput[2])
  341.             while a > 0 do
  342.                 dev(true)
  343.                 print(a," left")
  344.                 turtle.down() a = a-1
  345.             end
  346.             dev(true)
  347.             print("Finish")
  348.         end
  349.     elseif (tInput[1] == "back" or tInput[1] == "b") then a = tonumber(tInput[2])
  350.         while a > 0 do turtle.back() a = a-1 end
  351.     elseif (tInput[1] == "BlockRemover") then
  352.         if tInput[2] == nil or tInput[3] == nil or tInput[4] == nil then
  353.             terminalerr(BlockRemover)
  354.         else
  355.             BlockRemover.Start(tInput[2],tInput[3],tInput[4])
  356.         end
  357.     elseif (tInput[1] == "BlockPlacer") then
  358.         if tInput[2] == nil or tInput[3] == nil or tInput[4] == nil then
  359.             terminalerr(BlockPlacer)
  360.         else
  361.             BlockPlacer.Start(tInput[2],tInput[3],tInput[4])
  362.         end
  363.     elseif (tInput[1] == 'home') then
  364.         if (tInput[2] == nil or tInput[3] == nil or tInput[4] == nil) then
  365.             terminalerr("home")
  366.         else
  367.             shell.run('Haus.lua '..tInput[2]..' '..tInput[3]..' '..tInput[4])
  368.         end
  369.     elseif (tInput[1] == 'goTo' or tInput[1] == 'go') then
  370.         if (tInput[2] == nil or tInput[3] == nil or tInput[4] == nil or tInput[5] == nil or tInput[6] == nil or tInput[7] == nil) then
  371.             terminalerr("goTo")
  372.         else
  373.             goTo(tInput[2],tInput[3],tInput[4],tInput[5],tInput[6],tInput[7])
  374.         end
  375.     elseif (tInput[1] == "app" or tInput[1] == "run" ) then shell.run(tInput[2])
  376.     elseif (tInput[1] == "train" or tInput[1] == "rail") then
  377.         if tInput[2] == nil then
  378.             terminalerr("rail")
  379.         else
  380.             Train.start(tInput[2],tInput[3],tInput[4])
  381.         end
  382.     elseif (tInput[1] == "help") then help()
  383.     elseif (tInput[1] == "drop") then
  384.         if (tInput[2] ~= nil) then
  385.             drop(tonumber(tInput[2]))
  386.         else
  387.             drop()
  388.         end
  389.     elseif tInput[1] == "gpAlias" then
  390.         if (tInput[2] == nil or tInput[3] == nil or tInput[4]) then
  391.             terminalerr("gpAlias")
  392.         else
  393.             Settings["ChestSide"..tInput[2]] = tInput[3]
  394.             Settings["ChestNr"..tInput[2]] = tInput[4]
  395.             saveSettings()
  396.         end
  397.     elseif tInput[1] == "get" then
  398.         if in_table("ChestSide"..tInput[2],Settings) == true then
  399.             local temp = tInput[2]
  400.             local sslot = tInput[3]
  401.             tInput[2] = Settings["ChestSide"..temp]
  402.             tInput[3] = Settings["ChestNr"..temp]
  403.             tInput[4] = sslot
  404.         end
  405.         if (tInput[2] == nil or tInput[3] == nil) then
  406.             terminalerr("get")
  407.         else
  408.             ChestFkt.go(tInput[3],tInput[2])
  409.             suck(tonumber(tInput[4]))
  410.             ChestFkt.goBack(tInput[2])
  411.             dev()
  412.         end
  413.     elseif tInput[1] == "put" then
  414.         if in_table("ChestSide"..tInput[2],Settings) == true then
  415.             local temp = tInput[2]
  416.             local sslot = tInput[3]
  417.             tInput[2] = Settings["ChestSide"..temp]
  418.             tInput[3] = Settings["ChestNr"..temp]
  419.             tInput[4] = sslot
  420.         end
  421.         if (tInput[2] == nil or tInput[3] == nil) then
  422.             terminalerr("put")
  423.         else
  424.             ChestFkt.go(tInput[3],tInput[2])
  425.             drop(tonumber(tInput[4]),0)
  426.             ChestFkt.goBack(tInput[2])
  427.             dev()
  428.         end
  429.     elseif tInput[1] == "upd8r" then
  430.         shell.setDir("/")
  431.         print("GET UPD8R")
  432.         a = http.get("http://tinyurl.com/upd8r")
  433.         a = a.readAll()
  434.         b = fs.open("upd8r.lua","w")
  435.         b.write(a)
  436.         b.close()
  437.         shell.run("upd8r.lua")
  438.     elseif tInput[1] == "buildChest" then
  439.         if (tInput[2] == nil) then
  440.             terminalerr("buildChest")
  441.         else
  442.             ChestFkt.build(tonumber(tInput[2]))
  443.         end
  444.     elseif (tInput[1] == "exit" or tInput[1] == "e") then
  445.         dev() print("Terminal closed") tInput = nil
  446.     elseif (tInput[1] == "nTr" or tInput[1] == "plant") then
  447.         if (tInput[2] == nil or tInput[3] == nil or tInput[4] == nil) then
  448.             terminalerr("plant")
  449.         else
  450.             placeTrees(tInput[2],tInput[3],tInput[4])
  451.         end
  452.     elseif (tInput[1] == "settings") then settings()
  453.     elseif (tInput[1] == "field") then
  454.         if (tInput[2] == nil) then
  455.             terminalerr("field")
  456.         else
  457.             Feld(tInput[2],tInput[3])
  458.         end
  459.     elseif (tInput[1] == "SuperMiner" or tInput[1] == "sm") then
  460.         if (tInput[2] == nil) then
  461.             terminalerr("SuperMiner")
  462.         else
  463.             SuperMiner(tInput[2],tInput[3],tInput[4])
  464.         end
  465.     elseif (tInput[1] == "fell" or tInput[1] == "gTr") then
  466.         if (tInput[2] == nil) then
  467.             terminalerr("fell")
  468.         else         
  469.             automaticTrees(tInput[2])
  470.         end
  471.     elseif (tInput[1] == "install") then
  472.         install()
  473.     elseif (tInput[1] == "MultiField" or "mf") then
  474.         if (tInput[2] == nil or tInput[3] == nil or tInput[4] == nil) then
  475.             terminalerr("MultiField")
  476.         else
  477.             MultiField(tInput[2],tInput[3],tInput[4])
  478.         end
  479.     else
  480.         print("Not given") sleep(1) terminal()
  481.     end
  482. end
  483.  
  484. function in_table(element,table)
  485.   for _, value in pairs(table) do
  486.     if value == element then
  487.       return true
  488.     end
  489.   end
  490.   return false
  491. end
  492.  
  493. function detect(where,max) --Where[1 detect,2 detect up, 3 detect down]
  494.     goThrow = 0
  495.     going = true
  496.     if where == 1 then
  497.         while turtle.detect() == false and going == true do
  498.             turtle.forward()
  499.             goThrow = goThrow+1
  500.             if max ~= nil then
  501.                 if max == goThrow then
  502.                     going = false
  503.                 end
  504.             end
  505.             dev(false)
  506.             makeColor(colors.red)
  507.             print("Go ",goThrow," steps now")
  508.             makeColor()
  509.         end
  510.         makeColor(colors.green)
  511.         print("Finish")
  512.         makeColor(colors.green)
  513.     elseif where == 2 then
  514.         while turtle.detectUp() == false and going == true do
  515.             turtle.up()
  516.             goThrow = goThrow+1
  517.             if max ~= nil then
  518.                 if max == goThrow then
  519.                     going = false
  520.                 end
  521.             end
  522.             dev(false)
  523.             makeColor(colors.red)
  524.             print("Go ",goThrow," steps now")
  525.             makeColor()
  526.         end
  527.         makeColor(colors.green)
  528.         print("Finish")
  529.         makeColor()
  530.     elseif where == 3 then
  531.         while turtle.detectDown() == false and going == true do
  532.             turtle.down()
  533.             goThrow = goThrow+1
  534.             if max ~= nil then
  535.                 if max == goThrow then
  536.                     going = false
  537.                 end
  538.             end
  539.             dev(false)
  540.             makeColor(colors.red)
  541.             print("Go ",goThrow," steps now")
  542.             makeColor()
  543.         end
  544.         dev()
  545.         makeColor(colors.green)
  546.         print("Finish")
  547.         makeColor()
  548.     end
  549. end
  550.  
  551. function checkDown(xxx)
  552.     if turtle.detectDown() == true then
  553.         drop(xxx)
  554.     end
  555. end
  556.  
  557. function SuperMiner(dest,ptorch,run)
  558.     if ptorch ~= nil and ptorch ~= 0 then
  559.         torch = true
  560.         tS = tonumber(ptorch)
  561.     else
  562.         torch = false
  563.     end
  564.     if run ~= nil then
  565.         dig = false
  566.     else
  567.         dig = true
  568.     end
  569.     dist = tonumber(dest)
  570.     count = 0
  571.  
  572.     if dig == true then
  573.         while dist > 0 do
  574.             turtle.dig()
  575.             turtle.forward()
  576.             turtle.digDown()
  577.             turtle.turnLeft()
  578.             turtle.dig()
  579.             turtle.forward()
  580.             turtle.digDown()
  581.             turtle.turnRight()
  582.             dist = dist-1
  583.             if count == 3 and torch == true then
  584.                 turtle.select(tS)
  585.                 turtle.placeDown()
  586.             end
  587.             count = count+1
  588.             dev()
  589.             print(dist.." left")
  590.         end
  591.     else
  592.         while dist > 0 do
  593.             turtle.forward()
  594.             turtle.turnRight()
  595.             turtle.forward()
  596.             turtle.turnLeft()
  597.             dist = dist-1
  598.             dev()
  599.             print(dist.." left")
  600.         end
  601.     end
  602.     dev()
  603.     makeColor(colors.green)
  604.     print("Finish!")
  605.     makeColor()
  606. end
  607.  
  608. function fell(tf)
  609.     if tf == false then
  610.         a = 0
  611.         b = 0
  612.     elseif tf == true then
  613.         b = 0
  614.         makeColor(colors.green)
  615.         print("Last tree high = ",a)
  616.         makeColor()
  617.     end
  618.     makeColor(colors.red)
  619.     print("Wait..:")
  620.     print("Tree is felling....")
  621.     if tf == false then
  622.         turtle.dig()
  623.         turtle.forward()
  624.         while turtle.detectUp() do
  625.             turtle.digUp()
  626.             turtle.up()
  627.             a = a+1
  628.             b = b+1
  629.         end
  630.         while b > 0 do
  631.             turtle.down()
  632.             b = b-1
  633.         end
  634.     elseif tf == true then
  635.         while a > 0 do
  636.             if turtle.detectUp() then
  637.                 turtle.digUp()
  638.             end
  639.             turtle.up()
  640.             if turtle.detect() then
  641.                 turtle.dig()
  642.                 turtle.turnLeft()
  643.                 turtle.dig()
  644.                 turtle.turnLeft()
  645.                 turtle.dig()
  646.                 turtle.turnLeft()
  647.                 turtle.dig()
  648.                 turtle.turnLeft()
  649.             end
  650.             a = a-1
  651.             b = b+1
  652.         end
  653.         while b > 0 do
  654.             turtle.down()
  655.             b = b-1
  656.         end
  657.     end
  658.     dev()
  659.     makeColor(colors.green)
  660.     print("Tree high = ",a)
  661.     print("Finish!")
  662.     makeColor()
  663. end
  664.  
  665. function placeTrees(pX,pSlot,pDirt)
  666.     dirt = true
  667.     slot = tonumber(pSlot)
  668.     if dirtslot == 'false' then
  669.         dirt = false
  670.     else
  671.         dirt = tonumber(pDirt)
  672.     end
  673.  
  674.     a = pX*5
  675.     b = a+0
  676.     c = 4
  677.     while a > 0 do
  678.       turtle.forward()
  679.         if turtle.detect() == true then
  680.             turtle.dig()
  681.         end
  682.       c = c+1
  683.       if c == 5 then
  684.         turtle.down()
  685.         if turtle.detectDown() == false then
  686.             if dirt == true then
  687.                 turtle.select(dirtslot)
  688.                 turtle.placeDown()
  689.                 turtle.select(slot)
  690.             end
  691.         end
  692.         turtle.up()
  693.         turtle.placeDown()
  694.         c = 0
  695.       end
  696.       a = a-1
  697.     end
  698.  
  699.     while b > 0 do
  700.       turtle.back()
  701.       b = b-1
  702.     end
  703.     dev()
  704.     makeColor(colors.green)
  705.     print("Finish!")
  706.     makeColor()
  707. end
  708.  
  709. function automaticTrees(pX)
  710.     x = pX*5
  711.     y = x+0
  712.     while x > 0 do
  713.         turtle.forward()
  714.         if turtle.detect() == true then
  715.             fell(false)
  716.             x = x-1
  717.         end
  718.         x = x-1
  719.     end
  720.    
  721.     while y > 0 do turtle.back() y=y-1 end
  722.     dev()
  723.     makeColor(colors.green)
  724.     print("All trees are fell!")
  725.     makeColor()
  726. end
  727.  
  728. function drop(tfxx,tfg)
  729.     if tfxx ~= nil then
  730.         turtle.select(tfxx)
  731.         if tfg == nil then
  732.             turtle.dropDown()
  733.         else
  734.             turtle.drop()
  735.         end
  736.     else
  737.         tfxx = 1
  738.         while tfxx <= 16 do
  739.             turtle.select(tfxx)
  740.             if tfg == nil then
  741.                 turtle.dropDown()
  742.             else
  743.                 turtle.drop()
  744.             end
  745.             tfxx = tfxx+1
  746.         end
  747.     end
  748.     turtle.select(1)
  749. end
  750.  
  751. function suck(tfxx)
  752.     if tfxx ~= nil then
  753.         turtle.select(tfxx)
  754.         turtle.suck()
  755.     else
  756.         tfxx = 1
  757.         while tfxx <= 16 do
  758.             turtle.select(tfxx)
  759.             turtle.suck()
  760.             tfxx = tfxx+1
  761.         end
  762.     end
  763.     turtle.select(1)
  764. end
  765.  
  766. function MultiField(pAnz,pLenght,pPlant)
  767.     local x = pAnz+0
  768.     local going = (pAnz*3)-3
  769.     while pAnz > 0 do
  770.         Feld(pLenght,pPlant)
  771.         turtle.turnRight()
  772.         local fw = 3
  773.         while fw > 0 do
  774.             turtle.forward()
  775.             fw = fw-1
  776.         end
  777.         turtle.turnLeft()
  778.         anz = anz-1
  779.     end
  780.     turtle.turnLeft()
  781.     turtle.turnLeft()
  782.     while going > 0 do
  783.         turtle.forward()
  784.         going = going-1
  785.     end
  786.     dev()
  787.     makeColor()
  788.     print("Finish!")
  789.     makeColor()
  790. end
  791.  
  792. function Feld(pLenght,pPlant)
  793.     dev()
  794.     makeColor(colors.red)
  795.     print("Working...")
  796.     makeColor()
  797.     a = pLenght
  798.     b = a+0
  799.     a = tonumber(a)
  800.     tf = tfBack(pPlant)
  801.     turtle.forward()
  802.     while a > 0 do
  803.         turtle.digDown()
  804.         if tf == true then turtle.placeDown() end
  805.             turtle.turnRight()
  806.             turtle.forward()
  807.             turtle.digDown()
  808.         if tf == true then turtle.placeDown() end
  809.             turtle.back()
  810.             turtle.turnLeft()
  811.             turtle.forward()
  812.             a = a-1
  813.     end
  814.     turtle.turnRight()
  815.     turtle.turnRight()
  816.     while b > 0 do
  817.         turtle.forward()
  818.         b = b-1
  819.     end
  820.     turtle.turnRight()
  821.     turtle.turnRight()
  822.     turtle.back()
  823.     checkDown(2)
  824.     dev()
  825.     makeColor(colors.green)
  826.     print("Finish!")
  827.     makeColor()
  828. end
  829.  
  830. function update()
  831.     if fs.exists("upd8r.lua") == true then
  832.         shell.run("upd8r.lua")
  833.         shell.run("TurtleControll.lua")
  834.         shell.exit()
  835.     else
  836.         a = http.get("http://goo.gl/7gUVmb")
  837.         b = fs.open(shell.getRunningProgram(),"w")
  838.         b.write(a.readAll())
  839.         b.close()
  840.         shell.run(shell.getRunningProgram())
  841.     end
  842. end
  843.  
  844. function goTo( x, y, z, xPos, depth, zPos)
  845.     while depth > y do
  846.         if turtle.up() then
  847.             depth = depth - 1
  848.         elseif turtle.digUp() or turtle.attackUp() then
  849.            
  850.         else
  851.             sleep( 0.5 )
  852.         end
  853.     end
  854.  
  855.     if xPos > x then
  856.         while xDir ~= -1 do
  857.             turtle.turnLeft()
  858.         end
  859.         while xPos > x do
  860.             if turtle.forward() then
  861.                 xPos = xPos - 1
  862.             elseif turtle.dig() or turtle.attack() then
  863.                
  864.             else
  865.                 sleep( 0.5 )
  866.             end
  867.         end
  868.     elseif xPos < x then
  869.         while xDir ~= 1 do
  870.             turtle.turnLeft()
  871.         end
  872.         while xPos < x do
  873.             if turtle.forward() then
  874.                 xPos = xPos + 1
  875.             elseif turtle.dig() or turtle.attack() then
  876.                
  877.             else
  878.                 sleep( 0.5 )
  879.             end
  880.         end
  881.     end
  882.    
  883.     if zPos > z then
  884.         while zDir ~= -1 do
  885.             turtle.turnLeft()
  886.         end
  887.         while zPos > z do
  888.             if turtle.forward() then
  889.                 zPos = zPos - 1
  890.             elseif turtle.dig() or turtle.attack() then
  891.                
  892.             else
  893.                 sleep( 0.5 )
  894.             end
  895.         end
  896.     elseif zPos < z then
  897.         while zDir ~= 1 do
  898.             turtle.turnLeft()
  899.         end
  900.         while zPos < z do
  901.             if turtle.forward() then
  902.                 zPos = zPos + 1
  903.             elseif turtle.dig() or turtle.attack() then
  904.                
  905.             else
  906.                 sleep( 0.5 )
  907.             end
  908.         end
  909.     end
  910.    
  911.     while depth < y do
  912.         if turtle.down() then
  913.             depth = depth + 1
  914.         elseif turtle.digDown() or turtle.attackDown() then
  915.            
  916.         else
  917.             sleep( 0.5 )
  918.         end
  919.     end
  920.     makeColor(colors.green)
  921.     print("Finish!")
  922.     makeColor()
  923. end
  924.  
  925. function leiterBuilder(pDeep,pSlot,pBack)
  926.     a = read(pDeep)
  927.     Slot = tonumber(pSlot)
  928.     turtle.select(Slot)
  929.     qwas = tfBack(pBack)
  930.     b = 0
  931.     if a == "detect" then
  932.         while not turtle.detectDown() do
  933.             turtle.place()
  934.             turtle.down()
  935.             b = b+1
  936.         end
  937.         if tfBack(qwas) then
  938.             while b > 0 do
  939.                 turtle.up()
  940.                 b = b-1
  941.             end
  942.         end
  943.         Main()
  944.     elseif a == "Slot" then
  945.         a = turtle.getItemCount(Slot)
  946.     else
  947.         a = tonumber(a)
  948.     end
  949.     while a > 0 do
  950.         turtle.place()
  951.         turtle.down()
  952.         a = a-1
  953.         b = b+1
  954.     end
  955.     if tfBack(qwas) == true then
  956.         while b > 0 do
  957.             turtle.up()
  958.             b = b-1
  959.         end
  960.     end
  961.     dev()
  962.     makeColor(colors.green)
  963.     print("Finish!")
  964.     makeColor()
  965. end
  966.  
  967. BlockPlacer = {
  968.     Start=function(pForward,pRight,pDown)
  969.         dev()
  970.         xSide = tonumber(pForward)
  971.         ySide = tonumber(pRight)
  972.         zSide = tonumber(pDown)
  973.         a = xSide+0
  974.         b = ySide+0
  975.         c = zSide+0
  976.         Comp = xSide*ySide*zSide
  977.         CompSLot = Comp/64
  978.         print("That's are ",Comp," Blocks. ")
  979.         print("Put Material in Slot 1 - 16 (Need "..CompSLot.."Slots")
  980.         print("press enter to start...")
  981.         while true do local sEvent, param = os.pullEvent("key")
  982.             if(sEvent == "key") then
  983.                 if (param == 28) then
  984.                     BlockPlacer.remove()
  985.                     break
  986.                 end
  987.             end
  988.         end
  989.         dev()
  990.         makeColor(colors.green)
  991.         print("Finish!")
  992.         makeColor()
  993.         Main()
  994.     end,
  995.    
  996.     Status=function()
  997.         term.clear()
  998.         term.setCursorPos(1,1)
  999.         print("Print...")
  1000.         print("X = ",xTemp)
  1001.         print("Y = ",yTemp)
  1002.         print("Z = ",zTemp)
  1003.         term.setCursorPos(1,5)
  1004.         print("I have ",MathTemp," blocks / "..Comp)
  1005.         jhf = Comp-MathTemp
  1006.         hfj = (MathTemp*100)/Comp
  1007.         print(jhf," blocks left")
  1008.         print(hfj,"%")
  1009.         ChestFkt.checkSlots()
  1010.         print("Slot = "..Slot)
  1011.         jhf = nil
  1012.         hfj = nil
  1013.     end,
  1014.        
  1015.     remove=function()
  1016.         print("Please wait...")
  1017.         aTemp = a+0
  1018.         bTemp = b+0
  1019.         cTemp = c+0
  1020.         xTemp = 1
  1021.         yTemp = 1
  1022.         zTemp = c+0
  1023.         MathTemp = 0
  1024.         while cTemp > 0 do
  1025.             while aTemp > 0 do
  1026.                 turtle.turnRight()
  1027.                 while bTemp > 0 do
  1028.                     ChestFkt.checkSlots()
  1029.                     turtle.placeDown()
  1030.                     MathTemp = MathTemp+1
  1031.                     BlockPlacer.Status()
  1032.                     if bTemp > 1 then
  1033.                         if turtle.detect() then turtle.dig() end
  1034.                         turtle.forward()
  1035.                         xTemp = xTemp+1
  1036.                     end
  1037.                     bTemp = bTemp-1
  1038.                 end
  1039.                 bTemp = b+0
  1040.                 while bTemp > 1 do
  1041.                     turtle.back()
  1042.                     bTemp = bTemp-1
  1043.                     xTemp = xTemp-1
  1044.                 end
  1045.                 bTemp = b+0
  1046.                 turtle.turnLeft()
  1047.                 if aTemp > 1 then
  1048.                     if turtle.detect() then turtle.dig() end
  1049.                     turtle.forward()
  1050.                     yTemp = yTemp+1
  1051.                 end
  1052.                 aTemp = aTemp-1
  1053.             end
  1054.             aTemp = a+0
  1055.             while aTemp > 1 do
  1056.                 turtle.back()
  1057.                 aTemp = aTemp-1
  1058.                 yTemp = yTemp-1
  1059.             end
  1060.             if cTemp > 1 then
  1061.                 turtle.up()
  1062.                 zTemp = zTemp-1
  1063.                 xTemp = 1
  1064.                 yTemp = 1
  1065.             end
  1066.             cTemp = cTemp-1
  1067.             aTemp = a+0
  1068.             bTemp = b+0
  1069.         end
  1070.         cTemp = c+0
  1071.         while cTemp > 0 do
  1072.             if cTemp > 1 then
  1073.                 turtle.up()
  1074.             end
  1075.             cTemp = cTemp-1
  1076.         end
  1077.     end,
  1078. }
  1079.  
  1080. ChestFkt = {
  1081.     checkSlots = function()
  1082.         if turtle.getItemCount(Slot) <= 0 then
  1083.             if Slot <= 16 then
  1084.                 Slot = Slot+1
  1085.                 turtle.select(Slot)
  1086.             end
  1087.         end
  1088.     end,
  1089.     build=function(aIn)
  1090.         print("High of the Tower/Chests")
  1091.         a = aIn
  1092.         b = a+0
  1093.         print("Build Blocks in Slots 1-8")
  1094.         print("Chests in Slot 9-16")
  1095.         print("Press enter to start|Type e or exit for end")
  1096.         xyz = read()
  1097.         if (xyz == 'e' or xyz == 'exit') then
  1098.             dev()
  1099.         else
  1100.             shell.run("Haus.lua 6 6 "..a.." go")
  1101.             Slot = 9
  1102.             turtle.select(Slot)
  1103.             turtle.turnRight()
  1104.             turtle.forward()
  1105.             turtle.forward()
  1106.             turtle.turnLeft()
  1107.             turtle.dig()
  1108.             turtle.up()
  1109.             turtle.dig()
  1110.             turtle.down()
  1111.             turtle.forward()
  1112.             turtle.forward()
  1113.             turtle.forward()
  1114.             turtle.turnLeft()
  1115.             while a > 0 do
  1116.                 turtle.place()
  1117.                 ChestFkt.checkSlots()
  1118.                 turtle.up()
  1119.                 a = a-1
  1120.             end
  1121.             turtle.turnRight()
  1122.             turtle.forward()
  1123.             turtle.turnLeft()
  1124.             while b > 0 do
  1125.                 ChestFkt.checkSlots()
  1126.                 turtle.place()
  1127.                 turtle.down()
  1128.                 b = b-1
  1129.             end
  1130.             turtle.turnRight()
  1131.             while a > 0 do
  1132.                 ChestFkt.checkSlots()
  1133.                 turtle.place()
  1134.                 turtle.up()
  1135.                 a = a-1
  1136.             end
  1137.             turtle.turnRight()
  1138.             turtle.forward()
  1139.             turtle.turnLeft()
  1140.             while b > 0 do
  1141.                 ChestFkt.checkSlots()
  1142.                 turtle.place()
  1143.                 turtle.down()
  1144.                 b = b-1
  1145.             end
  1146.             turtle.turnRight()
  1147.             turtle.forward()
  1148.             while a > 0 do
  1149.                 ChestFkt.checkSlots()
  1150.                 turtle.place()
  1151.                 turtle.up()
  1152.                 a = a-1
  1153.             end
  1154.             turtle.turnRight()
  1155.             turtle.forward()
  1156.             turtle.turnLeft()
  1157.             while b > 0 do
  1158.                 ChestFkt.checkSlots()
  1159.                 turtle.place()
  1160.                 turtle.down()
  1161.                 b = b-1
  1162.             end
  1163.             turtle.back()
  1164.             turtle.turnLeft()
  1165.         end
  1166.     end,
  1167.  
  1168.     go=function(chest,side)
  1169.         temp = 0
  1170.         if side == '1' then
  1171.             turtle.turnLeft()
  1172.         elseif side == '2' then
  1173.             turtle.forward()
  1174.         elseif side == '3' then
  1175.             turtle.turnRight()
  1176.             turtle.forward()
  1177.         end
  1178.         chest = chest-1
  1179.         while chest > 0 do
  1180.             turtle.up()
  1181.             chest = chest-1
  1182.             temp = temp+1
  1183.         end
  1184.     end,
  1185.  
  1186.     goBack=function(side)
  1187.         while temp > 0 do
  1188.             turtle.down()
  1189.             temp = temp-1
  1190.         end
  1191.         if side == '1' then
  1192.             turtle.turnRight()
  1193.         elseif side == '2' then
  1194.             turtle.back()
  1195.         elseif side == '3' then
  1196.             turtle.back()      
  1197.             turtle.turnLeft()
  1198.         end
  1199.     end,
  1200. }
  1201.  
  1202. BlockRemover = {
  1203.     Start=function(pForward,pRight,pDown)
  1204.         term.clear()
  1205.         term.setCursorPos(1,1)
  1206.         local back = true
  1207.         xSide = tonumber(pForward)
  1208.         ySide = tonumber(pRight)
  1209.         zSide = tonumber(pDown)
  1210.         a = xSide+0
  1211.         b = ySide+0
  1212.         c = zSide+0
  1213.         Comp = xSide*ySide*zSide
  1214.         print("That's are ",Comp," Blocks. ")
  1215.         print("press enter to start...")
  1216.         while true do local sEvent, param = os.pullEvent("key")
  1217.             if(sEvent == "key") then
  1218.                 if (param == 28) then
  1219.                     BlockRemover.remove()
  1220.                     break
  1221.                 end
  1222.             end
  1223.         end
  1224.         dev()
  1225.         makeColor(colors.green)
  1226.         print("Finish!")
  1227.         makeColor()
  1228.         Main()
  1229.     end,
  1230.    
  1231.     Status=function()
  1232.         term.clear()
  1233.         term.setCursorPos(1,1)
  1234.         print("Scanning...")
  1235.         print("X = ",xTemp)
  1236.         print("Y = ",yTemp)
  1237.         print("Z = ",zTemp)
  1238.         term.setCursorPos(1,5)
  1239.         print("I have ",MathTemp," blocks")
  1240.         jhf = Comp-MathTemp
  1241.         hfj = (MathTemp*100)/Comp
  1242.         print(jhf," blocks left")
  1243.         print(hfj,"%")
  1244.         jhf = nil
  1245.         hfj = nil
  1246.     end,
  1247.        
  1248.     remove=function()
  1249.         print("Please wait...")
  1250.         aTemp = a+0
  1251.         bTemp = b+0
  1252.         cTemp = c+0
  1253.         xTemp = 1
  1254.         yTemp = 1
  1255.         zTemp = c+0
  1256.         MathTemp = 0
  1257.         while cTemp > 0 do
  1258.             while aTemp > 0 do
  1259.                 turtle.turnRight()
  1260.                 while bTemp > 0 do
  1261.                     turtle.digDown()
  1262.                     MathTemp = MathTemp+1
  1263.                     BlockRemover.Status()
  1264.                     if bTemp > 1 then
  1265.                         if turtle.detect() then turtle.dig() end
  1266.                         turtle.forward()
  1267.                         xTemp = xTemp+1
  1268.                     end
  1269.                     bTemp = bTemp-1
  1270.                 end
  1271.                 bTemp = b+0
  1272.                 while bTemp > 1 do
  1273.                     turtle.back()
  1274.                     bTemp = bTemp-1
  1275.                     xTemp = xTemp-1
  1276.                 end
  1277.                 bTemp = b+0
  1278.                 turtle.turnLeft()
  1279.                 if aTemp > 1 then
  1280.                     if turtle.detect() then turtle.dig() end
  1281.                     turtle.forward()
  1282.                     yTemp = yTemp+1
  1283.                 end
  1284.                 aTemp = aTemp-1
  1285.             end
  1286.             aTemp = a+0
  1287.             while aTemp > 1 do
  1288.                 turtle.back()
  1289.                 aTemp = aTemp-1
  1290.                 yTemp = yTemp-1
  1291.             end
  1292.             if cTemp > 1 then
  1293.                 turtle.down()
  1294.                 zTemp = zTemp-1
  1295.                 xTemp = 1
  1296.                 yTemp = 1
  1297.             end
  1298.             cTemp = cTemp-1
  1299.             aTemp = a+0
  1300.             bTemp = b+0
  1301.         end
  1302.         if back == true then
  1303.             cTemp = c+0
  1304.             while cTemp > 0 do
  1305.                 if cTemp > 1 then
  1306.                     turtle.up()
  1307.                 end
  1308.                 cTemp = cTemp-1
  1309.             end
  1310.         end
  1311.     end,
  1312. }
  1313.  
  1314. Train = {
  1315.     ["Slots"] = {
  1316.     [1] = 'Rails',
  1317.     [2] = 1, [3] = 1, [4] = 1, [5] = 1, [6] = 1,[7] = 1, "Dirt",8,8,8,8,8,8,
  1318.     [12] = "Motor Rail",[13] = 12, [14] = 12,
  1319.     [15] = "Redstone Torch",[16] = 15,
  1320.     },
  1321.  
  1322.     CheckSlot=function(y)
  1323.         while turtle.getItemCount(Slot) == 0 do
  1324.             if Slot+1 > y then
  1325.                 print("Out of Material")
  1326.                 a = 0
  1327.             else
  1328.                 Slot = Slot+1
  1329.                 Train.sel()
  1330.             end
  1331.         end
  1332.     end,
  1333.    
  1334.     status=function()
  1335.         term.clear()
  1336.         term.setCursorPos(1,1)
  1337.         print("a =",a)
  1338.         print("temp =",temp)
  1339.     end,
  1340.    
  1341.     speed=function()
  1342.         if temp == Detectby then
  1343.             Slot = 15
  1344.             Train.sel()
  1345.             Train.CheckSlot(16)
  1346.         elseif temp == Detectby+1 or temp == Detectby+2 then
  1347.             Slot = 12
  1348.             Train.sel()
  1349.             Train.CheckSlot(14)
  1350.         elseif temp == Detectby+3 then
  1351.             Slot = 15
  1352.             Train.sel()
  1353.             Train.CheckSlot(16)
  1354.             temp = 0
  1355.         else
  1356.             Slot = 1
  1357.             Train.sel()
  1358.             Train.CheckSlot(7)
  1359.         end
  1360.     end,
  1361.        
  1362.     sel=function()
  1363.         turtle.select(Slot)
  1364.     end,
  1365.        
  1366.     start=function(lenght,flat,maybe)
  1367.         Detectby = 10
  1368.         temp = 0
  1369.         a = lenght
  1370.         if flat ~= nil and flat ~= '1' then
  1371.             CheckGround = false
  1372.         else
  1373.             CheckGround = true
  1374.         end
  1375.         if maybe ~= nil then
  1376.             for i=1,#Train["Slots"] do
  1377.                 print("Slot:",i,"=",Slots[i])
  1378.             end
  1379.             print("e for exit|t or f for follow rails")
  1380.             a = read()
  1381.         end
  1382.         if a == "e" then
  1383.             shell.exit()
  1384.         elseif a == "t" or a == "f" then
  1385.             a = 0
  1386.             while turtle.detectDown() == true do
  1387.                 turtle.forward()
  1388.                 a = a+1
  1389.                 Train.status()
  1390.             end
  1391.         else
  1392.             a = tonumber(lenght)
  1393.             while a > 0 do
  1394.                 if CheckGround == true then
  1395.                     turtle.down()
  1396.                     if turtle.detectDown() == false then
  1397.                         Slot = 8
  1398.                         Train.sel()
  1399.                         Train.CheckSlot(11)
  1400.                         turtle.placeDown()
  1401.                     end
  1402.                     turtle.up()
  1403.                 end
  1404.                 Train.speed()
  1405.                 turtle.placeDown()
  1406.                 turtle.forward()
  1407.                 a = a-1
  1408.                 temp = temp+1
  1409.                 Train.status()
  1410.             end
  1411.         end
  1412.     end, }
  1413.  
  1414. dev()
  1415. Main()
Add Comment
Please, Sign In to add comment