Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- distance = 4 --turtle with go twice this far
- torchCounter = 3 --jump start first torch placement
- turtleName = os.getComputerLabel()
- ownerTabletId = 2 --what is the computer # of the owner's PDA where messages will be sent.
- --open wireless if available. modem is on the left arm.
- if peripheral.isPresent("right") == true then
- local wireless = peripheral.wrap("right")
- --wireless.open(4)
- rednet.open("right")
- wireless.open(65535)
- else
- print("no modem available")
- end
- --turtle movement functions
- function moveForward()
- while turtle.detect() == true do
- turtle.dig()
- os.sleep(0.5)
- --print("there is something in the way")
- --return to top of loop here.
- restartLoop = 1
- --else
- --turtle.forward()
- --restartLoop = 0 --this is junk but might do the job until i make a better way
- end
- --print("the function is actually running")
- turtle.forward()
- while turtle.detectUp() do
- turtle.digUp()
- os.sleep(0.5)
- end
- turtle.digDown()
- end
- --turtle inventory dump module
- --all slots will be dumped to the inventory in front of the turtle
- -- i = 1
- -- while i < 17 do
- -- slot = 1
- -- turtle.select(slot)
- -- turtle.drop()
- -- i = (i + 1)
- -- end
- --pick up all items from normal size chest
- --turtle will not be able to hold it all in one trip
- --i = 1
- -- while i < 27 do
- -- turtle.suck()
- -- os.sleep(0.25)
- -- i = (i + 1)
- -- end
- function moveUp()
- while turtle.detectUp() == true do
- turtle.digUp()
- os.sleep(0.5)
- --return to top and check again
- --else
- --turtle.up()
- end
- end
- function moveDown()
- while turtle.detectDown() == true do
- turtle.digDown()
- os.sleep(0.5)
- --return to top
- --else
- --turtle.down()
- end
- end
- function moveLeft() --not sure I like how this function works. the facing needs of a particular program may change
- turtle.turnLeft()
- moveForward()
- end
- --turn right then forward one. then dig up and down. then turn right again and dig up and down. then return to start. to turn twice then forward then left then forward then right.
- function rightSide()
- turtle.turnRight()
- moveForward() --displaced one space right
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- moveForward() --now -1x, -1y
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- turtle.turnRight()
- moveForward() --now -1x, 0y
- turtle.turnLeft()
- moveForward()
- turtle.turnRight()--now facing the same was as when we started
- end
- function leftSide()
- turtle.turnLeft()
- moveForward() --displaced one space left
- turtle.digUp()
- turtle.digDown()
- turtle.turnLeft()
- moveForward() --now +1x, +1y
- turtle.digUp()
- turtle.digDown()
- turtle.turnLeft()
- turtle.turnLeft()
- moveForward() --now +1x, 0y
- turtle.turnRight()
- moveForward()
- turtle.turnLeft()--now facing the same was as when we started
- end
- --refuel module
- --checks the turtle inventory for compatible fuel and uses it
- function refuel()
- limit = turtle.getFuelLimit()
- level = turtle.getFuelLevel()
- room = (limit) - (level)
- s = 1
- while s < 17 do
- slot = s
- turtle.select(slot)
- if room > 5000 then
- --i feel like something belongs here
- turtle.refuel()
- --i = (i + 1)
- print(turtle.getFuelLevel)
- --if i = 16 then
- end
- if s == 16 then
- print(turtle.getFuelLevel())
- end
- s = (s + 1)
- end
- end
- function checkFuel()
- checkLevel = turtle.getFuelLevel()
- if checkLevel < 500 then
- refuel()
- end
- if checkLevel < 250 and managerNotified ~= true then
- rednet.send(ownerTabletId, turtleName.." is running low on fuel.") --ad message protocol?
- --location data when available. this sends every few seconds when normally running. find a way to make that happen LESS
- managerNotified = true
- end
- --if no fuel found return to start? or notify PDA
- checkLevel = turtle.getFuelLevel()
- if checkLevel > 500 then
- managerNotified = false
- end
- end
- -- function detectReturnBlockage()
- -- location = {}
- -- location["first"] = (shell.run("gp locate")) --keys 1,2,3 to v x y z?
- -- print(location["first"])
- -- rednet.send(2, turtleName.."here. Something is blocking my return! I am at "..shell.run("gps locate") --pull the result, not the whole damn thing. --add coordinates use them to tell if it is moving or not
- -- end
- -- end
- -- function detectReturnBlockage()
- -- local firstLocation = vector.new(gps.locate())
- -- turtle.forward()
- -- local secondLocation = vector.new(gps.locate())
- -- local movement = secondLocation:sub(firstLocation)
- -- if movement < 1 then
- -- rednet.send(2, turtleName.."here. Something is blocking my return! I am at "..(gps.locate()) --pull the result, not the whole damn thing. --add coordinates use them to tell if it is moving or not
- -- end
- -- end
- function workComplete()
- rednet.send(ownerTabletId, turtleName.." has completed its task. Ready for work!")
- end
- function startPoint()
- --startLocation = vector.new(gps.locate())
- startX, startY, startZ = (gps.locate(5))
- print(startX, startY, startZ) --still only printing one number
- end
- function properReturn()
- --firstLocation = vector.new(gps.locate())
- -- turtle.forward()
- local finishX, finishY, finishZ = (gps.locate(5))
- if tonumber(startX) ~= tonumber(finishX) or tonumber(startY) ~= tonumber(finishY) or tonumber(startZ) ~= tonumber(finishZ) then
- rednet.send(2, "I did not make it all the way back to start.")
- else
- workComplete()
- end
- end
- function checkInventoryState()
- invSlot = 1
- counter = 0
- invFull = false
- while invSlot < 17 do
- slot = invSlot
- turtle.select(slot)
- contents = 0
- contents = turtle.getItemCount()
- invSlot=invSlot+1
- if contents > 0 then
- counter = counter + 1
- end
- end
- if counter > 15 then
- invFull = true
- end
- end
- function dumpToChest()
- if invFull then
- turtle.select(2)
- turtle.placeDown()
- i = 3
- while i < 17 do
- slot = i
- turtle.select(slot)
- turtle.dropDown()
- i=i+1
- end
- os.sleep(150)
- end
- turtle.select(2)
- turtle.digDown()
- turtle.suckUp()
- end
- --if INV is full then select chest and place it then dump inv, then pick chest back up with proper slot selected
- function returnToSender()
- d=1
- turtle.turnRight()
- turtle.turnRight()--now facing 180
- while d < distance do
- turtle.forward() --use the simple forward to save time and not break any work happening behind the turtle
- --detectReturnBlockage()
- turtle.forward() --it moves 2 spaces ahead so it needs to move 2 spaces back per distance counter
- --detectReturnBlockage()
- d = d + 1
- end
- end
- --torch placement function
- --designate slot for torches
- --divide i or d by 7 or 8 and place each time it divides evenly or reset the counter when it hits 7
- function torch()
- if torchCounter == 4 then
- turtle.select(1)
- turtle.placeDown()
- torchCounter = 1
- else
- torchCounter = torchCounter + 1
- end
- end
- function dig() --reused variables are messing up the counts for travel distance. and the vector isnt working.
- refuel()
- travel=1
- while travel < distance do
- moveForward()
- moveForward()
- rightSide()
- leftSide()
- checkInventoryState()
- dumpToChest()
- travel = travel+1
- torch()
- print(torchCounter)
- checkFuel()
- end
- end
- --lets do this
- startPoint()
- dig()
- returnToSender()
- --properReturn()
- workComplete()
- --send my pda a message when work is done
- --send one if contact is lost?
- -- i want something to say go X distance and check for full inventory, if full go back to the chest adn dump the inv,
- --then return to previous until total requested distance is completed and go back to start]]--
- --this particular program should dig a 3x3 hole to whatever distance I desire and put the contents in a chest.
Advertisement
Add Comment
Please, Sign In to add comment