Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #########################################
- -- auto refuel
- -- version 0.1
- -- http://hevohevo.hatenablog.com/
- -- You must prepare many many fuel items.
- -- Config
- local suck = turtle.suckDown
- local drop = turtle.dropDown
- -- Functions
- function myGetFuelLevel()
- local tmp = turtle.getFuelLevel()
- print("Fuel Level: "..tmp)
- return tmp
- end
- function dropAll()
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- drop()
- end
- end
- end
- -- main
- local limit_level = turtle.getFuelLimit()
- -- see ComputerCraft.cfg
- if not limit_level or limit_level == 0 then
- error("no FuelLimit")
- end
- local args = {...}
- local goal_level = tonumber(args[1])
- if #args == 0 then
- print("FuelLimit is ",limit_level)
- myGetFuelLevel()
- while true do
- write("\nReally? (y/n): ")
- local str = read()
- if str == "n" or str == "N" then
- error("terminated")
- elseif str=="Y" or str=="y" then
- goal_level = limit_level
- break
- end
- end
- end
- turtle.select(1)
- while (goal_level > myGetFuelLevel()) and suck() do
- local status, error_msg = turtle.refuel()
- if not status then
- print(error_msg)
- break
- end
- end
- dropAll()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement