View difference between Paste ID: N5wFUqSg and 6g4Aw0DT
SHOW: | | - or go back to the newest paste.
1
--Unloader Controller
2
3
function manyInputAnd(...)
4
	local tArgs = {...}
5
	if type(tArgs[1]) == "table" then
6
		tArgs = tArgs[1]
7
	end
8
	local length = 0
9
	for i,v in pairs(tArgs) do
10
		print("AND Parameter "..i..": "..tostring(v))
11
		length = length +1
12
	end
13
	local truths = 0
14
	for i,v in pairs(tArgs) do
15
	--[[
16
		if match ~= nil and type(v) == "number" then
17
			
18
		end	
19
	]]
20
		if (type(v) == "boolean" and v == true) or (type(v) == "number" and v > 0) then
21
			print("Truth found")
22
			truths = truths + 1
23
		end
24
	end
25
	if truths == length and length > 0 then
26
		return true
27
	else
28
		return false
29
	end
30
end
31
32
function pulser(output, outputSide, highDelay, lowDelay)
33
	if lowDelay == nil then
34
		lowDelay = highDelay
35
	end
36
	local signal = output
37
	local antiSignal = not output
38
	local command = redstone.setOutput
39
	if type(output) == "number" then
40
		command = redstone.setBundledOutput
41
		antiSignal = redstone.getBundledOutput(outputSide)
42
		signal = antiSignal + output
43
	end
44
	command(outputSide, signal)
45
	sleep(highDelay)
46
	command(outputSide, antiSignal)
47
	sleep(lowDelay)	
48
end
49
50
function trainLoop(l)
51
	sleep(10)
52
	if l == 0 then
53
		pulser(true, "top", 5, 0)
54
		return
55
	end
56
	local looping = true
57
	while looping do
58
		local t = {}
59
		for i = 1,l do
60
			print("Testing for: "..2^(i-1))
61
			local v = redstone.testBundledInput("bottom", 2^(i-1))
62
			table.insert(t,i,v)
63
		end
64
		if manyInputAnd(t) then
65
			print("Unloader Work Finished")
66
			redstone.setOutput("top", true)
67
			pulser(true, "top", 3, 0)
68
			looping = false
69
		else
70
			sleep(5)
71
		end			
72
	end
73
end
74
75
while true do
76
	term.clear()
77
	term.setCursorPos(1,1)
78
	print("Unloader Manager")
79
	os.pullEvent("redstone")
80
	local input = redstone.getBundledInput("bottom")
81
	local trainLength
82
	local cartNumber
83
	if input >= colors.cyan then
84
		trainLength = 7
85
		cartNumber = 5
86
	elseif input >= colors.lightGray then
87
		trainLength = 6
88
		cartNumber = 4
89
	elseif input >= colors.gray then
90
		trainLength = 5
91
		cartNumber = 3
92
	elseif input >= colors.pink then
93
		trainLength = 4
94
		cartNumber = 2
95
	elseif input >= colors.lime then
96
		trainLength = 3
97
		cartNumber = 1
98
	else
99
		trainLength = 0
100
		cartNumber = "0 - Letting Locomotive Passthrough"
101
	end
102
	print("Train has arrived.")
103
	print("Chest Carts Detected: "..cartNumber)
104
	trainLoop(cartNumber)
105
	print("Goodbye Train")
106
	sleep(5)
107
end