Posted 21 September 2012 - 04:22 AM
This is just like a door lock but it runs off of Rednet!
Feedback welcomed!
______________________________________________________________________________________________________
Feedback welcomed!
______________________________________________________________________________________________________
Pastebin:
Transmitter:
or
pastebin get ixySUsSj Transmitter
Receiver:
http://pastebin.com/vDhVip8E
or
pastebin get vDhVip8E Receiver
______________________________________________________________________________________________________
Code:
Spoiler
Transmitter:
local modemSide = "right" -- Change to the direction of your modem!
local receiverId = 3 -- The ID of your receiver computer
local sel = 0 -- Used for selection of opening and closing.
local password = "password" -- Password, duh.
local isSetup = false -- Change to true after you have set everything up.
-- No edit past this line!
local checkPassword = false
if isSetup then
os.pullEvent = os.pullEventRaw
end
rednet.open(modemSide)
function checkArrowKeys()
event,param = os.pullEvent("key")
if event == "key" then
if param == 208 then
sel = sel + 1
if sel > 1 then
sel = 0
end
elseif param == 200 then
sel = sel - 1
if sel < 0 then
sel = 1
end
elseif param == 28 then
checkPassword = true
end
end
end
while true do
if checkPassword then
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then
rednet.send(receiverId, input)
sleep(2) -- Gives time for receiver to parse the password
if sel == 0 then
rednet.send(receiverId, "open")
checkPassword = false
elseif sel == 1 then
rednet.send(receiverId, "close")
checkPassword = false
end
end
else
term.clear()
term.setCursorPos(1,1)
if sel == 0 then
print("*Open*")
print(" Close")
elseif sel == 1 then
print(" Open")
print("*Close*")
end
checkArrowKeys()
end
end
Receiver:
local modemSide = "left" -- Change to the side of the modem...
local doorSide = "right" -- Change to the side of the door...
local transmitterId = 2 -- Change to the ID of the transmitter.
local password = "password" -- MUST BE THE SAME AS THE TRANSMITTER ONE!
local isSetup = false -- Change to true when you've edited all the variables
-- Don't edit past this line!
if isSetup then
os.pullEvent = os.pullEventRaw
end
rednet.open(modemSide)
while true do
id,msg = rednet.receive()
if id == transmitterId then
if msg == password then
id,msg2 = rednet.receive()
if msg2 == "open" then
rs.setOutput(doorSide, true)
elseif msg2 == "close" then
rs.setOutput(doorSide, false)
end
end
else
rednet.broadcast(id.." IS A FRAUD!")
end
end
______________________________________________________________________________________________________
How to get a computer's ID:
You just type ID in your computer :)/>/>.