Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local location = ""
- local position = ""
- local returnValue = ""
- local boolreturn = false;
- local whatIHaveIs = "empty"
- function teleport()
- tp = peripheral.wrap("bottom")
- tp.teleport()
- end
- function isFull()
- boolreturn = false
- greader = peripheral.wrap("right")
- data = greader.get()
- boolreturn = data["Full Energy"]
- end
- function checkEmpty()
- greader = peripheral.wrap("right")
- data = greader.get()
- while not data["No Energy"] do
- sleep(15)
- data = greader.get()
- end
- turtle.dig()
- whatIHaveIs = "empty"
- end
- function checkLoc()
- loc = turtle.detectUp()
- if loc == true then
- print ("I am at the charge station")
- location = "Charging"
- isCharging()
- if boolreturn == true then
- position = "charger"
- else
- position = "teleporter"
- end
- else
- print("I am at the quarry")
- location = "Quarry"
- end
- shell.run('clear')
- print("-------------------------")
- print("location = "..location)
- print("position = "..position)
- print("whatIHaveIs = "..whatIHaveIs)
- print("Fuel = "..tostring(turtle.getFuelLevel()))
- print("-------------------------")
- end
- function checkFuel()
- fuel = turtle.getFuelLevel()
- if fuel < 5000 then
- print("I need fuel")
- FuelUp()
- end
- end
- function DeepCharge()
- checkLoc()
- if location == "Charging" then
- if position == "charger" then
- while turtle.getFuelLevel() < 15000 do
- shell.run('clear')
- print("-------------------------")
- print("location = "..location)
- print("position = "..position)
- print("whatIHaveIs = "..whatIHaveIs)
- print("Deep Fuel = "..tostring(turtle.getFuelLevel()))
- print("-------------------------")
- sleep(1)
- end
- end
- end
- end
- function FuelUp()
- checkLoc()
- if location == "Charging" then
- if position == "charger" then
- while turtle.getFuelLevel() < 9000 do
- shell.run('clear')
- print("-------------------------")
- print("location = "..location)
- print("position = "..position)
- print("whatIHaveIs = "..whatIHaveIs)
- print("Fueling = "..tostring(turtle.getFuelLevel()))
- print("-------------------------")
- sleep(1)
- end
- end
- end
- end
- function isCharging()
- boolreturn = false
- fuellevel = turtle.getFuelLevel()
- sleep(5)
- if fuellevel < turtle.getFuelLevel() then
- boolreturn = true
- end
- end
- function CheckChargeStationSpotPlacement()
- print("Spot Check 4 Place")
- boolreturn = false
- turtle.forward()
- turtle.turnLeft()
- loc = turtle.detect()
- if loc == false then
- boolreturn = true
- turtle.place()
- end
- turtle.turnRight()
- end
- function CheckChargeStationSpotGet()
- print("Spot Check 4 Get")
- boolreturn = false
- turtle.forward()
- turtle.turnLeft()
- loc = turtle.detect()
- if loc == true then
- isFull()
- if boolreturn == true then
- whatIHaveIs = "full"
- turtle.dig()
- end
- end
- turtle.turnRight()
- end
- function return2ChargeStation()
- turtle.turnLeft()
- turtle.turnLeft()
- while turtle.forward() do
- sleep(0.1)
- end
- turtle.turnRight()
- turtle.forward()
- FuelUp()
- end
- function Go()
- checkLoc()
- shell.run('clear')
- print("-----------GO------------")
- print("location = "..location)
- print("position = "..position)
- print("whatIHaveIs = "..whatIHaveIs)
- print("Fuel = "..tostring(turtle.getFuelLevel()))
- print("-------------------------")
- if location == "Charging" then
- if position == "teleporter" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- end
- FuelUp()
- if turtle.getItemCount(1) >= 1 then
- if whatIHaveIs == "empty" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- CheckChargeStationSpotPlacement()
- if boolreturn == true then
- return2ChargeStation()
- else
- CheckChargeStationSpotPlacement()
- if boolreturn == true then
- return2ChargeStation()
- else
- CheckChargeStationSpotPlacement()
- return2ChargeStation()
- end
- end
- return true
- end
- if whatIHaveIs == "full" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- teleport()
- end
- else
- if whatIHaveIs == "nothing" then
- DeepCharge()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- teleport()
- return true
- else
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- CheckChargeStationSpotGet()
- if boolreturn == true then
- return2ChargeStation()
- else
- CheckChargeStationSpotGet()
- if boolreturn == true then
- return2ChargeStation()
- else
- CheckChargeStationSpotGet()
- return2ChargeStation()
- end
- end
- end
- end
- else
- if turtle.getItemCount(1) >= 1 then
- whatIHaveIs = "full"
- turtle.turnLeft()
- turtle.place()
- whatIHaveIs = "nothing"
- turtle.turnRight()
- teleport()
- else
- whatIHaveIs = "nothing"
- turtle.turnLeft()
- checkEmpty()
- turtle.turnRight()
- teleport()
- end
- end
- return true
- end
- while true do
- Go()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement