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

Rednet doorlock!

Started by stilldabomb, 21 September 2012 - 02:22 AM
stilldabomb #1
Posted 21 September 2012 - 04:22 AM
This is just like a door lock but it runs off of Rednet!
Feedback welcomed!

______________________________________________________________________________________________________

Pastebin:


Transmitter:


or

pastebin get ixySUsSj Transmitter


Receiver:


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 :)/>/>.
Lithia #2
Posted 21 September 2012 - 04:23 AM
Nice! i was standing next to you on the server while you were coding this :)/>/>

Your a really good Coder Btw
stilldabomb #3
Posted 21 September 2012 - 04:24 AM
Haha, thanks Lithia :)/>/>
gijsdeb #4
Posted 23 September 2012 - 12:41 AM
print("this is awesome, i love this program")

term.write("you are a super coder") :P/>/>
stilldabomb #5
Posted 24 September 2012 - 03:01 AM
Thanks bro (or brah?)! I'm working on a turtle program (PezzTurtle) and I was working on our OS (PezzOS) and our API (PezzAPI) which had the RedWorks showWindow function, but I later gave up on PezzOS and PezzAPI and will probably be making a new OS and a new API by those names, anyone want to join in? Add me on skype, [Deleted Skype].
stilldabomb #6
Posted 24 September 2012 - 03:07 AM
Oh crap! Forgot to add the password check for the server! D:
stilldabomb #7
Posted 01 October 2012 - 06:14 AM
Almost to the 350 mark on views guys! :)/>/>
stilldabomb #8
Posted 05 October 2012 - 03:11 AM
Holly crap! We hit 450 views!!
rhyleymaster #9
Posted 06 October 2012 - 04:43 AM
Stilldabomb. This is pretty sick. Which server did you make this on? Immibis'?
stilldabomb #10
Posted 06 October 2012 - 05:08 AM
Nah, I was doing it in notepad++ XD I tested it on SSP and http://azacraft.enjin.com (198.50.25.35)
dmitchell94 #11
Posted 28 May 2013 - 02:07 PM
multiuser capabilities?