Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CC Redstone Alarm by Teki
- local side = "back"
- local tArgs = { ... }
- local startActive = 0
- local redstoneState = "inactive"
- local curTime = 0
- local hours = 0
- local minutes = 0
- local startHour = 0
- local startMin = 0
- local endHour = 0
- local endMin = 0
- if #tArgs > 4 then
- startActive = tonumber(tArgs[5])
- if startActive == 1 then
- redstone.setOutput(side, true)
- else
- redstone.setOutput(side, false)
- end
- end
- if #tArgs > 3 then
- startHour = tonumber(tArgs[1])
- startMin = tonumber(tArgs[2])
- endHour = tonumber(tArgs[3])
- endMin = tonumber(tArgs[4])
- elseif #tArgs > 1 then
- startHour = tonumber(tArgs[1])
- endHour = tonumber(tArgs[2])
- else
- print("Tape RedstoneAlarm <1> <2> <3> <4> <5>")
- print("<1> : Heure de depart")
- print("<2> : Minutes de depart")
- print("<3> : Heure de fin")
- print("<4> : Minutes de fin")
- print("<5> : (0/1) Redstone Inactive/active au demarage")
- return 0
- end
- function getTime()
- hours = http.get("http://www.timeapi.org/gmt/in+1+hour?format=%25H")
- minutes = http.get("http://www.timeapi.org/gmt/in+1+hour?format=%25M")
- end
- function activate()
- if startActive == 1 then
- redstone.setOutput(side, false)
- else
- redstone.setOutput(side, true)
- end
- end
- function deactivate()
- if startActive == 1 then
- redstone.setOutput(side, true)
- else
- redstone.setOutput(side, false)
- end
- end
- while true do
- getTime()
- if hours ~= nil and minutes ~= nil then
- hours = tonumber(hours.readAll())
- minutes = tonumber(minutes.readAll())
- if hours >= startHour and hours <= endHour then
- if startHour ~= endHour then
- if hours == endHour and minutes < endMin then
- activate()
- elseif hours == startHour and minutes >= startMin then
- activate()
- elseif hours > startHour and hours < endHour then
- activate()
- else
- deactivate()
- end
- else
- if minutes >= startMin and minutes < endMin then
- activate()
- else
- deactivate()
- end
- end
- else
- deactivate()
- end
- if redstone.getOutput(side) == true then
- redstoneState = "active"
- else
- redstoneState = "inactive"
- end
- print(hours .. ":" .. minutes .. " : Redstone is " .. redstoneState)
- end
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement