Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- rs_lock v1
- local locks_enabled = false
- local pullEvent_snapshot = os.pullEventRaw
- function enable(freeze_signal_side)
- locks_enabled = true
- os.pullEventRaw = function(filter)
- while true do
- local e = { coroutine.yield() }
- if e[1] == "redstone" then
- if redstone.getInput(freeze_signal_side) then -- freeze!
- term.clear()
- if fs.exists("startup") then
- if fs.exists(".rslock") then
- fs.delete(".rslock")
- end
- fs.makeDir(".rslock")
- fs.move("startup", ".rslock/startup")
- local f = fs.open("startup", "w")
- f.write([[
- local freeze_signal_side = "]]..freeze_signal_side..[["
- local oldPull = os.pullEvent
- os.pullEvent = nil
- while true do
- local e = { coroutine.yield() }
- if e[1] == "redstone" then
- if not redstone.getInput(freeze_signal_side) then
- break
- end
- end
- end
- fs.delete("startup")
- fs.move(".rslock/startup", "startup")
- fs.delete(".rslock")
- os.pullEvent = oldPull
- local f = loadfile("startup")
- f()
- ]])
- f.close()
- end
- while true do
- local e2 = { coroutine.yield() }
- if e2[1] == "redstone" then
- if not redstone.getInput(freeze_signal_side) then
- break
- end
- end
- end
- fs.delete("startup")
- fs.move(".rslock/startup", "startup")
- fs.delete(".rslock")
- end
- end
- if filter == nil or e[1] == filter then
- return unpack(e)
- end
- end
- end
- end
- function disable()
- locks_enabled = false
- os.pullEventRaw = pullEvent_snapshot
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement