Advertisement
fremnet

MultiMobRoof

Mar 14th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. RADIO="top"
  2. BUNDLE="back"
  3.  
  4. mobs = {}
  5. mobs["creaper"]  = colors.green
  6. mobs["skeleton"] = colors.white
  7. mobs["pigmen"]   = colors.yellow
  8.  
  9. controller = nil
  10.  
  11. function colorOn(color)
  12.     local c = redstone.getBundledOutput(BUNDLE)
  13.     c = colors.combine(c, color)
  14.     redstone.setBundledOutput(BUNDLE, c)
  15. end
  16.  
  17. function colorOff(color)
  18.     local c = redstone.getBundledOutput(BUNDLE)
  19.     c = colors.subtract(c, color)
  20.     redstone.setBundledOutput(BUNDLE, c)
  21. end
  22.  
  23. function colorToggle(color)
  24.     local c = redstone.getBundledOutput(BUNDLE)
  25.     if colors.test(c, color) then
  26.         c = colors.subtract(c, color)
  27.     else
  28.         c = colors.combine(c, color)
  29.     end
  30.     redstone.setBundledOutput(BUNDLE, c)
  31. end
  32.  
  33. function colorAllOn()
  34.     redstone.setBundledOutput(BUNDLE, 65535)
  35. end
  36.  
  37. function processMessage(data)
  38.     if data["action"] == "acknowledge" or (data["action"] == "announce" and data["device"] == "controller") then
  39.         controller = data["computer_id"]
  40.         if data["action"] == "announce" then
  41.             rednet.send(data["computer_id"], textutils.serialize({action="acknowledge", type="multimob", device="roof"}))
  42.         end
  43.     elseif data["action"] == "mobon" then
  44.         colorAllOn()
  45.         if mobs[data["mob"]] ~= nil then
  46.             colorOff(mobs[data["mob"]])
  47.         end
  48.     elseif data["action"] == "off" then
  49.         colorAllOn()
  50.     end
  51. end
  52.  
  53. colorAllOn()
  54.  
  55. if peripheral.isPresent(RADIO) and peripheral.getType(RADIO) == "modem" then
  56.     rednet.open(RADIO)
  57.     rednet.broadcast(textutils.serialize({action="announce", type="multimob", device="roof"}))
  58. else
  59.     print("Modem not found")
  60.     return
  61. end
  62.  
  63. while true do
  64.     ev,p1,p2,p3 = os.pullEvent()
  65.     if ev == "rednet_message" then
  66.         data = textutils.unserialize(p2)
  67.         if data["type"] == "multimob" then
  68.             data["computer_id"] = p1
  69.             processMessage(data)
  70.         end
  71.     end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement