Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Jaffa's attack turtle program
- -- Version: 1.0.1.0
- local hits = 0
- local tries = 0
- local movemode = false
- local moveallowed = false
- local tstop
- local ignoredkeys = {["2"]=true, ["5"]=true, ["8"]=true}
- local waittext = " - Wait"
- local args = { ... }
- if args[1] == "movemodeon" then movemode = true end
- if movemode == true then
- local tx, ty = term.getCursorPos()
- term.setCursorPos(1 ,ty - 1)
- term.clearLine()
- print("Jaffa's attack program")
- end
- function cleanInv ()
- for i = 1, 16 do
- if turtle.getItemCount(i) then
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.select(1)
- end
- function checkInv ()
- cleanInv()
- while not tstop do
- sleep(1)
- if turtle.getItemCount(4) > 0 then
- cleanInv()
- end
- end
- cleanInv()
- end
- function keywait ()
- while not tstop do
- local event,key = os.pullEvent()
- if (event == "key") and (key == 203) then
- if not turtle.turnLeft() then print("Error turning left") end
- elseif (event == "key") and (key == 205) then
- if not turtle.turnRight() then print("Error turning right") end
- elseif (event == "key") and (key == 200) and (moveallowed == true) then
- if not turtle.forward() then print("Error moving forward") end
- elseif (event == "key") and (key == 208) and (moveallowed == true) then
- if not turtle.back() then print("Error moving back") end
- elseif (event == "key") and (key == 76) and (movemode == true) then
- if moveallowed == true then
- moveallowed = false
- print("Move lock enabled")
- else
- moveallowed = true
- print("Move lock disbled")
- end
- elseif (event == "key") and (key == 72) and (moveallowed == true) then
- if not turtle.up() then print("Error moving up") end
- elseif (event == "key") and (key == 80) and (moveallowed == true) then
- if not turtle.down() then print("Error moving down") end
- -- elseif (event == "char") and (not ignoredkeys[key]) then
- -- tstop = true
- elseif (event == "char") and (key == "s") then
- tstop = true
- write(waittext)
- elseif (event == "char") and (key == "d") then
- cleanInv()
- end
- end
- end
- function attack ()
- while not tstop do
- if turtle.attack() then
- hits = hits + 1
- else
- sleep(0.15)
- end
- tries = tries + 1
- end
- end
- function stats ()
- local tx,ty = term.getCursorPos()
- while not tstop do
- sleep(2)
- local percentage = (hits/tries) * 100
- term.setCursorPos(1,ty)
- term.clearLine()
- term.setCursorPos(1,ty)
- write("Hits: ")
- write(hits)
- write("/")
- write(tries)
- write(" (")
- write(percentage)
- write("%)")
- end
- write(waittext)
- end
- turtle.select(1)
- print("Press S to stop, D to drop")
- parallel.waitForAll(keywait,attack,stats,checkInv)
- local mx,my = term.getCursorPos()
- term.setCursorPos((mx - string.len(waittext)),my)
- print(" \\e/ ")
Advertisement
Add Comment
Please, Sign In to add comment