Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- update = false
- --[[
- Simplistic Turtle Program (STP)
- --]]
- if fs.exists("/disk") and not fs.exists("/disk/startup.lua") and shell.getRunningProgram() ~= "/disk/startup.lua" then
- print("Type 'install' to install disk installer")
- write(": ")
- if string.lower(read()) == "install" then
- if fs.exists("/disk") then
- if fs.exists("/disk/startup.lua") then fs.delete("/disk/startup.lua") end
- fs.copy(shell.getRunningProgram(), "/disk/startup.lua")
- print("Installed to 'disk/startup.lua'. Rebooting...")
- sleep(1) os.reboot()
- end
- end
- end
- local w,h = term.getSize()
- clr, cp, sb, st = term.clear, term.setCursorPos, term.setBackgroundColor, term.setTextColor
- local loadingIcon, lisel = {" \n ", ". \n ", "..\n ", "..\n. ", "..\n.."," .\n.."," \n.."," \n ."},1
- local load = function() while math.random(1,2) ~= 1 do clr() cp(1,1) print("STL") write(loadingIcon[lisel]) lisel = lisel+1 if lisel > #loadingIcon then lisel = 1 end sleep(.2) end end
- local c = function(t) return print("[STP] "..t) end
- local setLabel = function(name) return os.setComputerLabel(tostring(name)) end -- did it this way to convert to string because fuck lua
- local prevLabel = os.getComputerLabel()
- setLabel("§aBooting STL...")
- local status, color = "Idle", "e"
- load()
- if not http then
- --c("Http is disabled. Skipping Update...") sleep(.5)
- load() sleep(.5)
- elseif not update then
- --c("Updates disabled. Skipping...") sleep(.2)
- load() sleep(.2)
- else
- --c("Checking for updates")
- load()
- load() st(colors.black)
- if fs.exists("STP_tmp.lua") then fs.delete("STP_tmp.lua") end
- local tmpx, tmpy = term.getCursorPos()
- shell.run("pastebin get VJAVD7UY STP_tmp.lua") st(colors.white) cp(tmpx, tmpy)
- if fs.exists("STP_tmp.lua") then
- local t = fs.open("STP_tmp.lua", "r")
- local u = t.readAll() t.close()
- local t = fs.open(shell.getRunningProgram(), "r")
- local current = t.readAll() t.close()
- if u ~= current then
- load()
- fs.delete(shell.getRunningProgram())
- fs.copy("STP_tmp.lua", shell.getRunningProgram())
- if fs.exists("/disk/startup.lua") then
- clr() cp(1,1)
- print("Update disk? ('disk/startup.lua')")
- print("y - yes")
- print("n - no")
- while true do
- _,a = os.pullEvent("key")
- if a == keys.y then
- if fs.exists("/disk/startup.lua") then fs.delete("/disk/startup.lua") end
- fs.copy("STP_tmp.lua", "/disk/startup.lua") break
- elseif a == keys.n then break end
- end
- end
- c("Update Complete. Rebooting...") sleep(1) os.reboot()
- else
- --c("You are Up-To-Date.") sleep(.2)
- load() sleep(.2)
- end
- else
- --c("Failed to obtain update. Skipping Update...") sleep(.5)
- load() sleep(.5)
- end
- end
- --c("Cleaning up files...")
- load()
- if fs.exists("STP_tmp.lua") then fs.delete("STP_tmp.lua") end -- cleanup update files
- if not turtle then
- setLabel(prevLabel)
- clr() cp(1,1)
- c("Unit is not a turtle.") return
- end
- local getLevel = turtle.getFuelLevel
- local blocks_total = 0
- if not fs.exists("/startup.lua") and turtle then
- clr() cp(1,1)
- print("Install Simple Turtle Program (STP)?")
- print("Type 'install' to install.")
- write(": ")
- if string.lower(read()) == "install" then
- print("Installing...")
- if fs.exists("/startup.lua") then fs.delete("/startup.lua") end
- fs.copy(shell.getRunningProgram(), "/startup.lua")
- print("Installed to 'startup.lua'. Rebooting...")
- sleep(1) os.reboot()
- end
- end
- if shell.getRunningProgram() == "disk/startup.lua" then
- clr() cp(1,1)
- setLabel("§eBooting STL...")
- c("Turtle plugged in. Unplug to use.") return
- end
- --c("Loading Functions...")
- load()
- local function doRefuel()
- turtle.select(1) -- ensure first slot is selected
- if getLevel() == 0 then -- checks the first time
- turtle.refuel(1) -- attempts to refuel
- if getLevel() == 0 then -- if fails
- local tmp = os.getComputerLabel()
- setLabel("§cREFUEL")
- c("Need Fuel to proceed...") -- needs fuel
- while getLevel() == 0 do turtle.refuel(1) sleep(.5) end -- searches for fuel
- setLabel("§f"..tmp)
- end
- end
- end
- local function setInfo(stat, col)
- status, color = stat or status, col or color
- setLabel("§f"..math.min(getLevel(), 9999).." | §"..color..status)
- end
- local function drawInfo()
- setInfo()
- local res,block_info = turtle.inspect()
- clr() cp(1,1)
- print("Fuel: "..math.min(getLevel(), 9999))
- for i=1, w do write("=") end
- if res then print("Block Info: "..block_info.name) end
- print("Blocks Total: "..blocks_total)
- end
- local function goUp() while not turtle.up() do blocks_total = blocks_total + 1 turtle.digUp() sleep(.25) end end
- local function goDown() while not turtle.down() do blocks_total = blocks_total + 1 turtle.digDown() sleep(.25) end end
- local function goForward() while not turtle.forward() do blocks_total = blocks_total + 1 turtle.dig() sleep(.25) end end
- local function goBack() while not turtle.back() do blocks_total = blocks_total + 1 turtle.turnRight() turtle.turnRight() turtle.dig() turtle.turnRight() turtle.turnRight() sleep(.25) end end
- local function digForward() while turtle.dig() do blocks_total = blocks_total + 1 turtle.dig() sleep(.25) end end
- local function digUp() while turtle.digUp() do blocks_total = blocks_total + 1 turtle.digUp() sleep(.25) end end
- local function doTunnel(distance)
- drawInfo()
- c("Tunneling for "..distance.." blocks...")
- setInfo(distance-1, "a")
- for i=1, distance do
- turtle.turnLeft()
- drawInfo() digForward()
- doRefuel() goUp()
- drawInfo() digForward()
- turtle.turnRight()
- turtle.turnRight()
- drawInfo() digForward()
- drawInfo() doRefuel() goDown()
- drawInfo() digForward()
- turtle.turnLeft()
- if i ~= distance then while turtle.detect() do drawInfo() turtle.dig() sleep(.5) end doRefuel() turtle.forward() setInfo(distance-i-1, "a") end
- end
- setInfo("Idle", "e")
- end
- local function doAdvTunnel(distance)
- doTunnel(distance) sleep(.5)
- turtle.turnLeft()
- turtle.turnLeft()
- doRefuel() goUp()
- doRefuel() goUp()
- doTunnel(distance) sleep(.5)
- turtle.turnLeft()
- turtle.turnLeft()
- doRefuel() goDown()
- doRefuel() goDown()
- end
- local function doStripTunnel(distance)
- for i=1, distance do
- doRefuel() drawInfo() setInfo(distance-i, "a") goForward() digUp()
- end
- for i=1, distance do doRefuel() drawInfo() setInfo(distance-i, "a") goBack() end setInfo("Idle", "e")
- end
- local function requestDistance(efu)
- clr() cp(1,1)
- write("Distance: ") distance = tonumber(read())
- if distance == nil then c("Invalid input.") sleep(1) return false end
- print("Estimated Fuel Usage: "..math.ceil((distance*efu)/80))
- print("Current Fuel Level: "..getLevel())
- c("Press enter to confirm...")
- _,b = os.pullEvent("key")
- if b ~= keys.enter then return false end
- return distance
- end
- local run, sel = true, 1
- local menu = {{"3x4 Tunnel (Big)", 4, doAdvTunnel}, {"3x2 Tunnel (Small)", 3, doTunnel}, {"1x2 Strip Mine (Tiny)", 2, doStripTunnel}, {"Exit", 0}}
- --c("Executing STP...") sleep(.5)
- load() sleep(.5)
- doRefuel() setInfo("Idle", "e")
- while run do
- blocks_total = 0
- clr() cp(1,1)
- for i=1, #menu do
- if i == sel then
- print("> "..menu[i][1].." <")
- else
- print(" "..menu[i][1].." ")
- end
- end
- _,b = os.pullEvent("key")
- if b == keys.w or b == keys.up then
- if sel == 1 then sel = #menu else sel = sel - 1 end
- elseif b == keys.s or b == keys.down then
- if sel == #menu then sel = 1 else sel = sel + 1 end
- elseif b == keys.enter or b == keys.e then
- sleep(0.2)
- if sel == #menu then break end
- local dis = requestDistance(menu[sel][2])
- if dis then
- menu[sel][3](dis)
- for i=1, 8 do turtle.turnLeft() sleep(.25) end
- end
- elseif b == keys.q then
- run = false
- end
- end
- clr() cp(1,1) print("STP Closed.") sleep(0.2)
Add Comment
Please, Sign In to add comment