Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Gate Connection ]]--
- --[[ Countdown ]]--
- --[[ Timer ]]--
- --[[ by Dog ]]--
- --[[ aka ]]--
- --[[ HydrantHunter ]]--
- --[[ pastebin: ]]--
- --[[ T6xmhsJB ]]--
- local nHours = 0 --# leave this at 0
- local nMinutes = 1 --# 59 or less
- local nSeconds = 0 --# 59 or less
- local totalTime, hours, minutes, seconds, sHours, sMinutes, sSeconds, sTenths, countdownTimer
- local timer, sgEvent, event, _, newState, oldState, direction
- local lcGate, continue, SG_OutgoingOnly = false, false, false
- local gate = peripheral.find("stargate")
- if not gate then lcGate = true gate = peripheral.find("StargateBase") end
- if not gate then error("No Stargate located") end
- local mon = {
- peripheral.find("monitor",
- function(name, object)
- object.setTextScale(4)
- local x, y = object.getSize()
- if x == 7 and y == 1 then
- object.clear()
- object.setCursorPos(1, 1)
- if object.isColor() then object.setTextColor(colors.red) end
- object.write("00:00:0")
- return true
- else
- return false
- end
- end
- )
- }
- term.clear()
- term.setCursorPos(1, 1)
- if term.isColor() then term.setTextColor(colors.red) end
- term.write("00:00:0")
- while true do
- if lcGate then
- os.pullEvent("connect")
- continue = true
- else
- sgEvent, _, newState, oldState = os.pullEvent("sgStargateStateChange")
- if newState == "Connected" then
- if SG_OutgoingOnly then
- newState, _, direction = gate.stargateState()
- if newState == "Connected" and direction == "Outgoing" then
- continue = true
- end
- else
- continue = true
- end
- end
- end
- if continue then
- if mon[1] then
- for i = 1, #mon do
- mon[i].setTextColor(colors.white)
- end
- end
- term.setTextColor(colors.white)
- totalTime = (nHours * 36000) + (nMinutes * 600) + (nSeconds * 10)
- for i = totalTime, 0, -1 do
- hours = totalTime > 35999 and math.floor(totalTime / 36000) or 0
- sHours = tostring(hours)
- minutes = totalTime > 599 and math.floor((totalTime - (hours * 36000)) / 600) or 0
- sMinutes = minutes > 9 and tostring(minutes) or "0" .. tostring(minutes)
- seconds = totalTime > 9 and math.floor((totalTime - ((hours * 36000) + (minutes * 600))) / 10) or 0
- sSeconds = seconds > 9 and tostring(seconds) or "0" .. tostring(seconds)
- sTenths = tostring(math.floor(totalTime - ((hours * 36000) + (minutes * 600) + (seconds * 10))))
- term.setCursorPos(1, 1)
- if totalTime == 0 and term.isColor() then term.setTextColor(colors.red) end
- term.write(sMinutes .. ":" .. sSeconds .. ":" .. sTenths)
- if mon[1] then
- for i = 1, #mon do
- mon[i].setCursorPos(1, 1)
- if totalTime == 0 and mon[i].isColor() then mon[i].setTextColor(colors.red) end
- mon[i].write(sMinutes .. ":" .. sSeconds .. ":" .. sTenths)
- end
- end
- if totalTime > 0 then
- countdownTimer = os.startTimer(0.1)
- while true do
- event, timer, newState = os.pullEvent()
- if event == "timer" and timer == countdownTimer then
- totalTime = totalTime - 1
- break
- elseif event == "disconnect" or (event == "sgStargateStateChange" and newState == "Idle") then
- totalTime = 0
- if term.isColor() then term.setTextColor(colors.red) end
- term.setCursorPos(1, 1)
- term.write("00:00:0")
- for i = 1, #mon do
- if mon[i].isColor() then mon[i].setTextColor(colors.red) end
- mon[i].setCursorPos(1, 1)
- mon[i].write("00:00:0")
- end
- break
- end
- end
- end
- if totalTime == 0 then
- continue = false
- if lcGate then
- pcall(gate.disengageStargate)
- else
- pcall(gate.disconnect)
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment