Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cls()
- term.clear()
- term.setCursorPos(1,1)
- end
- function fileInstall()
- fs.makeDir("save")
- local posX = 0
- local posY = 0
- local posZ = 0
- local posA = 0
- local gotox = 0
- local gotoy = 0
- local gotoz = 0
- local gotoa = 0
- local file = fs.open("save/goto.cfg", "w")
- file.writeLine("Turtle goto CFG file By Matteo")
- file.writeLine("------------------------------")
- file.writeLine("")
- file.writeLine("[POSITION]")
- file.writeLine("posX = " .. posX)
- file.writeLine("posY = " .. posY)
- file.writeLine("posZ = " .. posZ)
- file.writeLine("face = " .. posA)
- file.writeLine("")
- file.writeLine("[GOTO POSITION]")
- file.writeLine("gotox = " .. gotox)
- file.writeLine("gotoy = " .. gotoy)
- file.writeLine("gotoz = " .. gotoz)
- file.writeLine("gotoa = " .. gotoa)
- file.close()
- end
- function saveData()
- local file = fs.open("save/goto.cfg", "w")
- file.writeLine("Turtle goto CFG file By Matteo")
- file.writeLine("------------------------------")
- file.writeLine("")
- file.writeLine("[POSITION]")
- file.writeLine("posX = " .. posX)
- file.writeLine("posY = " .. posY)
- file.writeLine("posZ = " .. posZ)
- file.writeLine("face = " .. posA)
- file.writeLine("")
- file.writeLine("[GOTO POSITION]")
- file.writeLine("gotox = " .. gotox)
- file.writeLine("gotoy = " .. gotoy)
- file.writeLine("gotoz = " .. gotoz)
- file.writeLine("gotoa = " .. gotoa)
- file.close()
- cls()
- printS2()
- end
- function loadData()
- if fs.exists("save/goto.cfg") then
- local file = fs.open("save/goto.cfg", "r")
- file.readLine()
- file.readLine()
- file.readLine()
- file.readLine()
- lx = file.readLine()
- s1 = lx:find("=")
- posX = tonumber(lx:sub(s1+2))
- ly = file.readLine()
- s1 = ly:find("=")
- posY = tonumber(ly:sub(s1+2))
- lz = file.readLine()
- s1 = lz:find("=")
- posZ = tonumber(lz:sub(s1+2))
- f = file.readLine()
- s1 = f:find("=")
- posA = tonumber(f:sub(s1+2))
- file.readLine()
- file.readLine()
- lxgo = file.readLine()
- s1 = lxgo:find("=")
- gotox = tonumber(lxgo:sub(s1+2))
- lygo = file.readLine()
- s1 = lygo:find("=")
- gotoy = tonumber(lygo:sub(s1+2))
- lzgo = file.readLine()
- s1 = lzgo:find("=")
- gotoz = tonumber(lzgo:sub(s1+2))
- fgo = file.readLine()
- s1 = fgo:find("=")
- gotoa = tonumber(fgo:sub(s1+2))
- file.close()
- else
- posX = "???"
- posY = "???"
- posZ = "???"
- posA = "???"
- cls()
- print("Nincsenek meg a log file-ok.")
- print("Eloszor az install reszt inditsd el.")
- sleep(3)
- end
- end
- -----[[Move functions]]-----
- function Tforward()
- if turtle.forward() then
- if posA == 0 then
- loadData()
- posZ = posZ + 1
- saveData()
- elseif posA == 1 then
- loadData()
- posX = posX - 1
- saveData()
- elseif posA == 2 then
- loadData()
- posZ = posZ - 1
- saveData()
- elseif posA == 3 then
- loadData()
- posX = posX + 1
- saveData()
- end
- else
- turtle.dig()
- turtle.attack()
- sleep(.4)
- return Tforward()
- end
- end
- function Tback()
- if turtle.back() then
- if posA == 0 then
- loadData()
- posZ = posZ - 1
- saveData()
- elseif posA == 1 then
- loadData()
- posX = posX + 1
- saveData()
- elseif posA == 2 then
- loadData()
- posZ = posZ + 1
- saveData()
- elseif posA == 3 then
- loadData()
- posX = posX - 1
- saveData()
- end
- else
- turnL(2)
- turtle.dig()
- turtle.attack()
- turnL(2)
- return Tback()
- end
- end
- function Tup()
- if turtle.up() then
- loadData()
- posY = posY + 1
- saveData()
- else
- turtle.digUp()
- turtle.attackUp()
- return Tup()
- end
- end
- function Tdown()
- if turtle.down() then
- loadData()
- posY = posY - 1
- saveData()
- else
- turtle.digDown()
- turtle.attackDown()
- return Tdown()
- end
- end
- function TturnL()
- if turtle.turnLeft() then
- loadData()
- posA = math.fmod(posA+3, 4)
- saveData()
- end
- end
- function TturnR()
- if turtle.turnRight() then
- loadData()
- posA = math.fmod(posA+1, 4)
- saveData()
- end
- end
- -----[[Steps]]-----
- function forward(forward)
- for i = 1, forward do
- Tforward()
- end
- end
- function back(back)
- for i = 1, back do
- Tback()
- end
- end
- function up(up)
- for i = 1, up do
- Tup()
- end
- end
- function down(down)
- for i = 1, down do
- Tdown()
- end
- end
- function turnL(TL)
- for i = 1, TL do
- TturnL()
- end
- end
- function turnR(TR)
- for i = 1, TR do
- TturnR()
- end
- end
- function printS()
- if fs.exists("save/goto.cfg") == false then
- print("Nincsenek meg a log file-ok.")
- print("Eloszor az install reszt inditsd el.")
- sleep(3)
- return main()
- else
- loadData()
- print("x: " .. posX)
- print("y: " .. posY)
- print("z: " .. posZ)
- print("a: " .. posA)
- end
- end
- function goto(gotox, gotoy, gotoz, gotoa)
- if posX < gotox then -- X
- if posA == 0 then
- turnL(1)
- forward(gotox-posX)
- elseif posA == 1 then
- back(gotox-posX)
- elseif posA == 2 then
- turnR(1)
- forward(gotox-posX)
- elseif posA == 3 then
- forward(gotox-posX)
- end
- elseif posX > gotox then
- if posA == 0 then
- turnL(1)
- back(posX-gotox)
- elseif posA == 1 then
- forward(posX-gotox)
- elseif posA == 2 then
- turnR(1)
- back(posX-gotox)
- elseif posA == 3 then
- back(posX-gotox)
- end
- end
- if posY < gotoy then -- Y
- up(gotoy-posY)
- else
- down(posY-gotoy)
- end
- if posZ < gotoz then -- Z
- if posA == 0 then
- forward(gotoz-posZ)
- elseif posA == 1 then
- turnL(1)
- forward(gotoz-posZ)
- elseif posA == 2 then
- back(gotoz-posZ)
- elseif posA == 3 then
- turnR(1)
- forward(gotoz-posZ)
- end
- elseif posZ > gotoz then
- if posA == 0 then
- back(posZ-gotoz)
- elseif posA == 1 then
- turnL(1)
- back(posZ-gotoz)
- elseif posA == 2 then
- forward(posZ-gotoz)
- elseif posA == 3 then
- turnR(1)
- back(posZ-gotoz)
- end
- end
- local alpha = gotoa-posA+4
- if gotoa == 999 then
- alpha = 0
- end
- if math.fmod(alpha, 4) == 1 then --végső szögbe forgás
- turnR(1)
- elseif math.fmod(alpha, 4) == 2 then
- turnR(2)
- elseif math.fmod(alpha, 4) == 3 then
- turnL(1)
- end
- end
- function printS2()
- loadData()
- term.clear()
- term.setCursorPos(4,2)
- print("x: ")
- term.setCursorPos(4,3)
- print("y: ")
- term.setCursorPos(4,4)
- print("z: ")
- term.setCursorPos(4,5)
- print("a: ")
- term.setCursorPos(4,6)
- print("Start")
- term.setCursorPos(4,7)
- print("Back")
- term.setCursorPos(9,1)
- print("In")
- term.setCursorPos(15,1)
- print("Go")
- term.setCursorPos(4,1)
- print("Pos")
- term.setCursorPos(21,1)
- print("Set")
- term.setCursorPos(9,2)
- print( posX )
- term.setCursorPos(9,3)
- print( posY )
- term.setCursorPos(9,4)
- print( posZ )
- term.setCursorPos(9,5)
- print( posA )
- term.setCursorPos(15,2)
- print( gotox )
- term.setCursorPos(15,3)
- print( gotoy )
- term.setCursorPos(15,4)
- print( gotoz )
- term.setCursorPos(15,5)
- print( gotoa )
- end
- -----[[ Menu ]]-----
- -----[[ Local variables ]]-----
- local termWidth, termHeight = term.getSize()
- local selectedItem = 1
- local inMainMenu = true
- local inGotoMenu = false
- local inWhereMenu = false
- -----[[ Menu Methods ]]----- --Menu
- function Choice1()
- cls()
- inGotoMenu = true
- selectedItem = 1
- while inGotoMenu do
- loadData()
- term.clear()
- term.setCursorPos(9,1)
- print("In")
- term.setCursorPos(15,1)
- print("Go")
- term.setCursorPos(4,1)
- print("Pos")
- term.setCursorPos(21,1)
- print("Set")
- term.setCursorPos(9,2)
- print( posX )
- term.setCursorPos(9,3)
- print( posY )
- term.setCursorPos(9,4)
- print( posZ )
- term.setCursorPos(9,5)
- print( posA )
- term.setCursorPos(15,2)
- print( gotox )
- term.setCursorPos(15,3)
- print( gotoy )
- term.setCursorPos(15,4)
- print( gotoz )
- term.setCursorPos(15,5)
- print( gotoa )
- term.setCursorPos(1,2)
- printMenu(gotoMenu)
- event, key = os.pullEvent("key")
- onKeyPressed(key, gotoMenu)
- end
- end
- function Choice2()
- inWhereMenu = true
- selectedItem = 1
- while inWhereMenu do
- loadData()
- term.clear()
- term.setCursorPos(9,1)
- print("In")
- term.setCursorPos(15,1)
- print("Go")
- term.setCursorPos(4,1)
- print("Pos")
- term.setCursorPos(21,1)
- print("Set")
- term.setCursorPos(9,2)
- print( posX )
- term.setCursorPos(9,3)
- print( posY )
- term.setCursorPos(9,4)
- print( posZ )
- term.setCursorPos(9,5)
- print( posA )
- term.setCursorPos(15,2)
- print( gotox )
- term.setCursorPos(15,3)
- print( gotoy )
- term.setCursorPos(15,4)
- print( gotoz )
- term.setCursorPos(15,5)
- print( gotoa )
- term.setCursorPos(1,2)
- printMenu(whereMenu)
- event, key = os.pullEvent("key")
- onKeyPressed(key, whereMenu)
- end
- end
- function Choice3()
- cls()
- fileInstall()
- print("Log file-ok telepitve")
- sleep(2)
- end
- function Choice4()
- cls()
- printS()
- print("Tovább [ENTER]")
- id, key = os.pullEvent("key")
- if key ~= keys.enter then
- return Choice4()
- end
- end
- function Choice5()
- cls()
- print("Log file-ok torolve")
- if fs.exists("save/goto.cfg") then
- local file = fs.open("save/goto.cfg", "r")
- file.close()
- fs.delete("save")
- print("Log Mappa es file-ok torolve")
- sleep(3)
- end
- end
- function Choice6()
- cls()
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- cls()
- print("Slot ellenőrizve: " .. i )
- print("Uzemanyag szint: " .. turtle.getFuelLevel())
- end
- turtle.select(1)
- end
- function Exit()
- inMainMenu = false
- end
- function Choicex()
- term.setCursorPos(21,2)
- gotox = tonumber(read())
- if gotox == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- if gotox > (posX+100) then
- gotox = posX
- end
- gotox = gotox + 0
- selectedItem = 2
- saveData()
- end
- end
- function Choicey()
- term.setCursorPos(21,3)
- gotoy = tonumber(read())
- if gotoy == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- if gotoy > (posY+100) then
- gotoy = posY
- end
- gotoy = gotoy + 0
- selectedItem = 3
- saveData()
- end
- end
- function Choicez()
- term.setCursorPos(21,4)
- gotoz = tonumber(read())
- if gotoz == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- if gotoz > (posZ+100) then
- gotoz = posZ
- end
- gotoz = gotoz + 0
- selectedItem = 4
- saveData()
- end
- end
- function Choicea()
- term.setCursorPos(21,5)
- gotoa = tonumber(read())
- if gotoa == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- gotoa = math.fmod(gotoa, 4)
- selectedItem = 5
- saveData()
- end
- end
- function Wherex()
- term.setCursorPos(21,2)
- posX = tonumber(read())
- if posX == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- posX = posX + 0
- selectedItem = 2
- saveData()
- end
- end
- function Wherey()
- term.setCursorPos(21,3)
- posY = tonumber(read())
- if posY == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- posY = posY + 0
- selectedItem = 3
- saveData()
- end
- end
- function Wherez()
- term.setCursorPos(21,4)
- posZ = tonumber(read())
- if posZ == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- posZ = posZ + 0
- selectedItem = 4
- saveData()
- end
- end
- function Wherea()
- term.setCursorPos(21,5)
- posA = tonumber(read())
- if posA == nil then
- cls()
- print("Csak szamot lehet megadni!")
- sleep(3)
- else
- posA = math.fmod(posA, 4)
- selectedItem = 5
- saveData()
- end
- end
- function Back()
- selectedItem = 1
- inGotoMenu = false
- inWhereMenu = false
- end
- function Start()
- goto(gotox, gotoy, gotoz, gotoa)
- end
- -----[[ Menu Definitions ]]-----
- mainMenu = {
- [1] = { text = "Goto", handler = Choice1 },
- [2] = { text = "Hol vagyok", handler = Choice4 },
- [3] = { text = "Kalibráció", handler = Choice2 },
- [4] = { text = "Install", handler = Choice3 },
- [5] = { text = "Uninstall", handler = Choice5 },
- [6] = { text = "Tankolás", handler = Choice6 },
- [7] = { text = "Exit", handler = Exit }
- }
- gotoMenu = {
- [1] = { text = "x: ", handler = Choicex },
- [2] = { text = "y: ", handler = Choicey },
- [3] = { text = "z: ", handler = Choicez },
- [4] = { text = "a: ", handler = Choicea },
- [5] = { text = "Start", handler = Start},
- [6] = { text = "Back", handler = Back }
- }
- whereMenu = {
- [1] = { text = "x: ", handler = Wherex },
- [2] = { text = "y: ", handler = Wherey },
- [3] = { text = "z: ", handler = Wherez },
- [4] = { text = "a: ", handler = Wherea },
- [5] = { text = "Back", handler = Back }
- }
- -----[[ Printing Methods ]]-----
- function printMenu(menu)
- for i=1,#menu do
- if i == selectedItem then
- print(">> "..menu[i].text)
- else
- print(" "..menu[i].text)
- end
- end
- end
- -----[[ Handler Methods ]]-----
- function onKeyPressed( key, menu )
- if key == keys.enter then
- onItemSelected(menu)
- elseif key == keys.up then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == keys.down then
- if selectedItem < #menu then
- selectedItem = selectedItem +1
- end
- end
- end
- function onItemSelected(menu)
- menu[selectedItem].handler()
- end
- -----[[ Main Method ]]-----
- function main()
- while inMainMenu do
- cls()
- printMenu(mainMenu)
- event, key = os.pullEvent("key")
- onKeyPressed(key, mainMenu)
- end
- end
- -----[[Main program]]-----
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement