Marlingaming

Big Brother Base

Sep 16th, 2021 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. --big brother base
  2. --this program handles the base operations of the big brother system. these functions includes communications, file management, security, propoganda, etc
  3. --this program is for Minecraft 1.16.5, CC Tweaked
  4. local modem = peripheral.find("modem") or error("No modem attached", 0)
  5. local Broadcasting = false
  6. modem.open(43)
  7.  
  8. function start()
  9. print("checking power status")
  10. modem.transmit(32, 43, "power_check")
  11. local event, side, channel, replyChannel, message, distance
  12. repeat
  13. event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  14. until channel == 43
  15. if message == "power_status.online" then
  16. print("power online")
  17. Boot()
  18. else
  19. print("power offline")
  20. print("shutting down....")
  21. os.sleep(5)
  22. os.shutdown()
  23. end
  24. end
  25.  
  26. function Boot()
  27. print("checking security systems")
  28. modem.transmit(33,43, "security_check")
  29. local event, side, channel, replyChannel, message, distance
  30. repeat
  31. event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  32. until channel == 43
  33. if message == "security_status.online" then
  34. print("security Online")
  35. print("starting alert broadcast")
  36. parallel.waitForAll(Broadcast("Boot.dfpwm",5),Main)
  37. else
  38.  
  39. end
  40. end
  41.  
  42. function Main()
  43. term.clear()
  44. term.setCursorPos(1,1)
  45. print("System Online")
  46. while true do
  47. local event, a, b, c, d, e, f, g = os.pullEvent()
  48. if event == "modem_message") then
  49. if d == "power_status.offline" then
  50. print("power offline")
  51. print("shutting down.....")
  52. os.sleep(7)
  53. os.shutdown()
  54. elseif string.find(d,"PublicAnnouncement_") then
  55. modem.transmit(8,43,string.sub(d,19,string.len(d)))
  56. if Broadcasting == false then Broadcast("PublicAnnouncement.dfpwm",5) end
  57. end
  58. else
  59. if os.time() > 5.5 and os.time() < 6.1 then
  60. if Broadcasting == false then Broadcast("Morning.dfpwm",5) end
  61. elseif os.time() > 19.5 and os.time() < 20.1 then
  62. if Broadcasting == false then Broadcast("Afternoon.dfpwm",5) end
  63. end
  64. end
  65. os.queueEvent("pass")
  66. end
  67. end
  68.  
  69. function Broadcast(file,channel)
  70. Broadcasting = true
  71. local dfpwm = require "cc.audio.dfpwm"
  72. local decoder = dfpwm.make_decoder()
  73. for input in io.lines(file, 16 * 1024) do
  74. local decoded = decoder(input)
  75. modem.transmit(channel,43,textutils.serialize(decoded))
  76. end
  77. Broadcasting = false
  78. end
  79.  
  80.  
  81. start()
Add Comment
Please, Sign In to add comment