init.lua

181 lines · 4.8 KB

Open raw

eHydra Initialization System

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/eHydra_wip/init.lua
1-- eHydra Initialization System
2-- Manages advanced mining turtle deployment and initialization
3
4local function findModem()
5 for _, side in pairs(rs.getSides()) do
6 if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
7 return side
8 end
9 end
10 return nil
11end
12
13local function deployTurtle(turtleType, position)
14 print("Deploying " .. turtleType .. " at position " .. position .. "...")
15
16 -- Look for turtle in inventory
17 for slot = 1, 16 do
18 local item = turtle.getItemDetail(slot)
19 if item then
20 if item.name == "computercraft:turtle_advanced" or
21 item.name == "computercraft:" .. turtleType then
22 turtle.select(slot)
23
24 -- Place the turtle
25 if turtle.place() then
26 print("✓ Turtle deployed successfully")
27 return true
28 else
29 print("✗ Failed to place turtle - check space")
30 return false
31 end
32 end
33 end
34 end
35
36 print("✗ No " .. turtleType .. " found in inventory")
37 return false
38end
39
40local function initializeTurtle(id, program)
41 print("Initializing turtle " .. id .. " with " .. program .. "...")
42
43 -- Send initialization command
44 rednet.send(id, {
45 command = "INIT",
46 program = program,
47 autostart = true
48 })
49
50 -- Wait for response
51 local senderId, response = rednet.receive(5)
52 if senderId == id and response and response.status == "READY" then
53 print("✓ Turtle " .. id .. " initialized successfully")
54 return true
55 else
56 print("✗ Turtle " .. id .. " initialization failed or timed out")
57 return false
58 end
59end
60
61local function setupGPS()
62 print("Setting up GPS system...")
63
64 -- Try to get GPS coordinates
65 local x, y, z = gps.locate()
66 if x then
67 print("✓ GPS location: " .. x .. ", " .. y .. ", " .. z)
68 return true
69 else
70 print("⚠ GPS not available - manual positioning required")
71 return false
72 end
73end
74
75print("eHydra Initialization System v1.0")
76print("=================================")
77print()
78
79-- Check for modem
80local modemSide = findModem()
81if modemSide then
82 rednet.open(modemSide)
83 print("✓ Modem found on " .. modemSide .. " side")
84else
85 print("⚠ No modem found - limited functionality")
86end
87
88print()
89print("Select operation:")
90print("1. Deploy Advanced Mining Turtle")
91print("2. Deploy Advanced Wireless Chunky Turtle")
92print("3. Initialize existing turtle")
93print("4. Setup GPS system")
94print("5. Full deployment sequence")
95print()
96
97write("Choice [1-5]: ")
98local choice = tonumber(read()) or 1
99
100if choice == 1 then
101 print()
102 print("Deploying Advanced Mining Turtle...")
103 deployTurtle("turtle_advanced", "current")
104
105elseif choice == 2 then
106 print()
107 print("Deploying Advanced Wireless Chunky Turtle...")
108 deployTurtle("turtle_advanced", "current")
109
110 -- Additional setup for chunky turtles
111 print("Configuring chunky loading...")
112 -- This would require specific chunky turtle setup
113
114elseif choice == 3 then
115 if not modemSide then
116 print("Error: Modem required for turtle initialization")
117 return
118 end
119
120 print()
121 write("Turtle ID: ")
122 local id = tonumber(read())
123
124 write("Program to load [quarry]: ")
125 local program = read()
126 if program == "" then program = "quarry" end
127
128 initializeTurtle(id, program)
129
130elseif choice == 4 then
131 setupGPS()
132
133elseif choice == 5 then
134 print()
135 print("Full Deployment Sequence")
136 print("=======================")
137
138 -- Setup GPS
139 setupGPS()
140
141 print()
142 write("Number of turtles to deploy [1]: ")
143 local count = tonumber(read()) or 1
144
145 write("Turtle type (mining/chunky) [mining]: ")
146 local turtleType = read()
147 if turtleType == "" then turtleType = "mining" end
148
149 write("Mining program [quarry]: ")
150 local program = read()
151 if program == "" then program = "quarry" end
152
153 print()
154 print("Deploying " .. count .. " " .. turtleType .. " turtle(s)...")
155
156 for i = 1, count do
157 print()
158 print("Deploying turtle " .. i .. "/" .. count .. "...")
159
160 if deployTurtle("turtle_advanced", i) then
161 -- Wait a moment for turtle to boot
162 sleep(2)
163
164 if modemSide then
165 -- Try to initialize the turtle
166 -- This would require the turtle to have a known ID or auto-discovery
167 print("Turtle deployed - manual initialization may be required")
168 end
169 end
170 end
171
172 print()
173 print("Deployment sequence complete!")
174
175else
176 print("Invalid choice")
177end
178
179print()
180print("eHydra initialization finished.")
181