Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Blueshop item chute controller
- -- TX = 0, RX = (Number of items)
- -- TX = (Number of items), RX = (0 if OK, 1 if stock too low)
- local network = component.proxy(component.list("modem")())
- local redstone = component.proxy(component.list("redstone")())
- local strength = 255 -- 255 if using Project:Red, 15 if using Vanilla
- local stackSize = 64 -- How many items per stack, used by stock calculation
- local stock
- network.open(120) -- Ensure that the network card is open on chute port (120)
- redstone.setOutput(0, 0) -- Set a known state for the dispenser output
- network.broadcast(120, network.address) -- Broadcast address for master unit
- -- "modem_message" _ reply _ _ msg
- while true do
- local signal = table.pack(computer.pullSignal())
- if signal[1] == "modem_message" then -- New message over network
- if signal[6] == 0 then -- Request system stock
- network.send(signal[3], 120, checkStock())
- elseif signal[6] <= stock then -- Request dispenser fire
- for i = 1,signal[6],1 do
- computer.pullSignal(0.1) -- Avoid system timeout errors
- redstone.setOutput(0, strength) -- Best case 50% MSR, worst case 33% MSR
- os.sleep(0.1)
- redstone.setOutput(0, 0)
- os.sleep(0.1)
- end
- network.send(signal[3], 120, 0)
- else
- network.send(signal[3], 120, -1)
- end
- end
- end
- local function checkStock() -- Returns integer, containing lower-bound stock
- local strength = redstone.getInput(4)
- stock = math.ceil((stackSize * 54 / 14) * (strength - 1))
- return max(strength, stock)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement