Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------------------
- -- Config
- ----------------------------------------------------------------------------
- local occupations = {"guardtower", "barrackstower", "netherworker"}
- ----------------------------------------------------------------------------
- -- INITIALIZATION
- ----------------------------------------------------------------------------
- local colony = peripheral.find("colonyIntegrator")
- local env = peripheral.find("environmentDetector")
- local skipNight = false
- ----------------------------------------------------------------------------
- -- MAIN
- ----------------------------------------------------------------------------
- local function has_value(tab, val)
- for index, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- -- Scan for requests periodically.
- while true do
- local now = os.time()
- if colony and peripheral.isPresent(peripheral.getName(colony)) then
- if colony.isInColony() then
- if now < 5 or now > 19.5 then
- if not skipNight then
- local citizens = colony.getCitizens()
- skipNight = true
- for _, citizen in pairs(citizens) do
- if citizen.home ~= nil and textutils.serialiseJSON(citizen.location, true) ~=
- textutils.serialiseJSON(citizen.bedPos, true) then
- skipNight = false
- if citizen.work and has_value(occupations, citizen.work.type) then
- skipNight = true
- end
- if not skipNight then
- if citizen.work then
- term.clear()
- term.setCursorPos(1, 1)
- print("name: ", citizen.name, "job: ", citizen.work.type)
- sleep(0.15)
- else
- term.clear()
- end
- break
- end
- end
- end
- if skipNight then
- redstone.setOutput("right", true)
- sleep(1)
- redstone.setOutput("right", false)
- else
- redstone.setOutput("right", false)
- end
- end
- else
- skipNight = false
- redstone.setOutput("right", false)
- end
- end
- else
- colony = peripheral.find("colonyIntegrator")
- end
- -- Rain/Thunder disabler
- if env and peripheral.isPresent(peripheral.getName(env)) then
- if env.isRaining() == true or env.isThunder() == true then
- redstone.setOutput("left", true)
- sleep(1)
- redstone.setOutput("left", false)
- else
- redstone.setOutput("left", false)
- end
- else
- colony = peripheral.find("environmentDetector")
- end
- -- Rain/Thunder disabler
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement