View difference between Paste ID: U6W5tF29 and 02E1jUGa
SHOW: | | - or go back to the newest paste.
1
function ClearPages()
2-
sen = sensor.wrap("right")
2+
    sleep(0.5)
3-
mon = peripheral.wrap("top")
3+
    redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.black))
4-
state = false
4+
    sleep(0.5)
5
    redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.black))
6-
mon.setTextScale(1)
6+
    sleep(2)
7-
mon.clear()
7+
8
9
function ResetSignals()
10-
function formatNumber(number)
10+
    sleep(0.5)
11-
    local formatted = tostring(number)
11+
    redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.orange))
12-
    local k = #formatted % 3
12+
    sleep(0.5)
13-
    if k == 0 then k = 3 end
13+
    redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.blue))
14-
    local result = formatted:sub(1, k)
14+
15-
    while k < #formatted do
15+
   
16-
        result = result .. "." .. formatted:sub(k + 1, k + 3)
16+
function RequestItems()
17-
        k = k + 3
17+
    -- CONSTANTS
18
    local PIPE_SIDE = "right"
19-
    return result
19+
 
20
    -- IMPLEMENTATION
21
    function convertNBT(nbt)
22
        local conv = {}
23-
x = 0
23+
        if (nbt == nil) then
24
            return nil
25-
	s = sen.getTargets()
25+
        elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
26-
	function getS()
26+
            for key, value in pairs(nbt["value"]) do
27-
		for v, k  in pairs(s) do
27+
                conv[key] = convertNBT(value)
28-
			if k.Name == "ME Wireless Access Point" then   
28+
29-
				target = v
29+
        else
30-
			end
30+
            conv = nbt["value"]
31-
		end
31+
32-
		return target
32+
        return conv
33-
	end
33+
34
 
35-
	f = getS()
35+
    function getItems(pipe)
36-
	s1 = sen.getTargetDetails(target)
36+
        pipe.getAvailableItems()
37
        local event, result = os.pullEvent("available_items_return")
38-
	for v, k in pairs(s1.Items) do
38+
        return result
39-
        mon.setTextColor(colors.yellow)
39+
40-
   		if k.Name == "Low Voltage Solar Array" then
40+
 
41-
        	if state == false then
41+
    function inList(item)
42-
            	lv1 = k.Size
42+
        local id = item.id
43-
                print("LV Rechenwert 1: "..lv1)
43+
        local dmg = item.dmg
44-
        	elseif state == true then
44+
        local idKey = tostring(id)
45-
            	lv2 = k.Size	
45+
        local exists, requestAmount = false, 0
46-
                print("LV IstWert 2:    "..lv2)
46+
 
47-
   				calc = (lv2 - lv1) * 6			--LVs pro Minute
47+
        if REQUEST_IDS[id] then
48-
				calc2 = calc * 60				--LVs pro Stunde
48+
            if type(REQUEST_IDS[id]) == "table" then
49-
                
49+
                local variantKey = idKey .. ":" .. tostring(dmg)
50-
                fN1 = formatNumber(calc)
50+
                if REQUEST_IDS[id][variantKey] then
51-
				fN2 = formatNumber(calc2)
51+
                    exists = true
52-
                fN3 = formatNumber(lv2)
52+
                    requestAmount = REQUEST_IDS[id][variantKey]
53-
                if calc >= 0 then
53+
54-
					mon.setCursorPos(2,2)
54+
            else
55-
    				mon.write("LV Solars/m:   "..fN1 .."                ")
55+
                exists = true
56-
                else
56+
                requestAmount = REQUEST_IDS[id]
57-
					mon.setCursorPos(2,2)
57+
58-
    				mon.write("LV Solars/m:   0                         ")                    
58+
59
 
60-
                if calc2 >= 0 then
60+
        return exists, requestAmount
61-
					mon.setCursorPos(2,3)
61+
62-
    				mon.write("LV Solars/h:   "..fN2 .."                ")
62+
 
63-
                else
63+
    -- MAIN
64-
					mon.setCursorPos(2,3)
64+
    local pipe = peripheral.wrap(PIPE_SIDE)
65-
    				mon.write("LV Solars/h:   0                         ")                    
65+
    for i, result in pairs(getItems(pipe)) do
66
        local iid, amount = unpack(result)
67-
                mon.setCursorPos(2,8)
67+
        local item = {
68-
                mon.write("LVs on stock:  "..fN3 .."                ")
68+
            id = pipe.getItemID(iid),
69-
        	else
69+
            dmg = pipe.getItemDamage(iid),
70-
            	print("Error(1)")
70+
            nbt = convertNBT(pipe.getNBTTagCompound(iid))
71-
        	end
71+
        }
72
        local exists, requestAmount = inList(item)
73-
		elseif k.Name == "UU-Matter" then
73+
        if exists then
74-
        	if state == false then
74+
            pipe.makeRequest(iid, requestAmount)
75-
           		uu1 = k.Size
75+
            sleep(sle)
76-
                print("UU Rechenwert 1: "..uu1)
76+
77-
        	elseif state == true then
77+
78-
            	uu2 = k.Size
78+
79-
                print("UU IstWert 2:    "..uu2)
79+
80-
   				calc = (uu2 - uu1) * 6
80+
---------------------------------------------------------
81-
   				calc2 = calc * 60
81+
function RequestPage1()
82-
                
82+
    REQUEST_IDS = {
83-
                fN4 = formatNumber(calc)
83+
        [900] = {       
84-
				fN5 = formatNumber(calc2)
84+
            ["900:2"] = 16,         --16x Controller
85-
                fN6 = formatNumber(uu2)
85+
            ["900:6"] = 16,     	--16x Access Terminal
86-
                if calc >= 0 then
86+
            ["900:5"] = 16,        	--16x Wireless Access Point
87-
					mon.setCursorPos(2,5)
87+
            ["900:7"] = 16,     	--16x ME Chest
88-
    				mon.write("UU-Matter/m:   "..fN4 .."                ")
88+
            ["900:8"] = 16,     	--16x Interface
89-
                else
89+
            ["900:1"] = 16,     	--16x Pattern Provider
90-
					mon.setCursorPos(2,5)
90+
        },
91-
    				mon.write("UU-Matter/m:   0                         ")  
91+
    }
92
    RequestItems()  
93-
                if calc2 >= 0 then
93+
    sleep(0.2)
94-
					mon.setCursorPos(2,6)
94+
    REQUEST_IDS = {
95-
    				mon.write("UU-Matter/h:   "..fN5 .."                ")
95+
        [901] = {   
96-
                else
96+
            ["901:3"] = 16,     	--16x Crafting Terminal
97-
					mon.setCursorPos(2,6)
97+
            ["901:12"] = 16,        --16x Storage Monitor
98-
    				mon.write("UU-Matter/h:   0                         ")  
98+
            ["901:11"] = 16,     	--16x Crafting Monitor
99
            ["901:10"] = 16,     	--16x IO Port
100-
                mon.setCursorPos(2,10)
100+
            ["901:6"] = 16,     	--16x Heat Vent
101-
                mon.write("UU on stock:   "..fN6 .."                ")
101+
            ["901:7"] = 16,     	--16x Containment Wall
102-
        	else
102+
            ["901:5"] = 16,     	--16x Crafting CPU
103-
            	print("Error(1)")
103+
            ["901:4"] = 16,     	--16x Level Emitter
104-
        	end
104+
            ["901:9"] = 16,     	--16x Storage Bus
105-
        elseif k.Name == "High Voltage Solar Array" then
105+
            ["901:1"] = 16,     	--16x Import Bus
106-
            if state == true then
106+
            ["901:0"] = 16,     	--16x Export Bus
107-
                hv = k.Size
107+
            ["901:13"] = 16,     	--16x ME Cable
108-
                print("HV IstWert:      "..hv)
108+
        },
109-
                
109+
    }
110-
                fN7 = formatNumber(hv)
110+
    RequestItems() 
111-
				
111+
    sleep(0.2)
112-
                mon.setCursorPos(2,9)
112+
    REQUEST_IDS = {
113-
                mon.write("HVs on stock:  "..fN7 .."                ")
113+
        [900] = {   
114
            ["900:0"] = 64,     	--64x ME Cable Blau
115
            ["900:10"] = 64,     	--64x ME Cable Schwarz
116-
	end
116+
            ["900:11"] = 64,     	--64x ME Cable Weis
117-
 	if state == true then
117+
            ["900:12"] = 64,     	--64x ME Cable Braun
118-
   		state = false
118+
            ["900:13"] = 64,     	--64x ME Cable Rot
119-
        for i = 20,11,-1 do
119+
            ["900:14"] = 64,     	--64x ME Cable Gelb
120-
            mon.setTextColor(colors.lightGray)
120+
            ["900:15"] = 64,     	--64x ME Cable GråBCn
121-
            if i <= 9 then 
121+
        },
122-
                mon.setCursorPos(18,12)
122+
    }
123-
                mon.write("reboot in:  "..i)
123+
    RequestItems()
124
end
125-
            mon.setCursorPos(17,12)
125+
---------------------------------------------------------
126-
            mon.write("reboot in: "..i)
126+
function RequestPage2()
127-
            sleep(1)
127+
    REQUEST_IDS = {
128
        [246] = {   
129-
        print(" ")
129+
            ["246:3"] = 60,     	--60x Solar Panel
130-
        print("Neue Berechnung gestartet:")
130+
        },
131-
 	else
131+
    }
132-
   		state = true
132+
    RequestItems() 
133-
        for i = 10,1,-1 do
133+
    REQUEST_IDS = {
134-
            mon.setTextColor(colors.lightGray)
134+
        [183] = {
135-
            if i <= 9 then 
135+
            ["183:0"] = 60,         --60x LV Solar Panel
136-
                mon.setCursorPos(18,12)
136+
            ["183:1"] = 60,         --60x MV Solar Panel
137-
                mon.write("reboot in:  "..i)
137+
            ["183:2"] = 60,         --60x HV Solar Panel
138
        },
139-
            mon.setCursorPos(17,12)
139+
    }
140-
            mon.write("reboot in: "..i)
140+
    RequestItems()
141-
            sleep(1)
141+
    sleep(0.2)
142-
      	end
142+
    REQUEST_IDS = {
143-
      x = x + 1
143+
        [750] = {
144-
      if x == 20 then
144+
            ["750:1280"] = 60,      --60x Blue Alloy Wire
145-
        os.reboot()
145+
            ["750:1281"] = 60,      --60x 10kV Wire
146-
      end
146+
            ["750:16913"] = 60,     --60x Jacketed Bluewire
147-
 	end
147+
        },
148
    }
149
    RequestItems()
150
    sleep(0.2)
151
    REQUEST_IDS = {
152
        [2050] = {   
153
            ["2050:14"] = 32,     	--32x Lead Wire
154
            ["2050:15"] = 32,     	--32x Furnace Heater
155
        },
156
    }
157
    RequestItems() 
158
    sleep(0.2)
159
    REQUEST_IDS = {
160
        [30184] = {
161
            ["30184:0"] = 60,      	--60x Copper Cable
162
            ["30184:4"] = 60,      	--60x 2x Ins. Gold Cable
163
            ["30184:9"] = 60,     	--60x Glass Fibre Cable
164
        },
165
    }
166
    RequestItems()
167
    REQUEST_IDS = {
168
        [227] = {   
169
            ["227:0"] = 10,     	--10x Bat Box
170
            ["227:1"] = 10,     	--10x MFE
171
            ["227:2"] = 10,     	--10x MFSU
172
            ["227:3"] = 10,     	--10x LV Transformer
173
            ["227:4"] = 10,     	--10x MV Transformer
174
            ["227:5d"] = 10,     	--10x HV Transformer
175
        },
176
    }
177
    RequestItems()
178
    sleep(0.2)
179
    REQUEST_IDS = {
180
        [2006] = {	["2006:0"] = 32  },   	--32x Redstone Energy Conduit	
181
        [4320] = {  ["4320:0"] = 32  },  	--32x Wooden Conductice Pipe
182
        [4324] = {  ["4324:0"] = 32  },   	--32x Golden Conductice Pipe
183
    }
184
    RequestItems() 
185
end
186
---------------------------------------------------------
187
function RequestPage3()
188
    REQUEST_IDS = {
189
        [207] = {   
190
           	["207:0"] = 5,     		--5x Computer
191
            ["207:16384"] = 5,     	--5x Adv. Computer
192
        },
193
    }
194
    RequestItems() 
195
    REQUEST_IDS = {
196
        [209] = {   ["209:0"] = 5  },   		--5x Turtle
197
        [900] = {   ["900:5"] = 5  },   		--5x Wireless Access Point
198
        [3893] = {  ["3893:0"] = 5  },   		--5x Sensor Peripheral
199
        [750] = {   ["750:256"] = 5  },   		--5x Red Alloy Wire
200
    }
201
    RequestItems()
202
    sleep(0.2)
203
    REQUEST_IDS = {
204
        [7742] = {
205
            ["7742:17"] = 2,          --2x Proximity Sensor Card Mk1
206
            ["7742:33"] = 2,          --2x Proximity Sensor Card Mk2
207
            ["7742:49"] = 2,          --2x Proximity Sensor Card Mk3
208
            ["7742:65"] = 2,          --2x Proximity Sensor Card Mk4
209
            ["7742:83"] = 2,          --2x Applied Energystics Sensor Card Mk1
210
            ["7742:99"] = 2,          --2x Applied Energystics Sensor Card Mk2
211
            ["7742:151"] = 2,         --2x Applied Energystics Sensor Card Mk3
212
            ["7742:131"] = 2,         --2x Applied Energystics Sensor Card Mk4
213
        },
214
    }
215
    RequestItems()
216
end
217
---------------------------------------------------------
218
function RequestPage4()
219
    sle = 0.2
220
    REQUEST_IDS = {
221
        [1] = {   	["1:0"] = 192  		},   		--
222
        [2] = {   	["2:0"] = 192  		},   		--
223
        [3] = {   	["3:0"] = 192  		},   		--
224
        [13] = {   	["13:0"] = 64  		},   		--
225
        [9] = {   	["9:0"] = 64  		},   		--
226
        [11] = {   	["11:0"] = 64  		},   		--
227
        [17] = {   	["17:0"] = 64		},   		--
228
        
229
		[24] = {   	["24:0"] = 64  		},   		--
230
        [24] = {   	["24:1"] = 64  		},   		--
231
        
232
        [128] = {   ["128:0"] = 64  	},   		--       
233
        [89] = {   	["89:0"] = 64  		},   		--
234
        [85] = {   	["85:0"] = 64  		},   		--      
235
        [3133] = { 	["3133:4"] = 192  	},   		--
236
        [45] = {   	["45:0"] = 64  		},   		--
237
        [20] = {   	["20:0"] = 64  		},   		--
238
        [80] = {   	["80:0"] = 128  	},   		--
239
        
240
        [98] = {   	["98:0"] = 128  	},	   		--
241
        [98] = {   	["98:3"] = 64  		},   		--
242
        
243
        [44] = {   	["44:0"] = 64 		},  		--
244
        [44] = {   	["44:1"] = 64  		},   		--
245
        
246
        [43] = {   	["43:0"] = 64 		},	   		--
247
        [43] = {   	["43:7"] = 64  		},   		--
248
        }
249
        RequestItems()
250
    	REQUEST_IDS = {
251
        [255] = {   ["255:0"] = 64  	},		   	--
252
        }
253
        RequestItems()
254
    	REQUEST_IDS = {
255
        [255] = {   ["255:1"] = 64  	},		   	--
256
        }
257
        RequestItems()
258
    	REQUEST_IDS = {
259
        [255] = {   ["255:2"] = 64  	},		   	--
260
        }
