Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local cldt = {}
- local mvfncs = {{turtle.forward,turtle.detect,turtle.dig,turtle.attack},
- {turtle.up,turtle.detectUp,turtle.digUp,turtle.attackUp},
- {turtle.down,turtle.detectDown,turtle.digDown,turtle.attackDown},}
- local function trply(mssgstr) -- i.e. "unbreakable block in path"
- print(mssgstr)
- if cldt.rcID then sleep(0.1) rednet.send(cldt.rcID,mssgstr) end
- end
- local function trply(mssgstr) -- i.e. "unbreakable block in path"
- print(mssgstr)
- if cldt.rcID then sleep(0.1) rednet.send(cldt.rcID,mssgstr) end
- end
- local function mvdgK(drctn) -- i.e.(1 = forward, 2 = up, 3 = down)
- local itr8 = 0
- while not mvfncs[drctn][1]() do
- if mvfncs[drctn][2]() then
- if not mvfncs[drctn][3]() then trply("unbreakable block in path") return false end
- elseif turtle.getFuelLevel() == 0 then trply("Out of fuel" ) return false
- else mvfncs[drctn][4]() end
- if itr8 > 64 then trply("persistent impediment") return false end
- itr8 = itr8+1
- end
- return true
- end
- rctfncs = {
- tnl = function() turtle.digUp() turtle.digDown() return mvdgK(1) end,
- dfd = function() return mvdgK(1) end,
- dup = function() return mvdgK(2) end,
- ddn = function() return mvdgK(3) end,
- bmb = function()
- turtle.placeDown()
- redstone.setOutput("bottom",true)
- sleep(0.5)
- redstone.setOutput("bottom",false)
- end,
- pckup = function()
- if not turtle.suck() then
- turtle.suckUp()
- else turtle.suckDown() end
- end,
- slct = function()
- cldt.slt = math.fmod(cldt.slt,16)+1
- turtle.select(cldt.slt)
- trply("Slot "..cldt.slt.." selected, contains "..turtle.getItemCount(cldt.slt)..", "..turtle.getItemSpace(cldt.slt).." from full")
- end,
- refuel = function()
- trply("Current fuel level is "..turtle.getFuelLevel())
- if not turtle.refuel(turtle.getItemCount(cldt.slt)) then
- trply("Slot "..cldt.slt.." does not contain fuel")
- else trply("New fuel level is "..turtle.getFuelLevel()) end
- end,
- gox = function()
- trply("send command string")
- repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
- tfnctns[6](cldt[3])
- end,
- gpslct = function() local x,y,z = gps.locate(2) trply("Turtle ID "..os.computerID().." GPS = "..x..", "..y..", "..z) end,
- gpshst = function()
- local rqstr,mssgrq = nil
- local x,y,z = gps.locate(2)
- repeat
- rqstr,mssgrq = rednet.receive()
- if mssgrq == "PING" then rednet.send(rqstr, textutils.serialize({x,y,z}))
- elseif cldt.rcID == rqstr and mssgrq == "gpshst" then x = nil end
- until not x
- trply("TurtleID "..os.computerID().." GPS hosting terminated")
- end,
- rcvfl = function()
- trply("send file name")
- repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
- local flnm = cldt[3]
- trply("send file body")
- repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
- local flbdy = fs.open(flnm,"w") flbdy.write(cldt[3]) flbdy.close()
- trply(flnm.." Updated")
- end,
- srvfl = function()
- trply("send file path/name")
- repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
- local flbdy = fs.open(cldt[3],"r")
- trply(flbdy.readAll()) flbdy.close()
- end,
- ldstrng = function()
- trply("send lua code chunk")
- repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
- local tmpfnc,rrmssg = loadstring(cldt[3])
- if tmpfnc then tmpfnc() else trply(rrmssg) end
- end,
- }
- cmdlst = {f=rctfncs.dfd,b=turtle.back,u=rctfncs.dup,d=rctfncs.ddn,
- l=turtle.turnLeft,r=turtle.turnRight,t= rctfncs.tnl,
- p=turtle.place,P=turtle.placeUp,o=turtle.placeDown,
- x=turtle.drop,X=turtle.dropUp,z=turtle.dropDown,
- e=turtle.dig,E=turtle.digUp,w=turtle.digDown,
- v=rctfncs.pckup,V=turtle.suckUp,c=turtle.suckDown,
- R=rctfncs.refuel,S=rctfncs.slct,B=rctfncs.bmb,
- }
- tfnctns = {
- function(psswrd,rtID)
- cldt.rcID = rtID
- rednet.open("right")
- if psswrd then cldt[1] = psswrd cldt.slt = 1 turtle.select(cldt.slt) else
- print("Enter confirmation password")
- cldt[1] = io.read() end
- print("Send password from control terminal")
- repeat cldt[2], cldt[3] = rednet.receive()
- if not cldt.rcID and cldt[3] == cldt[1] then cldt.rcID = cldt[2] end
- until cldt[2] == cldt.rcID and cldt[3] == cldt[1] trply("password accepted")
- local hndl = fs.open("startup","w")
- hndl.writeLine("shell.run(\"clfn\",1,\""..cldt[1].."\")") hndl.close()
- while cldt.rcID do cldt[2],rnmssg = rednet.receive()
- if cldt[2] == cldt.rcID then
- _,_,cldt[3], cldt[4] = rnmssg:find("^(%a+)(.*)")
- if turtle[cldt[3]] then trply(tostring(turtle[cldt[3]](tonumber(cldt[4]))))
- elseif rctfncs[cldt[3]] then rctfncs[cldt[3]]()
- elseif rnmssg == "trmn8RC" then cldt.rcID = nil end
- end
- end
- print("Remote Control Terminated") fs.delete("startup")
- end,
- function()
- cldt.slt = 16
- turtle.select(cldt.slt)
- print("Place fuel in Slot 16 and enter")
- io.read()
- rctfncs.refuel()
- end,
- function()
- print("Place material to be sifted in Slots 1-15\nLeave Slot 16 empty")
- io.read()
- repeat
- turtle.place()
- if turtle.getItemCount(cldt.slt) < 1 then rctfncs.slct() end
- if not turtle.dig() then print("Error") break end
- until cldt.slt > 15
- end,
- function()
- print("Place seeds in Slot 1\nBonemeal in Slots 2-15\nLeave Slot 16 empty")
- io.read()
- cldt.slt = 2
- repeat
- turtle.select(1)
- if not turtle.place() then print("There must be tilled dirt to plant") break end
- turtle.select(cldt.slt)
- if not turtle.place() then print("Process requires Bonemeal to continue") break end
- if turtle.getItemCount(cldt.slt) < 1 then rctfncs.slct() end
- turtle.dig()
- until cldt.slt > 15
- end,
- function()
- local x1Ps,y1Ps,z1Ps,x2Ps,z2Ps = 0,255,0,1,0
- local function gpsnode(xPos,yPos,zPos)
- turtle.select(2)
- turtle.place()
- for i=4,7 do if turtle.getItemCount(i) > 0 then turtle.select(i) break end end
- turtle.drop()
- strtfl = fs.open("disk/startup","w")
- strtfl.writeLine("shell.run(\"gps\",\"host\","..xPos..","..yPos..","..zPos..")")
- strtfl.close()
- turtle.up()
- turtle.forward()
- turtle.turnLeft()
- turtle.back()
- turtle.select(1)
- turtle.place()
- turtle.back()
- turtle.select(3)
- turtle.place()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- peripheral.call("front","turnOn")
- turtle.down()
- end
- local function plcaxis(xPos,yPos,zPos)
- x1Ps,y1Ps,z1Ps = gps.locate(2,true)
- turtle.forward()
- if x1Ps then --there is a GPS system, use it to determine coordinates and facing
- x2Ps,yPos,z2Ps = gps.locate(2)
- x2Ps,z2Ps = x2Ps-x1Ps,z2Ps-z1Ps
- else x1Ps,y1Ps,z1Ps = xPos,yPos,zPos end
- turtle.down()
- gpsnode(x1Ps+(x2Ps*2),y1Ps,z1Ps+(z2Ps*2))
- -- Go back 2 and set the second node
- turtle.turnRight()
- turtle.turnRight()
- for c=1,2 do turtle.forward() end
- gpsnode(x1Ps-(x2Ps*2),y1Ps,z1Ps-(z2Ps*2))
- end
- print([[Fill inventory as follows
- Slot 1 > 4+ Computers
- Slot 2 > 4+ Disk drives
- Slot 3 > 4+ Wireless Modems (4x)
- Slots 4-7 > Floppy disks
- Enter turtle's current x]])
- local x3Ps = tonumber(io.read())
- print("Enter turtle's current z")
- local z3Ps = tonumber(io.read())
- print("Enter turtle's current facing")
- for i=1, tonumber(io.read())+1 do turtle.turnLeft() end
- while turtle.getFuelLevel() < 500 do
- print("Low Fuel Warning")
- print("Place fuel in Slot 16 and press Enter")
- io.read()
- turtle.select(16)
- print("Current fuel level is"..turtle.getFuelLevel())
- if not turtle.refuel(turtle.getItemCount(16)) then
- print("Slot "..cldt.slt.." does not contain fuel")
- else print("New fuel level is"..turtle.getFuelLevel()) end
- end
- -- launch turtle
- while turtle.up() do end
- plcaxis(x3Ps,255,z3Ps)
- -- Go back to the middle and turn
- x2Ps,z2Ps = 0,1
- turtle.back()
- turtle.turnRight()
- plcaxis(x3Ps,254,z3Ps)
- while turtle.down() do end
- end,
- function(cmndstrng) -- Go commands
- -- non-nil array length
- local function lngth(lst)
- if lst then return #lst else return 0 end
- end
- local function gtNmbr(strg)
- local _,_,nmbr,rmndr = strg:find("^(%d+)(.*)$")
- return nmbr,lngth(strg)-lngth(rmndr)
- end
- local function gtLoop(strg)
- local _,_,loop,rmndr = strg:find("^(%b[])(.*)$")
- if loop then return loop:sub(2,-2),lngth(strg)-lngth(rmndr)
- else return nil,0 end
- end
- local function gox(cmnds)
- if not #cmnds then return false end
- local ndx,prvCmnd,result = 1,""
- while ndx <= #cmnds do
- local char = cmnds:sub(ndx,ndx)
- local nxtCh = cmnds:sub(ndx+1, ndx+1)
- if cmdlst[char] then
- ndx,result = ndx+1,cmdlst[char]()
- else
- local nmbr, nLen = gtNmbr(cmnds:sub(ndx))
- local loop, lpLen = gtLoop(cmnds:sub(ndx))
- if nmbr then
- for i = 2,tonumber(nmbr) do gox(prvCmnd) end
- ndx = ndx+nLen
- elseif loop then
- local nmbr, nLen = gtNmbr(cmnds:sub(ndx+lpLen))
- if nmbr then
- for i = 1,tonumber(nmbr) do gox(loop) end
- ndx = ndx+nLen
- else while gox(loop) do end end
- ndx = ndx+lpLen
- end end
- prvCmnd = char
- end
- return result
- end
- if not cmndstrng then
- print([[enter a string of commands/loops
- f b u d l r to move, t to tunnel
- p P o to place[U/Dn], x X z to drop
- e E w to dig [U/Dn], v V c to suck
- R to refuel, S to select next slot
- [...] loop while last command succeeds
- number for fixed loop]])
- cmndstrng = read() end
- gox(cmndstrng)
- end,
- }
- shell.run('clear')
- cldt[1] = tonumber(tArgs[1])
- if cldt[1] and tArgs[2] then tfnctns[cldt[1]](tArgs[2],tonumber(tArgs[3])) else
- repeat
- cldt.slt = 1
- turtle.select(cldt.slt)
- print("Select function by number")
- print([[1: Remote Control
- 2: Refuel
- 3: Sift Gravel
- 4: Auto Farm
- 5: Launch GPS Array
- 6: GoX commands
- Or other to exit]])
- sclfn = tfnctns[tonumber(io.read())]
- if sclfn then sclfn() end
- until not sclfn
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement