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

Wireless Permission Program

Started by Macapple, 15 March 2012 - 12:46 PM
Macapple #1
Posted 15 March 2012 - 01:46 PM
Hi guys,i got an issue about creating a permission program using Modems…
I will explain situation…

•Player is desperate.
•Player saw my house.
•Player types "Permission" in the Computer.
•I see that someone asked for permission (Maybe in a monitor).
•Computer displays: "Someone asked permission to enter,give permission?"
•If i type Yes,the door opens and Player enters in my house.
•If i type No,a message says "Permission Denied" and Player goes away.

But (I'm noob with Modems) i cant't figure how to do this…can someone help me?
Wolvan #2
Posted 15 March 2012 - 02:22 PM
Yes easy. You first have to open a rednet modem port(
rednet.open(side)
). Then you have to set up the computer at the door so someone can type a message. You send this message with
rednet.send(id of your PC, read text)
and your PC is listening like this:

while true do --Listens as long as the program is active
id, text = rednet.read() - Listening to rednet
if text == "Typed text eg. permissions" then
shell.run("clear") --Clears the screen
print("Someone asks for Permissions")
print("Give access?")
write("yes/no: ")
reply = read() --Give the answer
if reply == "yes" then -- Do you allow it?
rednet.send("accept")
else
rednet.send("no")
end
end -- if text ==
end -- end while
While you type the computer downstairs uses this:

while true do
shell.run("clear")
print("Waiting for answer")
id, msg = rednet.receive()
if msg == "accept" then
print("Accepted. Please enter")
redstone.setOutput(side of the door, true)
sleep(5) -- Waits 5 seconds
redstone.setOutput(side of the door, false)
shell.run(Program name)
else
print("You are not allowed to enter")
sleep(5)
shell.run(Program name)
end
Macapple #3
Posted 15 March 2012 - 02:43 PM
Where to write this? Lua or simply a Text document in Saves/World/Computer
Macapple #4
Posted 15 March 2012 - 08:17 PM
Can someone please compile this for me?
I can't get it out with that code :D/>/>
Wolvan #5
Posted 15 March 2012 - 08:44 PM
Can someone please compile this for me?
I can't get it out with that code :D/>/>
OK Will do that for you :)/>/>
Macapple #6
Posted 15 March 2012 - 09:36 PM
Thank you so much,bro…i'm sorry i'm a newbie with modems…
:D/>/>
Macapple #7
Posted 19 March 2012 - 08:55 PM
UP!
Wolvan #8
Posted 19 March 2012 - 11:02 PM
You can just use my code can't you? Copy it in one of your computers and edit the variables if you have to
Macapple #9
Posted 21 March 2012 - 12:52 PM
I tried to use your code but it doesn't work…i write "permission" (Program name) and it does anything…
Pls tell me:
•Does BOTH computers need modems? (Open rednet)
•How much does the message for permission stay in my Computer?
•Need to write this by editing a program or in LUA?
Liraal #10
Posted 21 March 2012 - 12:54 PM
-Yes
-Till you press enter
-Program
Wolvan #11
Posted 22 March 2012 - 12:16 PM
I tried to use your code but it doesn't work…i write "permission" (Program name) and it does anything…
Pls tell me:
•Does BOTH computers need modems? (Open rednet)
•How much does the message for permission stay in my Computer?
•Need to write this by editing a program or in LUA?
Yeah that is probably because noone sends a asking message. I edit it for you

print("Door-Permissions v1.0 by Wolvan loaded")
while true do --Listens as long as the program is active
id, text = rednet.read() - Listening to rednet
if text == "perm" then
shell.run("clear") --Clears the screen
print("Someone asks for Permissions")
print("Give access?")
write("yes/no: ")
reply = read() --Give the answer
if reply == "yes" then -- Do you allow it?
rednet.send(id, "accept")
else
rednet.send(id, "no")
end
end -- if text ==
end -- end while

While you type the computer downstairs uses this:

function Main()
shell.run("clear")
print("Ring the bell?")
write("[y/n]: ")
txt = read()
if txt == "y" or txt == "Y" then
rednet.broadcast("perm")
while true do
shell.run("clear")
print("Waiting for answer")
id, msg = rednet.receive()
if msg == "accept" then
print("Accepted. Please enter")
redstone.setOutput(side of the door, true)
sleep(5) -- Waits 5 seconds
redstone.setOutput(side of the door, false)
Main()
else
print("You are not allowed to enter")
sleep(5)
Main()
end
else
Main()
end
end
Main()