261
        RequestItems()
262
    	REQUEST_IDS = {
263
        [255] = {   ["255:6"] = 64  	},   		--  
264
    }
265
    RequestItems()
266
    sleep(1)
267
end
268
---------------------------------------------------------
269
function RequestPage5()
270
271
end
272
function RequestPage6()
273
274
end
275
function RequestPage7()
276
277
end
278
function RequestPage8()
279
280
end
281
function RequestPage9()
282
283
end
284
285
286
287
288
289
290
291
------------------------Program Start------------------------
292
293
sle = 0.1 --Sleep zwischen jeder Request
294
os.loadAPI("ocs/apis/sensor")
295
sen = sensor.wrap("bottom")
296
redstone.setBundledOutput("back",colors.combine(redstone.getBundledOutput("back"), colors.orange)) 	--orange an
297
sleep(0.5)
298
redstone.setBundledOutput("back",colors.subtract(redstone.getBundledOutput("back"), colors.blue))	--blau aus
299
300
while true do
301
    s = sen.getTargets()
302
    function getS()
303
        for v, k  in pairs(s) do
304
            if k.Name == "ME Wireless Access Point" then   
305
                target = v
306
            end
307
        end
308
        return target
309
    end
310
 
311
    f = getS()
312
    s1 = sen.getTargetDetails(target)
313
    
314
    local Page1 = 0
315
    local Page2 = 0
316
    local Page3 = 0
317
    local Page4 = 0
318
    local Page5 = 0
319
    local Page6 = 0
320
    local Page7 = 0
321
    local Page8 = 0
322
    local Page9 = 0
323
 
324
    for _, item in pairs(s1.Items) do
325
        --print(item.Name)
326
        --sleep(2)
327
        if item.Name == "ME Wireless Access Terminal" then
328
            Page1 = item.Size -- Werte ermittels und setzen
329
        end
330
        if item.Name == "Advanced Solar Panel" then
331
            Page2 = item.Size -- Werte ermittels und setzen
332
        end
333
        if item.Name == "Remote Orderer" then
334
            Page3 = item.Size -- Werte ermittels und setzen
335
        end
336
        if item.Name == "Cobblestone" then
337
            Page4 = item.Size -- Werte ermittels und setzen
338
        end
339
        if item.Name == "tile.machineBlock" then
340
            Page5 = item.Size -- Werte ermittels und setzen
341
        end
342
        if item.Name == "item.PipeItemsDiamond" then
343
            Page6 = item.Size -- Werte ermittels und setzen
344
        end
345
        if item.Name == "Electric Furnace" then
346
            Page7 = item.Size -- Werte ermittels und setzen
347
        end
348
        if item.Name == "Clay Dust" then
349
            Page8 = item.Size -- Werte ermittels und setzen
350
        end
351
        if item.Name == "Wooden Axe" then
352
            Page9 = item.Size -- Werte ermittels und setzen
353
        end
354
        if item.Size < 0 then
355
        	os.reboot()
356
    	end
357
    end
358
    
359
    term.setCursorPos(1,1)
360
    term.clear()
361
    print("1: "..Page1)
362
    print("2: "..Page2)
363
    print("3: "..Page3)
364
    print("4: "..Page4)
365
    print("5: "..Page5)
366
    print("6: "..Page6)
367
    print("7: "..Page7)
368
    print("8: "..Page8)
369
    print("9: "..Page9)
370
    
371
    reboot = 1
372
    if Page1 < 1 or Page2 < 1 or Page3 < 1 or Page4 < 1 then
373
        ResetSignals()
374
        ClearPages()
375
        reboot = 0
376
    end
377
    
378
    if Page1 < 1 then
379
        RequestPage1()
380
   	elseif Page2 < 1 then
381
        RequestPage2()
382
    elseif Page3 < 1 then
383
        RequestPage3()
384
    elseif Page4 < 1 then
385
        RequestPage4()
386
    end
387
	
388
    if reboot == 0 then
389
    	os.reboot()
390
    end
391
    sleep(1)
392
end