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

Security door, need help!

Started by Keltecfanboy, 23 March 2013 - 01:02 PM
Keltecfanboy #1
Posted 23 March 2013 - 02:02 PM
Title: Securtiy door, need help!

Hello! So I have been working on a program that uses a player detector to open a door if the player is on a whitelist, and if they aren't deploy a turtle to attack them. My problem is that it opens for everyone. I don't know why, and have spent an hour messing with it. Here is my code:
Spoiler

print("Keltecfanboys Security System V2.0")
print("Right click the player detector to the left to begin!")

rednet.open("back")
local ul = fs.open("ulist")
local pds = "left"
local oside = "bottom"
local otime = "8"
local p = peripheral.wrap(pds)
local rign = os.pullEvent("player")

local l1 = ul.readLine(1)
local l2 = ul.readLine(2)
local l3 = ul.readLine(3)

if rign == l1 or l2 or l3 then
	rs.setOutput(oside, true)
sleep(tonumber(otime))
rs.setOutput(oside, false)
	else
print("Unauthorized user!")
	rednet.send(2, attack)
end

os.reboot()

Any help is appreciated.
lieudusty #2
Posted 23 March 2013 - 02:46 PM
Problem: if rign == 1 or 12 or 13
Solution if rign == 1 or rign == 12 or rign == 13
Keltecfanboy #3
Posted 23 March 2013 - 02:53 PM
Problem: if rign == 1 or 12 or 13
Solution if rign == 1 or rign == 12 or rign == 13
Now after using this it doesn't open for anybody, even ones on the whitelist.
Engineer #4
Posted 24 March 2013 - 03:56 AM
You should do something like this:


http://pastebin.com/LBN9e6HT

And the file you read should look like:

{[1] = "playername", [2] = "another" }

If you have questions please post them
Keltecfanboy #5
Posted 24 March 2013 - 08:18 AM
You should do something like this:


http://pastebin.com/LBN9e6HT

And the file you read should look like:

{[1] = "playername", [2] = "another" }

If you have questions please post them

I'm a little confused at this part:

local players = textutils.unserialize( reader ) -- You have to serialize before you write to a file
I wasn't trying to write to a file.
Engineer #6
Posted 24 March 2013 - 08:25 AM
You was reading of a file, so I assumed you was writing to it. Your ulist should look like this:

{[1] = "name", [2] = "anothername", etc..}
Keltecfanboy #7
Posted 24 March 2013 - 09:12 AM
You was reading of a file, so I assumed you was writing to it. Your ulist should look like this:

{[1] = "name", [2] = "anothername", etc..}
It works now, thank you.