Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Redstone Activated Rings
- v1.0.0.1
- Created By: Fredyman_95
- ]]--
- -- User settings ----------------------------------------------------
- ringsAddress = {} -- {"Amun", "Khepri", ... "Felluca"}
- pauseBetweenDials = 3 -- Period in s between program restart after rings finish transport
- rsSignal = east -- Choose one of: east, west, south, north, top, bottom
- -- End of User settings ---------------------------------------------
- -- Declarations -----------------------------------------------------
- local component = require("component")
- local computer = require("computer")
- local event = require("event")
- local sides = require("sides")
- local term = require("term")
- local forceStop = false
- -- End of Declarations ----------------------------------------------
- -- Check of user settings and requirements --------------------------
- if type(pauseBetweenDials) ~= "number" then pauseBetweenDials = 3 end
- if pauseBetweenDials < 0 then pauseBetweenDials = 3 end
- if component.isAvailable("transportrings") then
- rings = component.transportrings
- NumberOfRings = 0
- for k,v in component.list() do if v == "transportrings" then NumberOfRings = NumberOfRings + 1 end end
- if NumberOfRings > 1 then
- io.stderr:write("Too Many Transport Rings Connected to Computer.")
- computer.beep()
- os.exit(1)
- end
- else
- io.stderr:write("No Transport Rings Connected")
- computer.beep()
- os.exit(1)
- end
- if component.isAvailable("redstone") then
- rs = component.redstone
- NumberOfRsIOs = 0
- for k,v in component.list() do if v == "redstone" then NumberOfRsIOs = NumberOfRsIOs + 1 end end
- if NumberOfRsIOs > 1 then
- io.stderr:write("Too Many Redstone Components Connected to Computer.(RedstoneIO or Redstone Card)")
- computer.beep()
- os.exit(1)
- end
- else
- io.stderr:write("No Redstone Component Installed. (RedstoneIO or Redstone Card)")
- computer.beep()
- os.exit(1)
- end
- -- End of Check of user settings-------------------------------------
- -- Events -----------------------------------------------------------
- local function startEvents()
- eventsActive = true
- eventInterrupted = event.listen("interrupted", function() forceStop = true end)
- eventTeleportStart = event.listen("transportrings_teleport_start", function(_, address, caller, initiating) mainRSLoop = false rsLockDialed = true end)
- eventTeleportFinished = event.listen("transportrings_teleport_finished", function(_, address, caller, initiating) rsLockDialed = false end)
- end
- local function cancelEvents()
- event.cancel(eventTeleportStart)
- event.cancel(eventTeleportFinished)
- event.cancel(eventInterrupted)
- eventsActive = false
- end
- -- End of Events ----------------------------------------------------
- -- Functions --------------------------------------------------------
- local function selectSide(rsSignal)
- if rsSignal == east then rsInput = sides.east
- elseif rsSignal == west then rsInput = sides.west
- elseif rsSignal == north then rsInput = sides.north
- elseif rsSignal == south then rsInput = sides.south
- elseif rsSignal == top then rsInput = sides.top
- elseif rsSignal == bottom then rsInput = sides.bottom end
- end
- local function dialRings()
- rsLockDialed = true
- for i,v in pairs(ringsAddress) do
- if forceStop then break end
- symbol = ringsAddress[i]
- rings.addSymbolToAddress(0, symbol)
- os.sleep(0.5)
- end
- if forceStop == false then
- os.sleep(0.5)
- computer.beep()
- rings.addSymbolToAddress(0, 5)
- end
- end
- -- End of Functions -------------------------------------------------
- selectSide(rsSignal)
- rings.addSymbolToAddress(0, 5)
- startEvents()
- ::start::
- term.clear()
- mainRSLoop = true
- rsLockDialed = false
- print("Press button to activate Transport rings")
- while mainRSLoop do
- if forceStop then goto closeProgram end
- if rs.getInput(rsInput) > 0 then break end
- os.sleep(0.1)
- end
- dialRings()
- while rsLockDialed do
- if forceStop then goto closeProgram end
- os.sleep(0.1)
- end
- os.sleep(pauseBetweenDials)
- goto start
- ::closeProgram::
- cancelEvents()
- print("All events listeners cancelled")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement