This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
scriptn00b's profile picture

i need help with a wireless password door

Started by scriptn00b, 27 July 2012 - 06:54 AM
scriptn00b #1
Posted 27 July 2012 - 08:54 AM
I need a locking/door opening program set that sends signals from one computer to another one telling it to open the door I'm not very good at programing so i figured this would be the best place to find one
brett122798 #2
Posted 27 July 2012 - 09:11 AM
Well I don't have a script made for your purpose but.. if you know enough about scripting you can do this yourself with these two commands: rednet.send() and rednet.receive()

I'd make a script for you but I'm very very busy with Doctor Who, if you're wondering where I am, look at my location.


<——–
Rotaretilbo #3
Posted 27 July 2012 - 01:27 PM
I'm bored and I've recent set this up. For this setup, you're going to need three computers, two modems, a disk drive, and a floppy disk.

Computer 1
This computer accepts the password. It will have one of the two modems. Somewhere in your code there should be an if else statement, where the if handles if the password is correct and the else handles if it is incorrect. Add this somewhere into the if statement:
rednet.open("<side>") --where <side> represents whichever side the modem is on (acceptable input for this would be left, right, top, bottom, or back)
time = textutils.formatTime(os.time(),true)
message = "Access denied at "..time
rednet.send(<id2>, message) --where <id2> represents the id of Computer 2; you can discern this by running id on Computer 2
sleep(1)  --keep in mind that unless you put this after the line that closes the door, this will affect how long the door is open
rednet.close("<side>") --has to be same as whichever side you opened
You may also choose to add this to the else statement:
rednet.open("<side>") --as before, whichever side the modem is on
time = textutils.formatTime(os.time(),true)
message = "Access denied at "..time.." with "..<attempt> --where <attempt> represents whichever variable you used to read the password
rednet.send(<id2>, message) --again, id of Computer 2
sleep(1)
rednet.close("<side>") --as before, has to be same as side you opened

Computer 2
This computer will be two blocks from Computer 3, with the disk drive between the two and touching both. The floppy disk will obviously be in the drive. Computer 2 will have the second modem. It simply acts as a listener, waiting to receive messages from Computer 1. This is a simple listener program:
while true do
id,message = rednet.receive()
if id == <id1> then --where <id1> represents the id of Computer 1
  file = io.open("/disk/<logs>", "a") --where <logs> represents some blank program that you saved on the disk in the adjacent disk drive's disk
  file:write(message)
  file:close()
end
end

Computer 3
This is the computer you will be using to view the logs. As before, this needs to be adjacent to the disk drive, which is also adjacent to Computer 2. Here is a simple viewer program:
io.open("/disk/<logs>", "r") --again, <logs> being the blank program on the disk
Logs = {}
count = 0
for line in file:lines() do
if line ~= "" then --for whatever reason, any time you physically edit the /disk/<logs> file, it will add a blank line when you save and exit; this line ignores those
  table.insert(Logs, line)
  count = count + 1
end
end
loop = "yes"
while loop == "yes" do
print("There are ",count," logs.")
write("Which log would you like to view: ")
view = io.read()
if view < count + 1 then
  print(Logs[view])
  loop = "no"
else
  print("Invalid entry. Please try again.")
end
end

I've thrown this together somewhat on the spot, so there may be some basic errors in there, but this should convey the idea behind how to set up what you're looking for.
scriptn00b #4
Posted 27 July 2012 - 09:19 PM
ok thanks for that but i managed to make one that uses 3 consoles (or 2 if you only want a single door) and the same number of modems no floppy drives the only down fall is once the programs are written the consoles cannot be used for anything else other than the door programs but its a pretty simple code

Sending/password terminal startup

rednet.open(“side”)
shellrun(“Open”)

"Open"

pass = “password”
term.setCursorPos(1,2)
write “Password: “
input = read()
if pass == input then
term.clear()
term.setCursorPos(1,1)
write “Welcome message”
rednet.broadcast”command word”
else
term.clear()
term.setCursorPos(1,1)
write “denial message”
end
shell.run(“Open”)

receiving/opener startup

rednet.open(“Side of modem”)
shell.run(“door”)

"door"

a,b=rednet.receive()
print(:)/>/>
if b=="command word" then
redstone.setOutput(“side”, true)
sleep(#)
redstone.setOutput(“side”, false)
end
shell.run(“door”)

note: you can replace [rednet.broadcast()] with the [rednet.send()] just remember to use a new .send line for each door if your using double doors
Edited on 27 July 2012 - 07:21 PM