daily pastebin goal
5%
SHARE
TWEET

alarmswitch

a guest Jan 12th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.broadcast("alarm:heartbeat:switch")
  2.  
  3. local idServer = 0
  4. local aAlarmstate = {}
  5.  
  6. while true do
  7.   idSender, sMsg = rednet.receive(1)
  8.   if type(sMsg) == "string" then
  9.     print("REDNET IN:" .. sMsg)
  10.     if (string.sub(sMsg, 1, 6) == "alarm:") then
  11.       if sMsg == "alarm:heartbeat:server" then
  12.         print("SRV idServer=" .. idSender)
  13.         idServer = idSender
  14.         rednet.send(idServer, "alarm:getAlarmTable")
  15.       elseif string.sub(sMsg, 7, 17) == "AlarmState:" then
  16.         aAlarmstate = textutils.unserialize(string.sub(sMsg, 18))
  17.         if aAlarmstate[1] == true then
  18.           redstone.setOutput("right", true)
  19.         else
  20.           redstone.setOutput("right", false)
  21.         end
  22.       end
  23.     end
  24.   end
  25.   if redstone.getInput("top") then
  26.     redstone.setOutput("left", true)
  27.     while redstone.getInput("top") do
  28.     end
  29.     redstone.setOutput("left", false)
  30.     redstone.setOutput("right", false)
  31.     aAlarmstate = {false}
  32.     print("REDNET OUT:alarm:setAlarmTable:" .. textutils.serialize(aAlarmstate))
  33.     rednet.send(idServer, "alarm:setAlarmTable:" .. textutils.serialize(aAlarmstate))
  34.   end
  35. end
RAW Paste Data
Top