View difference between Paste ID: LJ3HepVv and K8z7pWrE
SHOW: | | - or go back to the newest paste.
1
local tArgs = { ... }
2
local cldt = {}
3
local tfnctns = {}
4
local mvfncs = {{turtle.forward,turtle.detect,turtle.dig,turtle.attack},
5
		{turtle.up,turtle.detectUp,turtle.digUp,turtle.attackUp},
6-
local function trply(mssgstr) -- i.e. "unbreakable block in path"
6+
7
local function trply(mssgstr) -- e.g. "unbreakable block in path"
8-
	if cldt.rcID then sleep(0.1) rednet.send(cldt.rcID,mssgstr) end
8+
9
	if cldt.rcID then rednet.send(cldt.rcID,mssgstr) end
10-
local function trply(mssgstr) -- i.e. "unbreakable block in path"
10+
11
local function mvdgK(drctn) -- i.e.(1 = forward, 2 = up, 3 = down)
12-
	if cldt.rcID then sleep(0.1) rednet.send(cldt.rcID,mssgstr) end
12+
13
	while not mvfncs[drctn][1]() do
14
		if mvfncs[drctn][2]() then
15
			if not mvfncs[drctn][3]() then trply("unbreakable block in path") return false end
16
		elseif turtle.getFuelLevel() == 0 then trply("Out of fuel" ) return false
17
		else mvfncs[drctn][4]() end
18
		if itr8 > 64 then trply("persistent impediment") return false end
19
		itr8 = itr8+1
20
	end
21
	return true
22
end
23
local rctfncs = {
24
tnl = function() turtle.digUp() turtle.digDown() return mvdgK(1) end,
25
dfd = function() return mvdgK(1) end,
26-
rctfncs = {
26+
27
ddn = function() return mvdgK(3) end,
28
bmb = function()
29
	if turtle.placeDown() then redstone.setOutput("bottom",true)
30
		sleep(0.5) redstone.setOutput("bottom",false)
31
	if not turtle.detectDown() then return true end end
32-
	turtle.placeDown()
32+
return false end,
33-
	redstone.setOutput("bottom",true)
33+
34-
	sleep(0.5)
34+
	if turtle.suck() then return "front"
35-
	redstone.setOutput("bottom",false)
35+
	elseif turtle.suckUp() then return "top"
36
	elseif turtle.suckDown() then return "bottom"
37
	else return false end
38-
	if not turtle.suck() then
38+
39-
		turtle.suckUp()
39+
chst = function()
40-
	else turtle.suckDown() end
40+
	turtle.select(16)
41
	if turtle.place() then for i = 1,15 do turtle.select(i) turtle.drop() end return true end
42
return false end,
43
cprl = function()
44
	local frt,top,btm = 0,0,0
45-
	trply("Slot "..cldt.slt.." selected, contains "..turtle.getItemCount(cldt.slt)..", "..turtle.getItemSpace(cldt.slt).." from full") 
45+
	for i = 16,1,-1 do turtle.select(i)
46
		if turtle.compare() then frt = i end
47-
refuel = function()
47+
		if turtle.compareUp() then top = i end
48
		if turtle.compareDown() then btm = i end
49-
	if not turtle.refuel(turtle.getItemCount(cldt.slt)) then
49+
50-
		trply("Slot "..cldt.slt.." does not contain fuel")
50+
return frt.."-"..top.."/"..btm end,
51-
	else trply("New fuel level is "..turtle.getFuelLevel()) end
51+
52
	cldt.slt = math.fmod(cldt.slt,16)+1
53-
gox = function()
53+
54-
	trply("send command string")
54+
	local stcksz = turtle.getItemCount(cldt.slt)
55-
	repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
55+
	return "Slot "..cldt.slt..", "..stcksz.."/"..stcksz+turtle.getItemSpace(cldt.slt)
56-
	tfnctns[6](cldt[3])
56+
57
rfl = function()
58-
gpslct = function() local x,y,z = gps.locate(2) trply("Turtle ID "..os.computerID().." GPS = "..x..", "..y..", "..z) end,
58+
59
	trply("Current fuel level is "..turtle.getFuelLevel()) 
60-
	local rqstr,mssgrq = nil
60+
	if turtle.refuel() then return "New fuel level is "..turtle.getFuelLevel()
61-
	local x,y,z = gps.locate(2)
61+
	else return false end
62
end,
63-
		rqstr,mssgrq = rednet.receive()
63+
gox = function(cmmnds)
64-
		if mssgrq == "PING" then rednet.send(rqstr, textutils.serialize({x,y,z}))
64+
	cmmnds = cmmnds:match("%S+")
65-
		elseif cldt.rcID == rqstr and mssgrq == "gpshst" then x = nil end
65+
	return tfnctns[6](cmmnds)
66-
	until not x
66+
67-
	trply("TurtleID "..os.computerID().." GPS hosting terminated")
67+
gpslct = function() local x,y,z = gps.locate(2) if x then return "GPS = "..x..", "..y..", "..z
68
else return false end end,
69-
rcvfl = function()
69+
70-
	trply("send file name")
70+
	local tp = {gps.locate(2)}
71-
	repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
71+
	if tp[1] then trply("Serving GPS from "..tp[1]..", "..tp[2]..", "..tp[3]) end
72-
	local flnm = cldt[3]
72+
	repeat tp[4],tp[5],tp[6] = rednet.receive()
73-
	trply("send file body")
73+
		if tp[5] == "PING" then rednet.send(tp[4], textutils.serialize({tp[1],tp[2],tp[3]}))
74-
	repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
74+
			trply("PINGed by "..tp[4].." at "..tp[6].." meters")
75-
	local flbdy = fs.open(flnm,"w") flbdy.write(cldt[3]) flbdy.close()
75+
		elseif cldt.rcID == tp[4] and tp[5] == "gpshst" then tp[1] = nil end
76-
	trply(flnm.." Updated")
76+
	until not tp[1]
77
return "GPS hosting terminated"
78-
srvfl = function()
78+
79-
	trply("send file path/name")
79+
rcvfl = function(flnm)
80-
	repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
80+
	local cntnt
81-
	local flbdy = fs.open(cldt[3],"r")
81+
	flnm,cntnt = flnm:match("(%S+)%s*(.*)")
82
 	local hndl = fs.open(flnm,"w") hndl.writeLine(cntnt) hndl.close()
83
return flnm.." updated" end,
84-
ldstrng = function()
84+
srvfl = function(flnm)
85-
	trply("send lua code chunk")
85+
	flnm = flnm:match("%S+")
86-
	repeat cldt[2], cldt[3] = rednet.receive() until cldt[2] == cldt.rcID
86+
	local flbdy = fs.open(flnm,"r")
87-
	local tmpfnc,rrmssg = loadstring(cldt[3]) 
87+
88-
	if tmpfnc then tmpfnc() else trply(rrmssg) end
88+
return flnm.." served" end,
89
xqtfl = function(prms)
90
	local tprm,ndx = {},1
91-
cmdlst = {f=rctfncs.dfd,b=turtle.back,u=rctfncs.dup,d=rctfncs.ddn,
91+
	for v in prms:gmatch("%w+") do tprm[ndx] = v ndx = ndx+1 end
92
	shell.run(unpack(tprm))
93
	local hndl = fs.open("startup","w")
94
	hndl.writeLine("shell.run(\"clfn\",1,"..cldt.rcID..")") hndl.close()
95
return tprm[1].." executed" end,
96
ldstrng = function(luacd)
97-
	R=rctfncs.refuel,S=rctfncs.slct,B=rctfncs.bmb,
97+
	local tmpfnc,rrmssg = loadstring(luacd)
98
	if tmpfnc then return tmpfnc()
99
	else return rrmssg end
100-
function(psswrd,rtID)
100+
101-
	cldt.rcID = rtID
101+
102
local cmdlst = {f=rctfncs.dfd,b=turtle.back,u=rctfncs.dup,d=rctfncs.ddn,
103-
	if psswrd then cldt[1] = psswrd cldt.slt = 1 turtle.select(cldt.slt) else
103+
104-
	print("Enter confirmation password")
104+
105-
	cldt[1] = io.read() end
105+
106-
	print("Send password from control terminal")
106+
107-
	repeat cldt[2], cldt[3] = rednet.receive()
107+
108-
		if not cldt.rcID and cldt[3] == cldt[1] then cldt.rcID = cldt[2] end
108+
	R=rctfncs.rfl,S=rctfncs.slct,B=rctfncs.bmb,C=rctfncs.chst
109-
	until cldt[2] == cldt.rcID and cldt[3] == cldt[1] trply("password accepted")
109+
110
tfnctns = {
111-
	hndl.writeLine("shell.run(\"clfn\",1,\""..cldt[1].."\")") hndl.close()
111+
function(rtID)
112-
	while cldt.rcID do cldt[2],rnmssg = rednet.receive()
112+
	cldt.rcID = tonumber(rtID)
113-
		if cldt[2] == cldt.rcID then
113+
114-
			_,_,cldt[3], cldt[4] = rnmssg:find("^(%a+)(.*)")
114+
	if cldt.rcID then cldt.slt = 1 turtle.select(cldt.slt) else
115-
			if turtle[cldt[3]] then trply(tostring(turtle[cldt[3]](tonumber(cldt[4]))))
115+
		write("Enter controller ID> ") cldt.rcID = tonumber(read())
116-
			elseif rctfncs[cldt[3]] then rctfncs[cldt[3]]()
116+
117-
			elseif rnmssg == "trmn8RC" then cldt.rcID = nil end
117+
	print("Turtle "..os.computerID().." controlled by console "..cldt.rcID)
118
	local hndl = fs.open("startup","w")
119
	hndl.writeLine("shell.run(\"clfn\",1,"..cldt.rcID..")") hndl.close()
120-
	print("Remote Control Terminated") fs.delete("startup")
120+
	while cldt.rcID do
121
		repeat cldt[1],cldt[2] = rednet.receive() until cldt[1] == cldt.rcID
122
		cldt[3], cldt[4] = cldt[2]:match("^(%a+)%s*(.*)")
123
		if cldt[4] == "" then cldt[4] = "1" end
124
		if turtle[cldt[3]] then trply(tostring(turtle[cldt[3]](tonumber(cldt[4]))))
125-
	print("Place fuel in Slot 16 and enter")
125+
		elseif rctfncs[cldt[3]] then trply(tostring(rctfncs[cldt[3]](cldt[4])))
126-
	io.read()
126+
		elseif cldt[2] == "trmn8RC" then trply("Remote Control Terminated")
127-
	rctfncs.refuel()
127+
			cldt.rcID = nil
128
		end
129
	end
130-
	print("Place material to be sifted in Slots 1-15\nLeave Slot 16 empty")
130+
131-
	io.read()
131+
132
	cldt.slt = 16
133
	write("Place fuel in Slot 16 and enter") read()
134
	print(cmdlst.R())
135
end,
136
function()
137
	write("Place material to be sifted in Slots 1-15\nLeave Slot 16 empty") read()
138
	repeat
139-
	print("Place seeds in Slot 1\nBonemeal in Slots 2-15\nLeave Slot 16 empty")
139+
140-
	io.read()
140+
141
		if not turtle.dig() then print("Error") break end
142
	until cldt.slt > 15
143
end,
144
function()
145
	write("Place seeds in Slot 1\nBonemeal in Slots 2-15\nLeave Slot 16 empty") read()
146
	cldt.slt = 2
147
	repeat
148
		turtle.select(1)
149
		if not turtle.place() then print("There must be tilled dirt to plant") break end
150
		turtle.select(cldt.slt)
151
		if not turtle.place() then print("Process requires Bonemeal to continue") break end
152
		if turtle.getItemCount(cldt.slt) < 1 then rctfncs.slct() end
153
		turtle.dig()
154-
		turtle.select(2)
154+
155
end,
156-
		for i=4,7 do if turtle.getItemCount(i) > 0 then turtle.select(i) break end end
156+
function(x3Ps,z3Ps,fcng,dmn)
157-
		turtle.drop()
157+
	x3Ps,z3Ps,fcng,dmn = tonumber(x3Ps),tonumber(z3Ps),tonumber(fcng),tonumber(dmn)
158-
		strtfl = fs.open("disk/startup","w")
158+
159-
		strtfl.writeLine("shell.run(\"gps\",\"host\","..xPos..","..yPos..","..zPos..")")
159+
	local cntntstng = [[fs.copy("disk/rnhst","rnhst") shell.run("rnhst","host",]]
160
	if fs.exists("rom/programs/rnhst") then  cntntstng = [[shell.run("rnhst","host",]]
161-
		turtle.up()
161+
	elseif not fs.exists("rnhst") then print("Must have available rnhst program to execute")
162-
		turtle.forward()
162+
	return false end
163-
		turtle.turnLeft()
163+
164-
		turtle.back()
164+
		turtle.select(2) cmdlst.p()
165
		turtle.select(4) cmdlst.x()
166
		if fs.exists("rnhst") and not fs.exists("disk/rnhst") then fs.copy("rnhst","disk/rnhst") end
167-
		turtle.back()
167+
		local strtfl = fs.open("disk/startup","w")
168
		strtfl.writeLine(cntntstng..xPos..","..yPos..","..zPos..","..dmn..")")
169
		strtfl.close()
170-
		turtle.turnLeft()
170+
		local cmdstrng = {"u","f","l","b",}
171-
		turtle.forward()
171+
		for i = 1,#cmdstrng do cmdlst[cmdstrng[i]]() end
172-
		turtle.turnRight()
172+
		turtle.select(1) cmdlst.p() cmdlst.b()
173-
		turtle.forward()
173+
174-
		turtle.forward()
174+
		cmdstrng = {"p","l","f","r","f","f","r",}
175-
		turtle.turnRight()
175+
		for i = 1,#cmdstrng do cmdlst[cmdstrng[i]]() end
176
		peripheral.call("front","turnOn")
177-
		turtle.down()
177+
		cmdlst.d() cmdlst.v() cmdlst.e()
178
	end
179
	local function plcaxis(xPos,yPos,zPos)
180
		x1Ps,y1Ps,z1Ps = gps.locate(2,true)
181-
		turtle.forward()
181+
		cmdlst.f()
182
		if x1Ps then --there is a GPS system, use it to determine coordinates and facing
183
			x2Ps,yPos,z2Ps = gps.locate(2)
184
			x2Ps,z2Ps = x2Ps-x1Ps,z2Ps-z1Ps
185
		else x1Ps,y1Ps,z1Ps = xPos,yPos,zPos end
186-
		turtle.down()
186+
		cmdlst.d()
187
		gpsnode(x1Ps+(x2Ps*2),y1Ps,z1Ps+(z2Ps*2))
188
	-- Go back 2 and set the second node
189-
		turtle.turnRight()
189+
		cmdlst.r() cmdlst.r()
190-
		turtle.turnRight()
190+
191
		gpsnode(x1Ps-(x2Ps*2),y1Ps,z1Ps-(z2Ps*2))
192
	end
193
	while not(x3Ps and z3Ps and fcng and dmn) do
194-
	print([[Fill inventory as follows
194+
		write([[Fill inventory as follows
195
Slot 1 > 4+ Computers
196
Slot 2 > 4+ Disk drives
197
Slot 3 > 4+ Wireless Modems (4x)
198-
Slots 4-7 > Floppy disks
198+
Slot 4 > Floppy disk
199-
Enter turtle's current x]])
199+
Enter turtle's current x> ]]) x3Ps = tonumber(read())
200-
	local x3Ps = tonumber(io.read())
200+
		write("Enter turtle's current z> ") z3Ps = tonumber(read())
201-
	print("Enter turtle's current z")
201+
		write("Enter turtle's current facing> ") fcng = tonumber(read())
202-
	local z3Ps = tonumber(io.read())
202+
		write("Enter initial admin access ID") dmn = tonumber(read())
203-
	print("Enter turtle's current facing")
203+
204-
	for i=1, tonumber(io.read())+1 do turtle.turnLeft() end
204+
	for i=1, fcng+1 do turtle.turnLeft() end
205
	while turtle.getFuelLevel() < 500 do
206-
		print("Low Fuel Warning")
206+
		trply("Low Fuel Warning!")
207-
		print("Place fuel in Slot 16 and press Enter")
207+
		write("Place fuel in Slot 16 and press Enter") read()
208-
		io.read()
208+
		cldt.slt = 16 print(cmdlst.R())
209-
		turtle.select(16)
209+
210-
		print("Current fuel level is"..turtle.getFuelLevel()) 
210+
211-
		if not turtle.refuel(turtle.getItemCount(16)) then
211+
	while cmdlst.u() do end
212-
			print("Slot "..cldt.slt.." does not contain fuel")
212+
213-
		else print("New fuel level is"..turtle.getFuelLevel()) end
213+
214
	x2Ps,z2Ps = 0,1
215
	cmdlst.b() cmdlst.r()
216-
	while turtle.up() do end
216+
217
	cmdlst.b()
218
	while turtle.down() do end
219
end,
220-
	turtle.back()
220+
221-
	turtle.turnRight()
221+
222
local function lngth(lst)
223
	if lst then return #lst else return 0 end
224
end
225
local function gtNmbr(strg)
226
	local nmbr,rmndr = strg:match("^(%d+)(.*)$")
227
	return nmbr,lngth(strg)-lngth(rmndr)
228
end
229
local function gtLoop(strg)
230
	local loop,rmndr = strg:match("^(%b[])(.*)$")
231-
	local _,_,nmbr,rmndr = strg:find("^(%d+)(.*)$")
231+
232
	else return nil,0 end
233
end
234
local function gox(cmnds)
235-
	local _,_,loop,rmndr = strg:find("^(%b[])(.*)$")
235+
236
	local ndx,prvCmnd,result = 1,""
237
	while ndx <= #cmnds do
238
		local char = cmnds:sub(ndx,ndx)
239
		local nxtCh = cmnds:sub(ndx+1, ndx+1)
240
		if cmdlst[char] then
241
			ndx,result = ndx+1,cmdlst[char]()
242
		else
243
			local nmbr, nLen = gtNmbr(cmnds:sub(ndx))
244
			local loop, lpLen = gtLoop(cmnds:sub(ndx))
245
			if nmbr then
246
				for i = 2,tonumber(nmbr) do gox(prvCmnd) end
247
				ndx = ndx+nLen
248
			elseif loop then
249
				local nmbr, nLen = gtNmbr(cmnds:sub(ndx+lpLen))
250
				if nmbr then
251
					for i = 1,tonumber(nmbr) do gox(loop) end
252
					ndx = ndx+nLen
253
				else while gox(loop) do end end
254
				ndx = ndx+lpLen
255
		end	end
256
		prvCmnd = char
257
	end
258
	return result
259
end
260
if not cmndstrng then
261
	print([[enter a string of commands/loops
262
f b u d l r to move, t to tunnel
263
p P o to place[U/Dn], x X z to drop
264
e E w to dig [U/Dn], v V c to suck
265
R to refuel, S to select next slot
266
[...] loop while last command succeeds
267
number for fixed loop]])
268
	cmndstrng = read() end
269
	return gox(cmndstrng)
270
end,
271
}
272
shell.run('clear')
273
cldt[1] = tonumber(tArgs[1])
274-
	gox(cmndstrng)
274+
if cldt[1] and tArgs[2] then tfnctns[cldt[1]](unpack(tArgs,2)) else
275
repeat
276
	cldt.slt = 1
277
	turtle.select(cldt.slt)
278
	print("Select function by number")
279-
if cldt[1] and tArgs[2] then tfnctns[cldt[1]](tArgs[2],tonumber(tArgs[3])) else
279+
280
2: Refuel
281
3: Sift Gravel
282
4: Auto Farm
283
5: Launch GPS Array
284
6: GoX commands
285
Or other to exit]])
286
	sclfn = tfnctns[tonumber(read())]
287
	if sclfn then sclfn() end
288
until not sclfn
289
end