Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local cldt = {}
- local tfnctns = {}
- 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) -- e.g. "unbreakable block in path"
- print(mssgstr)
- if cldt.rcID then 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
- local 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()
- if turtle.placeDown() then redstone.setOutput("bottom",true)
- sleep(0.5) redstone.setOutput("bottom",false)
- if not turtle.detectDown() then return true end end
- return false end,
- pckup = function()
- if turtle.suck() then return "front"
- elseif turtle.suckUp() then return "top"
- elseif turtle.suckDown() then return "bottom"
- else return false end
- end,
- chst = function()
- turtle.select(16)
- if turtle.place() then for i = 1,15 do turtle.select(i) turtle.drop() end return true end
- return false end,
- cprl = function()
- local frt,top,btm = 0,0,0
- for i = 16,1,-1 do turtle.select(i)
- if turtle.compare() then frt = i end
- if turtle.compareUp() then top = i end
- if turtle.compareDown() then btm = i end
- end
- return frt.."-"..top.."/"..btm end,
- slct = function()
- cldt.slt = math.fmod(cldt.slt,16)+1
- turtle.select(cldt.slt)
- local stcksz = turtle.getItemCount(cldt.slt)
- return "Slot "..cldt.slt..", "..stcksz.."/"..stcksz+turtle.getItemSpace(cldt.slt)
- end,
- rfl = function()
- turtle.select(cldt.slt)
- trply("Current fuel level is "..turtle.getFuelLevel())
- if turtle.refuel() then return "New fuel level is "..turtle.getFuelLevel()
- else return false end
- end,
- gox = function(cmmnds)
- cmmnds = cmmnds:match("%S+")
- return tfnctns[6](cmmnds)
- end,
- gpslct = function() local x,y,z = gps.locate(2) if x then return "GPS = "..x..", "..y..", "..z
- else return false end end,
- gpshst = function()
- local tp = {gps.locate(2)}
- if tp[1] then trply("Serving GPS from "..tp[1]..", "..tp[2]..", "..tp[3]) end
- repeat tp[4],tp[5],tp[6] = rednet.receive()
- if tp[5] == "PING" then rednet.send(tp[4], textutils.serialize({tp[1],tp[2],tp[3]}))
- trply("PINGed by "..tp[4].." at "..tp[6].." meters")
- elseif cldt.rcID == tp[4] and tp[5] == "gpshst" then tp[1] = nil end
- until not tp[1]
- return "GPS hosting terminated"
- end,
- rcvfl = function(flnm)
- local cntnt
- flnm,cntnt = flnm:match("(%S+)%s*(.*)")
- local hndl = fs.open(flnm,"w") hndl.writeLine(cntnt) hndl.close()
- return flnm.." updated" end,
- srvfl = function(flnm)
- flnm = flnm:match("%S+")
- local flbdy = fs.open(flnm,"r")
- trply(flbdy.readAll()) flbdy.close()
- return flnm.." served" end,
- xqtfl = function(prms)
- local tprm,ndx = {},1
- for v in prms:gmatch("%w+") do tprm[ndx] = v ndx = ndx+1 end
- shell.run(unpack(tprm))
- local hndl = fs.open("startup","w")
- hndl.writeLine("shell.run(\"clfn\",1,"..cldt.rcID..")") hndl.close()
- return tprm[1].." executed" end,
- ldstrng = function(luacd)
- local tmpfnc,rrmssg = loadstring(luacd)
- if tmpfnc then return tmpfnc()
- else return rrmssg end
- end,
- }
- local 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.rfl,S=rctfncs.slct,B=rctfncs.bmb,C=rctfncs.chst
- }
- tfnctns = {
- function(rtID)
- cldt.rcID = tonumber(rtID)
- rednet.open("right")
- if cldt.rcID then cldt.slt = 1 turtle.select(cldt.slt) else
- write("Enter controller ID> ") cldt.rcID = tonumber(read())
- end
- print("Turtle "..os.computerID().." controlled by console "..cldt.rcID)
- local hndl = fs.open("startup","w")
- hndl.writeLine("shell.run(\"clfn\",1,"..cldt.rcID..")") hndl.close()
- while cldt.rcID do
- repeat cldt[1],cldt[2] = rednet.receive() until cldt[1] == cldt.rcID
- cldt[3], cldt[4] = cldt[2]:match("^(%a+)%s*(.*)")
- if cldt[4] == "" then cldt[4] = "1" end
- if turtle[cldt[3]] then trply(tostring(turtle[cldt[3]](tonumber(cldt[4]))))
- elseif rctfncs[cldt[3]] then trply(tostring(rctfncs[cldt[3]](cldt[4])))
- elseif cldt[2] == "trmn8RC" then trply("Remote Control Terminated")
- cldt.rcID = nil
- end
- end
- end,
- function()
- cldt.slt = 16
- write("Place fuel in Slot 16 and enter") read()
- print(cmdlst.R())
- end,
- function()
- write("Place material to be sifted in Slots 1-15\nLeave Slot 16 empty") 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()
- write("Place seeds in Slot 1\nBonemeal in Slots 2-15\nLeave Slot 16 empty") 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(x3Ps,z3Ps,fcng,dmn)
- x3Ps,z3Ps,fcng,dmn = tonumber(x3Ps),tonumber(z3Ps),tonumber(fcng),tonumber(dmn)
- local x1Ps,y1Ps,z1Ps,x2Ps,z2Ps = 0,255,0,1,0
- local cntntstng = [[fs.copy("disk/rnhst","rnhst") shell.run("rnhst","host",]]
- if fs.exists("rom/programs/rnhst") then cntntstng = [[shell.run("rnhst","host",]]
- elseif not fs.exists("rnhst") then print("Must have available rnhst program to execute")
- return false end
- local function gpsnode(xPos,yPos,zPos)
- turtle.select(2) cmdlst.p()
- turtle.select(4) cmdlst.x()
- if fs.exists("rnhst") and not fs.exists("disk/rnhst") then fs.copy("rnhst","disk/rnhst") end
- local strtfl = fs.open("disk/startup","w")
- strtfl.writeLine(cntntstng..xPos..","..yPos..","..zPos..","..dmn..")")
- strtfl.close()
- local cmdstrng = {"u","f","l","b",}
- for i = 1,#cmdstrng do cmdlst[cmdstrng[i]]() end
- turtle.select(1) cmdlst.p() cmdlst.b()
- turtle.select(3)
- cmdstrng = {"p","l","f","r","f","f","r",}
- for i = 1,#cmdstrng do cmdlst[cmdstrng[i]]() end
- peripheral.call("front","turnOn")
- cmdlst.d() cmdlst.v() cmdlst.e()
- end
- local function plcaxis(xPos,yPos,zPos)
- x1Ps,y1Ps,z1Ps = gps.locate(2,true)
- cmdlst.f()
- 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
- cmdlst.d()
- gpsnode(x1Ps+(x2Ps*2),y1Ps,z1Ps+(z2Ps*2))
- -- Go back 2 and set the second node
- cmdlst.r() cmdlst.r()
- for c=1,2 do turtle.forward() end
- gpsnode(x1Ps-(x2Ps*2),y1Ps,z1Ps-(z2Ps*2))
- end
- while not(x3Ps and z3Ps and fcng and dmn) do
- write([[Fill inventory as follows
- Slot 1 > 4+ Computers
- Slot 2 > 4+ Disk drives
- Slot 3 > 4+ Wireless Modems (4x)
- Slot 4 > Floppy disk
- Enter turtle's current x> ]]) x3Ps = tonumber(read())
- write("Enter turtle's current z> ") z3Ps = tonumber(read())
- write("Enter turtle's current facing> ") fcng = tonumber(read())
- write("Enter initial admin access ID") dmn = tonumber(read())
- end
- for i=1, fcng+1 do turtle.turnLeft() end
- while turtle.getFuelLevel() < 500 do
- trply("Low Fuel Warning!")
- write("Place fuel in Slot 16 and press Enter") read()
- cldt.slt = 16 print(cmdlst.R())
- end
- -- launch turtle
- while cmdlst.u() do end
- plcaxis(x3Ps,255,z3Ps)
- -- Go back to the middle and turn
- x2Ps,z2Ps = 0,1
- cmdlst.b() cmdlst.r()
- plcaxis(x3Ps,254,z3Ps)
- cmdlst.b()
- 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:match("^(%d+)(.*)$")
- return nmbr,lngth(strg)-lngth(rmndr)
- end
- local function gtLoop(strg)
- local loop,rmndr = strg:match("^(%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
- return gox(cmndstrng)
- end,
- }
- shell.run('clear')
- cldt[1] = tonumber(tArgs[1])
- if cldt[1] and tArgs[2] then tfnctns[cldt[1]](unpack(tArgs,2)) 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(read())]
- if sclfn then sclfn() end
- until not sclfn
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement