· 7 years ago · Feb 25, 2019, 11:34 PM
1InstallDir = ...
2if InstallDir == nil then InstallDir = '/' end
3term.clear()
4term.setCursorPos(1,1)
5print('Do you wish to install Min? (Y/N)')
6local x = read()
7
8if x == 'y' or x == 'Y' then
9local NF = fs.open(InstallDir..'/Min','w')
10NF.write(''
11..'--- This renders a minimap showing nearby ores using the overlay glasses and block scanner.\n'
12..'\n'
13..'--- We start the program by specifying a series of configuration options. Feel free to ignore these, and use the values\n'
14..'--- inline. Whilst you don't strictly speaking need a delay between each iteration, it does reduce the impact on the\n'
15..'--- server.\n'
16..'local scanInterval = 0.2\n'
17..'local renderInterval = 0.05\n'
18..'local scannerRange = 8\n'
19..'local scannerWidth = scannerRange * 2 + 1\n'
20..'\n'
21..'--- These values aren't very exciting, they just control what the minimap looks like\n'
22..'local size = 0.5\n'
23..'local cellSize = 16\n'
24..'local offsetX = 75\n'
25..'local offsetY = 75\n'
26..'\n'
27..'--- We end our on figuration section by defining the ores we're interested in and what colour we'll draw them as. We\n'
28..'--- define some ores as having a higher priority, so large ore veins don't mask smaller veins of more precious ores.\n'
29..'local ores = {\n'
30..' ["minecraft:emerald_ore"] = 10,\n'
31..' ["bno:ore_netheremerald"] = 10,\n'
32..' ["openblocks:grave"] = 9001,\n'
33..' ["minecraft:end_portal_frame"] = 20,\n'
34..'}\n'
35..'\n'
36..'local colours = {\n'
37..' ["minecraft:emerald_ore"] = { 0, 255, 0 },\n'
38..' ["bno:ore_netheremerald"] = { 0, 255, 0 },\n'
39..' ["openblocks:grave"] = {255,255,255},\n'
40..' ["minecraft:end_portal_frame"] = {255,0,255}\n'
41..'}\n'
42..'\n'
43..'--- Now let's get into the interesting stuff! Let's look for a neural interface and check we've got all the required\n'
44..'--- modules.\n'
45..'local modules = peripheral.find("neuralInterface")\n'
46..'if not modules then error("Must have a neural interface", 0) end\n'
47..'if not modules.hasModule("plethora:scanner") then error("The block scanner is missing", 0) end\n'
48..'if not modules.hasModule("plethora:glasses") then error("The overlay glasses are missing", 0) end\n'
49..'\n'
50..'--- Now we've got our neural interface, let's extract the canvas and ensure nothing else is on it.\n'
51..'local canvas = modules.canvas()\n'
52..'canvas.clear()\n'
53..'\n'
54..'--- We now need to set up our minimap. We create a 2D array of text objects around the player, each starting off\n'
55..'--- displaying an empty string. If we find an ore, we'll update their colour and text.\n'
56..'local block_text = {}\n'
57..'local blocks = {}\n'
58..'for x = -scannerRange, scannerRange, 1 do\n'
59..' block_text[x] = {}\n'
60..' blocks[x] = {}\n'
61..'\n'
62..' for z = -scannerRange, scannerRange, 1 do\n'
63..' block_text[x][z] = canvas.addText({ 0, 0 }, " ", 0xFFFFFFFF, size)\n'
64..' blocks[x][z] = { y = nil, block = nil }\n'
65..' end\n'
66..'end\n'
67..'\n'
68..'--- We also create a marker showing the current player's location.\n'
69..'canvas.addText({ offsetX, offsetY }, "^", 0xFFFFFFFF, size * 2)\n'
70..'\n'
71..'--- Our first big function is the scanner: this searches for ores near the player, finds the most important ones, and\n'
72..'--- updates the block table.\n'
73..'local function scan()\n'
74..' while true do\n'
75..' local scanned_blocks = modules.scan()\n'
76..'\n'
77..' --- For each nearby position, we search the y axis for interesting ores. We look for the one which has\n'
78..' --- the highest priority and update the block information\n'
79..' for x = -scannerRange, scannerRange do\n'
80..' for z = -scannerRange, scannerRange do\n'
81..' local best_score, best_block, best_y = -1\n'
82..' for y = -scannerRange, scannerRange do\n'
83..' --- The block scanner returns blocks in a flat array, so we index into it with this rather scary formulae.\n'
84..' local scanned = scanned_blocks[scannerWidth ^ 2 * (x + scannerRange) + scannerWidth * (y + scannerRange) + (z + scannerRange) + 1]\n'
85..'\n'
86..' --- If there is a block here, and it's more interesting than our previous ores, then let's use that!\n'
87..' if scanned then\n'
88..' local new_score = ores[scanned.name]\n'
89..' if new_score and new_score > best_score then\n'
90..' best_block = scanned.name\n'
91..' best_score = new_score\n'
92..' best_y = y\n'
93..' end\n'
94..' end\n'
95..' end\n'
96..'\n'
97..' -- Update our block table with this information.\n'
98..' blocks[x][z].block = best_block\n'
99..' blocks[x][z].y = best_y\n'
100..' end\n'
101..' end\n'
102..'\n'
103..' --- We wait for some delay before starting again. This isn't _strictly_ needed, but helps reduce server load\n'
104..' sleep(scanInterval)\n'
105..' end\n'
106..'end\n'
107..'\n'
108..'--- The render function takes our block information generated in the previous function and updates the text elements.\n'
109..'local function render()\n'
110..' while true do\n'
111..' --- If possible, we rotate the map using the current player's look direction. If it's not available, we'll just\n'
112..' --- use north as up.\n'
113..' local meta = modules.getMetaOwner and modules.getMetaOwner()\n'
114..' local angle = meta and math.rad(-meta.yaw % 360) or 0\n'
115..'\n'
116..' --- Like before, loop over every nearby block and update something. Though this time we're updating objects on\n'
117..' --- the overlay canvas.\n'
118..' for x = -scannerRange, scannerRange do\n'
119..' for z = -scannerRange, scannerRange do\n'
120..' local text = block_text[x][z]\n'
121..' local block = blocks[x][z]\n'
122..'\n'
123..' if block.block then\n'
124..' --- If we've got a block here, we update the position of our text element to account for rotation,\n'
125..' local px = math.cos(angle) * -x - math.sin(angle) * -z\n'
126..' local py = math.sin(angle) * -x + math.cos(angle) * -z\n'
127..'\n'
128..' local sx = math.floor(px * size * cellSize)\n'
129..' local sy = math.floor(py * size * cellSize)\n'
130..' text.setPosition(offsetX + sx, offsetY + sy)\n'
131..'\n'
132..' --- Then change the text and colour to match the location of the ore\n'
133..' text.setText(tostring(block.y))\n'
134..' text.setColor(table.unpack(colours[block.block]))\n'
135..' else\n'
136..' --- Otherwise we just make sure the text is empty. We don't need to faff about with clearing the\n'
137..' --- colour or position, as we'll change it next iteration anyway.\n'
138..' text.setText(" ")\n'
139..' end\n'
140..' end\n'
141..' end\n'
142..'\n'
143..' sleep(renderInterval)\n'
144..' end\n'
145..'end\n'
146..'\n'
147..'--- We now run our render and scan loops in parallel, continually updating our block list and redisplaying it to the\n'
148..'--- wearer.\n'
149..'parallel.waitForAll(render, scan)\n'
150)
151NF.close()
152end
153
154
155
156
157
158InstallDir = ...
159if InstallDir == nil then InstallDir = '/' end
160term.clear()
161term.setCursorPos(1,1)
162print('Do you wish to install Packager? (Y/N)')
163local x = read()
164
165if x == 'y' or x == 'Y' then
166local NF = fs.open(InstallDir..'/Packager','w')
167NF.write(''
168..'Args = {...}\n'
169..'if type(Args[1]) ~= "string" or type(Args[2]) ~= "string" or type(Args[3]) ~= "string" then\n'
170..' error("Arguments: <DirToCombine> <DefaultInstallDir> <OutputFileName>")\n'
171..'end\n'
172..'if fs.exists(Args[1]) ~= true then error("Directory is non-existent.") end\n'
173..'if fs.exists(Args[3]) == true then error("File already exists") end\n'
174..'List = fs.list(Args[1])\n'
175..'z = fs.open(Args[3],"w")\n'
176..'for i = 1, #List do\n'
177..' z.writeLine("InstallDir = ...")\n'
178..' z.writeLine("if InstallDir == nil then InstallDir = '"..Args[2].."' end")\n'
179..' z.writeLine("term.clear()")\n'
180..' z.writeLine("term.setCursorPos(1,1)")\n'
181..' z.writeLine("print('Do you wish to install "..List[i].."? (Y/N)')")\n'
182..' z.writeLine("local x = read()")\n'
183..' z.writeLine("")\n'
184..' z.writeLine("if x == 'y' or x == 'Y' then")\n'
185..' z.writeLine("local NF = fs.open(InstallDir..'/"..List[i].."','w')")\n'
186..' F = fs.open(Args[1].."/"..List[i],"r")\n'
187..' z.writeLine("NF.write(''")\n'
188..' repeat\n'
189..' Lin = F.readLine()\n'
190..' if Lin ~= nil then\n'
191..' z.writeLine("..'"..Lin.."\\n'")\n'
192..' end\n'
193..' until Lin == nil\n'
194..' z.writeLine(")")\n'
195..' F.close()\n'
196..' z.writeLine("NF.close()")\n'
197..' z.writeLine("end")\n'
198..' for i = 1,5 do\n'
199..' z.writeLine("")\n'
200..' end\n'
201..'end\n'
202..'z.close()\n'
203)
204NF.close()
205end
206
207
208
209
210
211InstallDir = ...
212if InstallDir == nil then InstallDir = '/' end
213term.clear()
214term.setCursorPos(1,1)
215print('Do you wish to install cht.lua? (Y/N)')
216local x = read()
217
218if x == 'y' or x == 'Y' then
219local NF = fs.open(InstallDir..'/cht.lua','w')
220NF.write(''
221..'rednet.open("front")\n'
222..'CH = peripheral.wrap("back")\n'
223..'Token = "aa679-23b"\n'
224..'Info = {}\n'
225..'CH.capture("![Oo]pen")\n'
226..'CH.capture("![Cc]lose")\n'
227..'while true do\n'
228..' _, Info[1], Info[3], Info[2], Info[4] = os.pullEvent("chat_capture")\n'
229..' if Info[3] == "![Oo]pen" then\n'
230..' rednet.send(27,{Token,Info[4],"Pos"})\n'
231..' print("Sent")\n'
232..' end\n'
233..' if Info[3] == "![Cc]lose" then\n'
234..' rednet.send(27,{Token,Info[4],"Neg"})\n'
235..' print("Sent")\n'
236..' end\n'
237..' ID, MSG = rednet.receive(10)\n'
238..' if MSG == "Yote" then\n'
239..' CH.tell("Hyeh")\n'
240..' end\n'
241..' sleep(1)\n'
242..' print(Info[3])\n'
243..'end\n'
244)
245NF.close()
246end
247
248
249
250
251
252InstallDir = ...
253if InstallDir == nil then InstallDir = '/' end
254term.clear()
255term.setCursorPos(1,1)
256print('Do you wish to install pwr? (Y/N)')
257local x = read()
258
259if x == 'y' or x == 'Y' then
260local NF = fs.open(InstallDir..'/pwr','w')
261NF.write(''
262..'rednet.open("front")\n'
263..'local V = peripheral.wrap("back").canvas()\n'
264..'local T = {}\n'
265..'local CRF = 0\n'
266..'local MRF = 0\n'
267..'local RCRF = 0\n'
268..'local RMRF = 0\n'
269..'local ID = "NA"\n'
270..'V.clear()\n'
271..'local BOX = V.addRectangle(2+353,2+270,154,14,0x777777FF)\n'
272..'local BX2 = V.addRectangle(3+353,3+270,152,12,0x00ff0055)\n'
273..'local TXT = V.addText({5+353,5+270},"")\n'
274..'function hecc()\n'
275..' ID, T = rednet.receive(1)\n'
276..' CRF = T[1]\n'
277..' MRF = T[2]\n'
278..' RCRF = T[3]\n'
279..' RMRF = T[4]\n'
280..' BX2.setSize(152*(RCRF/RMRF),12)\n'
281..' PCT = (math.floor(RCRF/RMRF*10000)/100)\n'
282..' if math.floor(PCT*10)/10 == PCT and math.floor(PCT) ~= PCT then\n'
283..' PCT = PCT.."0"\n'
284..' elseif math.floor(PCT) == PCT then\n'
285..' PCT = PCT..".00"\n'
286..' end\n'
287..' TXT.setText(CRF.."/"..MRF.." "..PCT.."%")\n'
288..' TXT.setColor(0x77ff00ff)\n'
289..'end\n'
290..'while true do\n'
291..' pcall(hecc)\n'
292..'end\n'
293)
294NF.close()
295end
296
297
298
299
300
301InstallDir = ...
302if InstallDir == nil then InstallDir = '/' end
303term.clear()
304term.setCursorPos(1,1)
305print('Do you wish to install rom? (Y/N)')
306local x = read()
307
308if x == 'y' or x == 'Y' then
309local NF = fs.open(InstallDir..'/rom','w')
310NF.write(''