Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turns and keeps the lights on the dock on from 12:00 PM to 6:00 AM
- nLightID = 1764
- bOn = false
- tLightsTimer = os.startTimer(5)
- function sendCommand(sCommand)
- rednet.open("top")
- if sCommand == "on" then
- rednet.send(nLightID, "lights_on")
- elseif sCommand == "off" then
- rednet.send(nLightID, "lights_off")
- end
- rednet.close("top")
- end
- function runLights()
- while true do
- local sEvent, param1 = os.pullEvent()
- if sEvent == "timer" and param1 == tLightsTimer then
- local sTime = textutils.formatTime(os.time(), false) -- The current time in the Minecraft world.
- local sTime_Period = sTime:sub(sTime:len() - 1, sTime:len()) -- AM or PM of the world time.
- local nTime_Hour = tonumber(sTime:sub(1, sTime:find(":", 1) - 1)) -- The current hour of the day.
- if bOn and nTimeHour == 12 and sTime_Period == "PM" then
- sendCommand("off")
- bOn = false
- -- If the time is between 8:00 PM to 6:AM then the lights should be on.
- elseif ((nTime_Hour < 6 and sTime_Period == "AM") or (nTime_Hour >= 6 and sTime_Period == "PM")) and (nTime_Hour ~= 12 and sTime_Period == "PM") and not bOn then
- sendCommand("on")
- bOn = true
- elseif ((nTime_Hour >= 6 and sTime_Period == "AM") or (nTime_Hour < 6 and sTime_Period == "PM")) and bOn then
- sendCommand("off")
- bOn = false
- end
- tLightsTimer = os.startTimer(5)
- end
- end
- end
- function runShell()
- while true do
- shell.run("shell")
- end
- end
- while true do
- parallel.waitForAny(runShell, runLights)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement