Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Unloader Controller
- function manyInputAnd(...)
- local tArgs = {...}
- if type(tArgs[1]) == "table" then
- tArgs = tArgs[1]
- end
- local length = 0
- for i,v in pairs(tArgs) do
- print("AND Parameter "..i..": "..tostring(v))
- length = length +1
- end
- local truths = 0
- for i,v in pairs(tArgs) do
- --[[
- if match ~= nil and type(v) == "number" then
- end
- ]]
- if (type(v) == "boolean" and v == true) or (type(v) == "number" and v > 0) then
- print("Truth found")
- truths = truths + 1
- end
- end
- if truths == length and length > 0 then
- return true
- else
- return false
- end
- end
- function pulser(output, outputSide, highDelay, lowDelay)
- if lowDelay == nil then
- lowDelay = highDelay
- end
- local signal = output
- local antiSignal = not output
- local command = redstone.setOutput
- if type(output) == "number" then
- command = redstone.setBundledOutput
- antiSignal = redstone.getBundledOutput(outputSide)
- signal = antiSignal + output
- end
- command(outputSide, signal)
- sleep(highDelay)
- command(outputSide, antiSignal)
- sleep(lowDelay)
- end
- function trainLoop(l)
- sleep(10)
- if l == 0 then
- pulser(true, "top", 5, 0)
- return
- end
- local looping = true
- while looping do
- local t = {}
- for i = 1,l do
- print("Testing for: "..2^(i-1))
- local v = redstone.testBundledInput("bottom", 2^(i-1))
- table.insert(t,i,v)
- end
- if manyInputAnd(t) then
- print("Unloader Work Finished")
- redstone.setOutput("top", true)
- pulser(true, "top", 3, 0)
- looping = false
- else
- sleep(5)
- end
- end
- end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("Unloader Manager")
- os.pullEvent("redstone")
- local input = redstone.getBundledInput("bottom")
- local trainLength
- local cartNumber
- if input >= colors.cyan then
- trainLength = 7
- cartNumber = 5
- elseif input >= colors.lightGray then
- trainLength = 6
- cartNumber = 4
- elseif input >= colors.gray then
- trainLength = 5
- cartNumber = 3
- elseif input >= colors.pink then
- trainLength = 4
- cartNumber = 2
- elseif input >= colors.lime then
- trainLength = 3
- cartNumber = 1
- else
- trainLength = 0
- cartNumber = "0 - Letting Locomotive Passthrough"
- end
- print("Train has arrived.")
- print("Chest Carts Detected: "..cartNumber)
- trainLoop(cartNumber)
- print("Goodbye Train")
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment