Advertisement
Redxone

[CC] - Home alarm system

Apr 2nd, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3. print("Nova Alarms - v1.0")
  4. local admin = "Lewisk3"
  5. local state = "on"
  6. local chat = peripheral.wrap("right")
  7. local alarm = peripheral.wrap("left")
  8. local log = ".log"
  9. local cmd = "alarm:"
  10.  
  11. local function update()
  12.   local ev, sd, pl, st = os.pullEvent()
  13.   if(ev == "chatbox_command")then
  14.     if(pl == admin)then
  15.       if(st:sub(1,#cmd) == cmd)then
  16.          state = st:sub(#cmd+1,#st)
  17.          chat.tell(admin,"Alarm state set to: " .. state)
  18.       end
  19.     end
  20.   end
  21.  
  22.     if(state=="on" and rs.getInput("front") and not alarm.isPlaying())then
  23.        print("Alarm triggered!")
  24.        chat.tell(admin,"Alarm has triggered!")
  25.        alarm.start()
  26.        local f = fs.open(log,"w")
  27.        f.writeLine(os.time() .. ": alarm triggered.")
  28.        f.close()
  29.     elseif(alarm.isPlaying() and state ~= "on")then
  30.        chat.tell(admin,"Stopping alarm...")
  31.        print("Stopping alarm")
  32.        alarm.stop()
  33.     end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement