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

computer controled prision

Started by deathvondoom, 22 January 2013 - 05:04 PM
deathvondoom #1
Posted 22 January 2013 - 06:04 PM
hello every one,

[indent=1]im trying to build a computr controled prision. there are 3 things i want to be able to do.[/indent]
the first is to be able to use a server to login to a client and open the cell (iron door) next to it.
the second is a master key (code) that opens all cells at once. and the last is to be
able to walk up to a client computer and be able to login. by loging in it opens the cell next to it.
ad only the cell next to it. now im just startin to learn how to write script. and what i mean is im noob.
if any one has any ideas or would like to help me code it that would be great. the prision will be huge
and i will put it on youtube with credits to all the help. thank you in advance for your help.
i have attached the code i have already.[attachment=959:code 1.jpg][attachment=960:code 2.jpg]

i would also like to say that the rednet script does not work but am i close?
3ydney #2
Posted 22 January 2013 - 07:00 PM
I'm trying to code something like this… Be right back

Edit: Wait what are looking for in this?
ikke009 #3
Posted 22 January 2013 - 10:52 PM
If rednet is too hard for you, you can just wire the master computer up to all the doors with bundled cables, and have the "client computers" directly next to each jaildoor.
Then you should be able to do everything you want without having to use rednet.
3ydney #4
Posted 22 January 2013 - 11:16 PM
Nope… Rednet is easy!
3ydney #5
Posted 23 January 2013 - 12:16 AM

local pass = "password"
local authkey = "p1cb7"
local rsos = "back"
for k,v in pairs( rs.getSides() ) do
  rednet.open( v )
end
cids = {
[15] = { id = 15 }
}
function send()
  local id, msg = rednet.receive()
  if cids[id].id == id  then
    rednet.send(tonumber(id), tostring(msg))
    rednet.send(tonumber(id), tostring(pass))
  end
end
send()

Server code ^^^^



Client code in next post
3ydney #6
Posted 23 January 2013 - 01:00 AM

rednet.send(14, "p1cb7")
rednet.receive()
id, msg = rednet.receive()
write("Password: ")
input = read("*")
if input == msg then
rs.setOutput("back", true)
end
deathvondoom #7
Posted 23 January 2013 - 02:38 PM
freepaidremake,
would you be able to explain your script line by line if possible?
i cant seem to make it work.

ikke,
thank you for the suggestion.
if i cant get rednet to work then i think ill use your idea.
redeye83 #8
Posted 23 January 2013 - 05:02 PM
If rednet is too hard for you, you can just wire the master computer up to all the doors with bundled cables, and have the "client computers" directly next to each jaildoor.
Then you should be able to do everything you want without having to use rednet.
If you need help with "making" the cells let me know. If I was you I would do this and use wireless redstone so you can have your central computer anywhere.
deathvondoom #9
Posted 23 January 2013 - 08:57 PM
If rednet is too hard for you, you can just wire the master computer up to all the doors with bundled cables, and have the "client computers" directly next to each jaildoor.
Then you should be able to do everything you want without having to use rednet.
If you need help with "making" the cells let me know. If I was you I would do this and use wireless redstone so you can have your central computer anywhere.
well i have tried using al wires now but it will not work from a remote. (computer)

the 2 things i need to be able to do is,
1. open a individual cell from the guard house
2. open the cell from the computer next to each cell. or other method. just want something that requires a key or password
so "inmates" can not open the doors freely.

again im new to LUA script but i am able to learn quickly. but the scripting required for what im doing is above me…
if any one knows any snippits of code that can help or if anyone knows how to do it please teach me.

to show the scope of the size of prision im building i have 44 cells so far.
the cells are all 4X4 cells. tis is just the first floor of the 1st cell block with 5 cell blocks.
so by the time im dont i will have 440 cells that all need to be controled by one main computer along with all of the indiviual ones
next to each cell. this also does not include the computer controlled doors that are for visitors, the mess hall, medical center,
and administration office. so the size of this will be huge.

again i thank you all in advance for the help.
ikke009 #10
Posted 23 January 2013 - 10:03 PM
Ok I just played around a bit with modems and stuff (never used them before xD) and I think I figured out how to do this..
So for the master computer edit startup and put this code there (ill try to explain it), also put a modem on top of it. Also there are a couple of variations on the password system and menu but I used the most simple ones here.

jail = {3,4,5} --put the computer id's of the jail pc's in that table, starting with the first jail
rednet.open("top")
term.clear()
term.setCursorPos(2,3)
write("Enter password: ")
pass = read()
if pass == "nyan" then --nyan is the password here
  sleep(0.25) -- just so it looks a bit nicer
  term.clear()
  term.setCursorPos(2,3)
  write("What do you want to do?")
  term.setCursorPos(2,4)
  command = read()
  if command == "open" then
    term.setCursorPos(2,5)
    write("Open jail nr.: ")
    x = read() --make sure to type a number here or it will crash
    if jail[x] then --if jail number x exists
	  rednet.send(jail[x],"open")
    end
  elseif command == "close" then
    term.setCursorPos(2,5)
    write("Close jail nr.: ")
    y = read() --make sure to type a number here or it will crash
    if jail[y] then --if jail number y exists
	  rednet.send(jail[y],"close")
    end
  end
else -- if the password was incorrect
  os.reboot()
end

now for the jail pc's add this code

mainpc = 1 --This should be the ID of the main pc
timeout = 0.5 --timeout time for timer
gtID = nil --
while true do
  gtID = os.startTimer(timeout)
  ev,p1 = os.pullEvent()
  if ev == "timer" and p1 == gtID then
    local rID,msg = rednet.receive(5)
    if rID == mainpc then
	  if msg == open then
	    rs.setOutput("right",true) --if the jaildoor is to the right of the pc
	  elseif msg == close then
	    rs.setOutput("right",false)
	  end
    end
  elseif ev == "key" then
    term.setCursorPos(2,3)
    write("Password: ")
    pass = read()
    if pass == "nyan" then
	  term.setCursorPos(2,4)
	  write("What do you want to do?")
	  command = read()
	  if command == "open" then
	    rs.setOutput("right",true)
	    sleep(5) --after 5 seconds door closes again
	    rs.setOutput("right",false)
	  end
    else -- if the password was wrong
	  os.reboot()
    end
  end
end

I did not test this code so i dont know if it works, but you should be able to fix it and make it better looking..
Willibilly19 #11
Posted 23 January 2013 - 10:04 PM
That could be accomplished easily with Wireless Redstone. I'd say put 2 wireless receivers under each door. One Frequency set to the room number, and one Frequency set to a number that you won't be using(1000 or so). Then when you run the code on your computer, have it either open a single door by telling it the room number, or to open all the doors by giving it that master frequency.

Having it so you can open each door individually from the cell, you could either have a computer at each cell…or you could carry a remote around with you to turn that frequency on. If you need help with it, I'd be glad to help you.
redeye83 #12
Posted 24 January 2013 - 01:41 AM
Well I'm not sure how real prisons are set out (I've never been caught and even if I was those pens fell in my bag) but I would have a guard station per cell block, then have 1 computer per cell block with all the doors wired up wireless (try normal redstone to a receiver) and like Willibilly19 said have a master frequency so you can open all the doors from a master computer elsewhere.
deathvondoom #13
Posted 21 July 2013 - 02:55 PM
i had figured it out. you use 2 computers at the cell door. one as like a normal password door computer the other waits for rednet message
diegodan1893 #14
Posted 22 July 2013 - 06:13 AM
It can be done with only 1 computer at the cell door with events. I think this tutorial would be usefull http://www.computerc...1156#entry11156
Sharidan #15
Posted 22 July 2013 - 08:20 PM
Hmm … interesting idea …

I might give it a try at writing the applications needed to control it all.

I have no idea how you have designed the prison building itself, but I'm assuming that you have wings/halls of cells, maybe cell blocks, maybe several floors? The layout of the prison would probably dictate how some of the programs need to be written.

I'd probably do this with 4 different applications:
1) door client - only accepts commands from the prison server and defaults all doors connected to it, to closed.
2) guard client - only connects to the prison server and gets a list of doors from the server.
3) warden's computer - only connects to the prison server and allows full control of all doors aswell as all guard clients.
4) prison server - does all of the controlling in the prison.

If the overall surface dimensions of the prison is too big, you may need more than one server computer to control all of it given distance problems, however if the size is within range of the server computer (place it as high up as possible in the prison building) you should only need one server.

EDIT: Could you possibly post a screenshot of one of your cell blocks? maybe one that shows how you have setup the computers by the cell doors? Just to give us an idea of how the prison is layed out :)/>/>

EDIT 2: Ok, I have set up two models for controlling the doors: one model where I have a computer hidden away in the floor/wall between two cell doors, leaving it to control only two doors, but allows for a single block seperation between prison floors/levels. As long as cells are placed on top of each other, nobody would be able to access the computer.
The second model requires more space between floors/levels, but allows a single computer to control 4 doors in it's current setup. A hollow space of 2 blocks is require between floors/levels for this setup to work. Space is needed for redstone wires and the wireless modem :/
Personally I think I'll go with the first door setup: it does require more computers, but it allows for a nicer design of the building itself. Destroy the floor block between two cells to access the computer.
I'll look into building up some code to control all of this …
Edited on 22 July 2013 - 07:03 PM
deathvondoom #16
Posted 04 October 2013 - 11:41 PM
i had finished the set up of this after about a few months of work. so the whole prison (about 750 cells) is controlled by one server.
all cells that were out of range i had put other computers that were set up like wifi range extenders. this worked great but i had to do a crap load of research to do it.
also i had incorporated sharidans idea of a wardens computer which can not open cells but tells you the status or the cell doors. thank you all for your help.