Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- XP Turtle program by DeliciousJaffa
- m = peripheral.wrap("right")
- m.setAutoCollect(true)
- local currLevel = 0
- local booksEnchanted = 0
- local waittext = " - Wait"
- local tstop
- local running = true
- local sx, sy
- local ix, xy
- function checkInv ()
- for s=2,16 do
- if turtle.getItemCount(s) > 0 then
- turtle.select(s)
- if turtle.compareTo(1) == true then
- turtle.transferTo(2)
- else
- turtle.dropDown()
- end
- end
- end
- if turtle.getItemCount(1) > 1 then
- turtle.select(1)
- turtle.transferTo(2, turtle.getItemCount(1) - 1)
- end
- turtle.select(2)
- if turtle.getItemCount(2) > 1 then
- turtle.dropDown(turtle.getItemCount(2) - 1)
- end
- end
- function enchantBook()
- if turtle.getItemCount(2) < 1 then
- turtle.suckDown()
- end
- checkInv()
- turtle.select(2)
- if turtle.compareTo(1) == true then
- if m.enchant(30) then
- booksEnchanted = booksEnchanted + 1
- turtle.dropDown()
- end
- else
- term.setCursorPos(1,sy)
- term.clearLine()
- term.setCursorPos(1,sy)
- write("Out of books.")
- end
- end
- function updatestats()
- currLevel = m.getLevels()
- term.setCursorPos(1,ty)
- term.clearLine()
- term.setCursorPos(1,ty)
- write("Level: " ..currLevel.. " | Books Completed: " ..booksEnchanted)
- end
- function keywait ()
- while not tstop do
- local event,key = os.pullEvent()
- if (event == "char") and (key == "s") then
- running = not running
- write(waittext)
- term.setCursorPos(1,sy)
- term.clearLine()
- term.setCursorPos(1,sy)
- if running then
- m.setAutoCollect(true)
- write("Running")
- else
- m.setAutoCollect(false)
- write("Not running")
- end
- elseif (event == "char") and (key == "q") then
- tstop = true
- end
- end
- end
- function stats ()
- tx,ty = term.getCursorPos()
- while not tstop do
- updatestats()
- sleep(1)
- end
- write(waittext)
- end
- --print(m.getLevels())
- --enchantBook()
- function main ()
- while not tstop do
- currLevel = m.getLevels()
- if running then
- if currLevel >=30 then
- enchantBook()
- else
- term.setCursorPos(1,sy)
- term.clearLine()
- term.setCursorPos(1,sy)
- write("Waiting for level 30")
- sleep(3)
- end
- else
- term.setCursorPos(1,sy)
- term.clearLine()
- term.setCursorPos(1,sy)
- write("Not running")
- sleep(3)
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- turtle.select(1)
- sx,sy = term.getCursorPos()
- print("Starting up")
- print("Press S to stop collecting, Q to quit")
- parallel.waitForAll(stats,keywait,main)
- local mx,my = term.getCursorPos()
- term.setCursorPos((mx - string.len(waittext)),my)
- updatestats()
- print(" \\e/")
Advertisement
Add Comment
Please, Sign In to add comment