-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps-deploy.lua
455 lines (428 loc) · 11.8 KB
/
gps-deploy.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
--
--GPS Deploy by neonerZ v1.1
--http://youtube.com/neonerz
--
--This script is originally from BigSHinyToys from ComputerCraft.info
--Original link can be found here:
--http://www.computercraft.info/forums2/index.php?/topic/3088-how-to-guide-gps-global-position-system/page__p__28333#entry28333
--Edited by neonerZ
--
-- Modifications included:
--
-- happydude11209: Line 209 - added logic to check if the server is set to no fuel mode
-- http://www.computercraft.info/forums2/index.php?/topic/9528-gps-deploy-10/page__view__findpost__p__123411
--
-- kittykiller: Line 110 - Bug in the locate code if you were using an existing GPS system to deploy a new one
-- http://www.computercraft.info/forums2/index.php?/topic/9528-gps-deploy-10/page__view__findpost__p__80323
--
-- Mad_Professor: Line 296 - Bug calling computers, monitors. Making people think they needed to load 4 monitors
-- http://www.computercraft.info/forums2/index.php?/topic/9528-gps-deploy-10/page__view__findpost__p__150291
--
--
--
-- In order to use this script you need to setup
-- either a mining turtle, or a standard turtle
-- Mining Turtle: Slot 1 - Fuel
-- Slot 2 - At least 4 computers
-- Slot 3 - At least 4 modems
-- Slot 4 - At lease 1 disk drive
-- Slot 5 - 1 Disk
-- Standard Turtle: Slot 1 - Fuel
-- Slot 2 - At least 4 computers
-- Slot 3 - At least 4 modems
-- Slot 4 - At lease 4 disk drives
-- Slot 5 - 1 Disk
--
-- (mining turtles will be able to reuse the same
-- disk drive, where-as a standard turtle will leave
-- them and deploy a separate disk drive for each
-- GPS host)
--
-- Default Usage: Place the turtle where you want it
-- deployed facing the SOUTH or 0 direction.
-- Fill the turtle with the required materials
-- above. Then use the command
--
-- gps-deploy x y z
--
-- Where x, y, z is the *absolute* positions of the deploment
-- turtle. By default the turtle will deploy the
-- the GPS array at around y = 254. Add a fourth
-- value to specify the height offset.
-- IMPORTANT: It's crucial you use your absolute coordinates,
-- (the ones inside the parentheses next to your realitive coordinates)
-- For Example: If F3 shows X = -6.43534 (-7) or Z = -15.542 (-16)
-- you'd use -7 and -16 respectively. If you use -6 and -15 all coordinates
-- that go past 0 in the opposite direction will be off by 1.)
--
-- Example: gps-deploy 1 1 1 20
--
-- Would assume the turtle's start position is
-- x=1, y=1, z=1 and will deploy the satelite
-- array at y= 21
--
--neonerZ added features
-- Smart Refilling: Fuel should go in slot 1.
-- If not enough fuel is available script
-- will prompt user for more fuel and wait 30.
-- Script will estimate how much fuel is needed
-- and try to take only that much (in coal)
-- Item Detection: Script will check slots 2-5
-- for the correct quantity of items. It does
-- *not* check if items are valid
-- GPS Host Coordinates: The script now requires
-- you to enter in the coordinates of the
-- turtle before launching. This will set
-- the GPS host computers to the correct
-- coordinates.
-- Satelite Array Location: The script allows
-- the user to set an offset for the placement
-- of the four satelites
-- PofMagicfingers added features
-- Launching "repeat" program if multitab shell is
-- available
-- No more features.
--
-- How heigh up should the satellite be deployed?
-- This is the default value if you don't pass a
-- value to the script. There is a check down below
-- to make sure the user entered values isn't > 254
height = 250
-- need to enable rednet first incase using locate
rednet.open( "right" )
local function printUsage()
print("")
print( "Usages:" )
print( "gps-deploy <x> <y> <z> [height]" )
print( "Example: gps-deploy 1 1 1 20")
print( "would deploy the satelite to y=21")
print( "gps-deploy locate [height]")
print( "if you have working GPS use this")
print( "to find out the coords over GPS")
end
-- confirm default height isn't set above 254
-- Check to see if a minimum of 3 values were
-- passed to the script
local tArgs = { ... }
if tArgs[1] == "locate" then
print ("")
print ("Locating GPS signal...")
xcord, ycord, zcord = gps.locate(5, false)
if xcord==nil then
print("")
print ("No GPS signal detected, please rerun manually")
return
end
if tArgs[2] == nil then
height = tonumber(height)
else
height = tonumber(tArgs[2])
end
print ("gps-deploy ",xcord," ",ycord," ",zcord," height: ",height)
xcord = tonumber(xcord)
ycord = tonumber(ycord)
zcord = tonumber(zcord)
else
if #tArgs <= 2 then
printUsage()
return
else
xcord = tonumber(tArgs[1])
ycord = tonumber(tArgs[2])
zcord = tonumber(tArgs[3])
if tArgs[4] == nil then
height = tonumber(height)
else
if tonumber(tArgs[4]) > 250 then
height = tonumber(height)
else
height = tonumber(tArgs[4])
end
end
end
end
if height > ycord and height < 256 then
height = height-ycord
end
if height > 255 then
height = 255
end
-- check if the script is running on a turtle
-- (original code)
if not turtle then
print("")
print("Error: not a turtle")
return
end
-- move functions
-- (original code)
local mov = {}
mov.forward = function ()
while not turtle.forward() do
sleep(1)
end
return true
end
mov.back = function ()
while not turtle.back() do
sleep(1)
end
return true
end
mov.up = function ()
while not turtle.up() do
sleep(1)
end
return true
end
mov.down = function ()
while not turtle.down() do
sleep(1)
end
return true
end
mov.place = function ()
while not turtle.place() do
sleep(1)
end
end
local base = nil
-- Check if we have enough fuel
-- we estimate the fuel usage ((height*2)+70) needed to
-- complete the deoployment and then see if we have enough
-- fuel loaded. If we don't, it checks the first slot for
-- available fuel and tries to fill up on it. If it doesn't
-- have enough fuel in there, it prompts the user for more
-- fuel. It allows 30 seconds for the user to add fuel
-- (trying to refuel and verify fuel level every second)
-- and if it doesn't get it's fill within 30 seconds
-- it exits with a message to the user
-- neonerZ
if type(turtle.getFuelLevel()) == "string" then
print("No-fuel mode")
else
if turtle.getFuelLevel() < (tonumber(height)*2)+70 then
while turtle.getFuelLevel() < (tonumber(height)*2)+70 do
turtle.select(1)
realcoal=(((tonumber(height)*2)+70)-turtle.getFuelLevel())/80
if realcoal>=64 then
coal=64
else
coal=math.ceil(realcoal)
end
if turtle.refuel(tonumber(coal)) == false then
fuel=((tonumber(height)*2)+70)-turtle.getFuelLevel()
print("")
print("You ran out of fuel in slot 1")
print("Please insert "..fuel.." fuel or "..realcoal.." coal to continue")
print("Waiting 30 seconds for fuel or exiting")
i=0
while i<=30 do
sleep(1)
realcoal=(((tonumber(height)*2)+70)-turtle.getFuelLevel())/80
if realcoal>=64 then
coal=64
else
coal=math.ceil(realcoal)
end
turtle.refuel(tonumber(coal))
if turtle.getFuelLevel() >= (tonumber(height)*2)+70 then
print("")
print("Turtle Fueled")
i=31
end
if i==30 then
fuel=((tonumber(height)*2)+70)-turtle.getFuelLevel()
print("")
print("Not enough fuel provided")
print("Please provide "..fuel.." fuel or "..realcoal.." coal and try again")
return
end
i=i+1
end
end
end
end
end
-- if fs.exists("custom") then
-- print("custom program detected")
-- print("please Enter base Station number")
-- local failFlag = false
-- repeat
-- if failFlag then
-- print("Error Not number")
-- print("try again")
-- end
-- write(" > ")
-- base = tonumber(read())
-- failFlag = true
-- until type(base) == "number"
-- end
-- print("Please Place 4 computers in slot two")
-- print("4 modems in slot three")
-- print("if mineing turtle then")
-- print("1 disk drive in slot four")
-- print("if not mineing then")
-- print("4 disk drive in slot four")
-- print("blank floopy disk in slot five")
-- print("press Enter key to continue")
-- while true do
-- local event , key = os.pullEvent("key")
-- if key == 28 then break end
-- end
-- print("Launching")
--end
-- check if the required quantity of items
-- are in the appropriate spots. I'm sure
-- there's a more elegant way of doing this.
-- I don't believe there's a way to check if
-- the items are correct without using compare
monitor=0
modem=0
diskdrive=0
disk=0
print("")
turtle.select(2)
if turtle.getItemCount(2) < 4 then
print("Please place at least 4 computers into slot two")
monitor=1
end
turtle.select(3)
if turtle.getItemCount(2) < 4 then
print("Please place at least 4 modems into slot three")
modem=1
end
turtle.select(4)
if turtle.getItemCount(2) < 1 then
print("Please place 1 disk drive into slot four if a -mining turtle-")
print("Please place 4 disk drives into slot four if a -standard turtle-")
diskdrive=1
end
turtle.select(5)
if turtle.getItemCount(2) < 1 then
print("Please place 1 disk into slot five")
disk=1
end
if monitor == 1 or modem == 1 or diskdrive == 1 or disk == 1 then
print("Please fix above issues to continue")
return
end
-- calculate the coordinates of the 4 satelite arrays
newycord=tonumber(ycord)+tonumber(height)
if newycord > 255 then newycord = 255 end
toycordns=newycord
toycordwe=newycord-3
if toycordns >= 255 or toycordwe >= 255 then
toycordns=255
toycordwe=252
end
local set = {}
set[1] = {x = tonumber(xcord),z = tonumber(zcord)+3,y = tonumber(toycordns)}
set[2] = {x = tonumber(xcord)-3,z = tonumber(zcord),y = tonumber(toycordwe)}
set[3] = {x = tonumber(xcord),z = tonumber(zcord)-3,y = tonumber(toycordns)}
set[4] = {x = tonumber(xcord)+3,z = tonumber(zcord),y = tonumber(toycordwe)}
-- start the climb up to the correct ycord
while not turtle.up() do
term.clear()
term.setCursorPos(1,1)
term.write("Please get off me")
end
if ycord+tonumber(height) >= 255 then
while turtle.up() do -- sends it up till it hits max hight
end
else
for i = 3,tonumber(height) do
turtle.up()
end
end
-- once at the correct height, deploy GPS array
-- this is a mixture of my own code and the
-- original code
for a = 1,4 do
--forward two
for i = 1,2 do
mov.forward()
end
turtle.select(2)
mov.place()
mov.back()
turtle.select(3)
mov.place()
mov.down()
mov.forward()
turtle.select(4)
mov.place()
turtle.select(5)
turtle.drop()
-- make a custom disk that starts up the gps host application
-- with the correct coordinates and copy it over. also makes
-- makes it a startup script so the computers will
-- start back up properly after chunk unloading
fs.delete("disk/startup")
file = fs.open("disk/startup","w")
file.write([[
fs.copy("disk/install","startup")
fs.delete("disk/startup")
if fs.exists("disk/custom") then
fs.copy("disk/custom","custom")
fs.delete("disk/custom")
end
print("sleep in 10")
sleep(10)
os.reboot()
]])
file.close()
if fs.exists("custom") then
fs.copy("custom","disk/custom")
end
file = fs.open("disk/install","w")
file.write([[
if shell and shell.openTab then
shell.openTab("repeat")
end
if fs.exists("custom") then
shell.run("custom","host",]]..set[a]["x"]..","..set[a]["y"]..","..set[a]["z"]..","..(base or "nil")..[[)
else
shell.run("gps","host",]]..set[a]["x"]..","..set[a]["y"]..","..set[a]["z"]..[[)
end
]])
file.close()
turtle.turnLeft()
mov.forward()
mov.up()
turtle.turnRight()
mov.forward()
turtle.turnRight()
peripheral.call("front","turnOn")
mov.down()
turtle.suck()
turtle.select(3)
turtle.dig()
mov.up()
-- reboot would be here
turtle.turnRight()
--back 3
for i = 1,3 do
mov.forward()
end
turtle.turnLeft()
mov.forward()
if a == 1 or a == 3 then
for i = 1,3 do
mov.down()
end
elseif a == 2 or a == 4 then
for i = 1,3 do
mov.up()
end
end
end
-- goes back down. this is the original code
-- might be worth editing to come down the same
-- amount of spaces it went up, but this should
-- do the job
while turtle.down() do
end
turtle = tMove
print("")
print("Finished")