SHOW:
|
|
- or go back to the newest paste.
| 1 | - | slaveName = "5" |
| 1 | + | slaveName = "5" -- number of button to assign to |
| 2 | masterID = 0 | |
| 3 | - | outputBool = false |
| 3 | + | outputBool = false -- default (off) state of redstone power for spawner, false means off |
| 4 | masterActive = false | |
| 5 | lastmessage = "foo" -- meaningless message | |
| 6 | ||
| 7 | - | pID = pID or -1 |
| 7 | + | |
| 8 | - | if pID == -1 then |
| 8 | + | if message == "KKRNBTNMaster" then |
| 9 | - | while true do |
| 9 | + | rednet.send(pID, slaveName) |
| 10 | - | id, message = rednet.receive() |
| 10 | + | masterID = pID |
| 11 | - | if message == "KKRNBTNMaster" then |
| 11 | + | print("Discovered Master with ID: " .. pID)
|
| 12 | - | rednet.send(id, slaveName) |
| 12 | + | return true |
| 13 | - | masterID = id |
| 13 | + | end |
| 14 | - | print("Discovered Master with ID: " .. id)
|
| 14 | + | |
| 15 | - | return true |
| 15 | + | |
| 16 | - | end |
| 16 | + | |
| 17 | function testMessage() | |
| 18 | id, message = rednet.receive() | |
| 19 | - | if message == "KKRNBTNMaster" then |
| 19 | + | |
| 20 | - | rednet.send(pID, slaveName) |
| 20 | + | |
| 21 | - | masterID = pID |
| 21 | + | |
| 22 | - | print("Discovered Master with ID: " .. pID)
|
| 22 | + | |
| 23 | - | return true |
| 23 | + | |
| 24 | - | end |
| 24 | + | |
| 25 | else | |
| 26 | if message ~= lastmessage then | |
| 27 | masterActive = false | |
| 28 | end | |
| 29 | if not masterActive then | |
| 30 | testMaster(id, message) | |
| 31 | masterActive = true | |
| 32 | lastmessage = message | |
| 33 | end | |
| 34 | end | |
| 35 | end | |
| 36 | ||
| 37 | function setRedstone(state) | |
| 38 | print("Setting Redstone to: " .. tostring(state))
| |
| 39 | redstone.setOutput("back", state)
| |
| 40 | - | if testMaster(id, message) and not masterActive then |
| 40 | + | |
| 41 | ||
| 42 | setRedstone(outputBool) | |
| 43 | ||
| 44 | rednet.open("top")
| |
| 45 | ||
| 46 | while true do | |
| 47 | testMessage() | |
| 48 | end |