Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RADIO="top"
- BUNDLE="back"
- mobs = {}
- mobs["creaper"] = colors.green
- mobs["skeleton"] = colors.white
- mobs["pigmen"] = colors.yellow
- controller = nil
- function colorOn(color)
- local c = redstone.getBundledOutput(BUNDLE)
- c = colors.combine(c, color)
- redstone.setBundledOutput(BUNDLE, c)
- end
- function colorOff(color)
- local c = redstone.getBundledOutput(BUNDLE)
- c = colors.subtract(c, color)
- redstone.setBundledOutput(BUNDLE, c)
- end
- function colorToggle(color)
- local c = redstone.getBundledOutput(BUNDLE)
- if colors.test(c, color) then
- c = colors.subtract(c, color)
- else
- c = colors.combine(c, color)
- end
- redstone.setBundledOutput(BUNDLE, c)
- end
- function colorAllOn()
- redstone.setBundledOutput(BUNDLE, 65535)
- end
- function processMessage(data)
- if data["action"] == "acknowledge" or (data["action"] == "announce" and data["device"] == "controller") then
- controller = data["computer_id"]
- if data["action"] == "announce" then
- rednet.send(data["computer_id"], textutils.serialize({action="acknowledge", type="multimob", device="roof"}))
- end
- elseif data["action"] == "mobon" then
- colorAllOn()
- if mobs[data["mob"]] ~= nil then
- colorOff(mobs[data["mob"]])
- end
- elseif data["action"] == "off" then
- colorAllOn()
- end
- end
- colorAllOn()
- if peripheral.isPresent(RADIO) and peripheral.getType(RADIO) == "modem" then
- rednet.open(RADIO)
- rednet.broadcast(textutils.serialize({action="announce", type="multimob", device="roof"}))
- else
- print("Modem not found")
- return
- end
- while true do
- ev,p1,p2,p3 = os.pullEvent()
- if ev == "rednet_message" then
- data = textutils.unserialize(p2)
- if data["type"] == "multimob" then
- data["computer_id"] = p1
- processMessage(data)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement