Advertisement
gelatine87

sleep/rain/thunder disabler

May 27th, 2023
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | Gaming | 0 0
  1. ----------------------------------------------------------------------------
  2. -- Config
  3. ----------------------------------------------------------------------------
  4. local occupations = {"guardtower", "barrackstower", "netherworker"}
  5. ----------------------------------------------------------------------------
  6. -- INITIALIZATION
  7. ----------------------------------------------------------------------------
  8. local colony = peripheral.find("colonyIntegrator")
  9. local env = peripheral.find("environmentDetector")
  10. local skipNight = false
  11. ----------------------------------------------------------------------------
  12. -- MAIN
  13. ----------------------------------------------------------------------------
  14.  
  15. local function has_value(tab, val)
  16.     for index, value in ipairs(tab) do
  17.         if value == val then
  18.             return true
  19.         end
  20.     end
  21.  
  22.     return false
  23. end
  24.  
  25. -- Scan for requests periodically.
  26. while true do
  27.     local now = os.time()
  28.     if colony and peripheral.isPresent(peripheral.getName(colony)) then
  29.         if colony.isInColony() then
  30.             if now < 5 or now > 19.5 then
  31.                 if not skipNight then
  32.                     local citizens = colony.getCitizens()
  33.                     skipNight = true
  34.                     for _, citizen in pairs(citizens) do
  35.                         if citizen.home ~= nil and textutils.serialiseJSON(citizen.location, true) ~=
  36.                             textutils.serialiseJSON(citizen.bedPos, true) then
  37.                             skipNight = false
  38.                             if citizen.work and has_value(occupations, citizen.work.type) then
  39.                                 skipNight = true
  40.                             end
  41.                             if not skipNight then
  42.                                 if citizen.work then
  43.                                     term.clear()
  44.                                     term.setCursorPos(1, 1)
  45.                                     print("name: ", citizen.name, "job: ", citizen.work.type)
  46.                                     sleep(0.15)
  47.                                 else
  48.                                     term.clear()
  49.                                 end
  50.                                 break
  51.                             end
  52.                         end
  53.                     end
  54.  
  55.                     if skipNight then
  56.                         redstone.setOutput("right", true)
  57.                         sleep(1)
  58.                         redstone.setOutput("right", false)
  59.                     else
  60.                         redstone.setOutput("right", false)
  61.                     end
  62.                 end
  63.             else
  64.                 skipNight = false
  65.                 redstone.setOutput("right", false)
  66.             end
  67.         end
  68.     else
  69.         colony = peripheral.find("colonyIntegrator")
  70.     end
  71.     -- Rain/Thunder disabler
  72.     if env and peripheral.isPresent(peripheral.getName(env)) then
  73.         if env.isRaining() == true or env.isThunder() == true then
  74.             redstone.setOutput("left", true)
  75.             sleep(1)
  76.             redstone.setOutput("left", false)
  77.         else
  78.             redstone.setOutput("left", false)
  79.         end
  80.     else
  81.         colony = peripheral.find("environmentDetector")
  82.     end
  83.     -- Rain/Thunder disabler
  84.     sleep(1)
  85. end
  86.  
Tags: lua CC:Tweaks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement