Jump to content

Customizable Player Proximity Detecting Door


Recommended Posts

zzsh7BZ.png

This is a customizable player proximity detecting door that uses computercraft and opencc sensors. It is very easy to setup and doesn't require much computercraft or opencc sensor knowledge to get working. Check out my video to see this in action and how to build it. You can also find the source code in the description of the video.

Update 6/15/2013

  • Temporarily removed the feature to reset settings
  • Readded the feature to reset settings. Just follow the on screen instructions on how to reset the settings

Update 5/31/2013

  • Fixed an error if you weren't using the new key system
  • Added the ability to reset the settings if you want to make changes like add new names, add/remove key system etc etc.

Update - 5/28/2013

I added an option to add a "key" to the program. Just set this up as shown in the video but you will now get an extra prompt if you want to use this new key system. This new function will make it so you have to hold a user defined item for the door to open. This can come in handy if you don't want the door to open up even if you are in sensor range.

Link to comment
Share on other sites

i posted this on your vid but i will post it here as well

this is good however i see in the api that a defined radius is there as well this would be nice to have i would add it myself but im not sure where i havent done any lua for long time any chance you could a var for that

that way i could use it to turn off my me system when im not right infront of the screen

also for a house door it would close behind me

·

ok not just me i guess lol

Link to comment
Share on other sites

would also be nice if you made it so we could edit allowed players without starting from scratch i think creating a file to reference players from would allow that course you would need to write in and end and it listen for input to end program

Link to comment
Share on other sites

Alas I don't think there is an "easy" way to implement a custom radius. Sadly both the computers and sensors don't keep track of their own XYZ locations in the world (computers can but you have to setup a complex network of at least 4 computers to triangulate their XYZ coordinates within the world). This makes entering a custom radius pretty much impossible unless I'm missing something within the APIs. The best way to have done this would have been to have the computer or sensor know its location within the world and then check for the player's location in the world. The computer could do some basic maths with the help of Pythagoras theorem to then create a line between yourself and the sensor. Once that line was set you could easily just measure the line and if the line is less then or equal to your custom radius, the door would open.

However, I can see where having the default radius of the mark 1 sensor card is a little to big for certain setups so instead of a custom radius I am currently working on alternative to custom radii. I am adding an option that will only open the door if you are within the default radius and are currently holding a specific item of your choice. This way you could stand next to the door and it won't open unless you are holding, for example, a piece of cooked pork. The door will still check if you are even on the white list of people with access to the door. I should have this update done sometime very soon.

TL: DR Can't do radius because its fucked, adding alternate shit to make it better

Link to comment
Share on other sites

im looking for the code i saw on a wiki that had the radius variable soon as i find it again i will post it here for you it involved telling the computer where the block you wanted turned on was in relation to the computer and then setting a radius for turning it on when the player got within the radius of the block it would turn on the block

aha found it here it is

os.loadAPI("ocs/apis/sensor")

-- the location of the redstone lamp relative to the sensor

local offset = {

X = 1,

Y = 1,

Z = 0

}

-- how close a player has to be to activate the lamp

local radius = 5

-- find the distance from the player position to the offset

function distance(pos)

local xd = pos.X - offset.X

local yd = pos.Y - offset.Y

local zd = pos.Z - offset.Z

return math.sqrt(xd*xd + yd*yd + zd*zd)

end

local proximity = sensor.wrap("left")

while true do

local signal = false

local targets = proximity.getTargets()

for k, v in pairs(targets) do

if distance(v.Position) < radius then

signal = true

end

end

rs.setOutput("top", signal)

end

Link to comment
Share on other sites

I am aware of this peice of code on the computercraft wiki, but as far as I can tell this won't work. As I described already in a previous post...

The best way to have done this would have been to have the computer or sensor know its location within the world and then check for the player's location in the world. The computer could do some basic maths with the help of Pythagoras theorem to then create a line between yourself and the sensor. Once that line was set you could easily just measure the line and if the line is less then or equal to your custom radius, the door would open.

This code would work if computers knew their coords.

I'll break down this code to hopefully show why this does not work. So in the main loop we are using the sensor to look for any entities within its range. Lets say you set this up and your coords are at x = 255,y = 63, and z = -689 (pretty damn normal coords) and you are within the computer's sensor range. This program will take your coords mentioned and subtract the offset of the sensor relative to the computer. These new coords would be x = 254, y = 62, and z = -689. Then it would take these coords and input them into the Pythagoreon theorem. The x coord squared is 64516, y squared is 3844, and z squared is 474721. Next it adds them up which is 543081. Finally it takes this sum, finds its square root which is roughly 737, and then sends this final number to see if it is less than the radius (which in this case is 5). Obviously 737 is not less than or even close to 5. No matter where you stand within this sensor's range it will never even come close to 5. Simply put, this code will not work.

As far as adding a way to edit the player white list without having to pick up and place the computer back down I can probably do that.

Link to comment
Share on other sites

Ok i hear what your saying and now without prejudice I must ask did you test it in game to see if it works either way I will test latter I can't right now

I still think that if we simply have the computer ask for its location and then have it run the code it should be able to allow custom radius

if you don't feel like continuing to work on this I understand if I could please have your permission I would like to enlist other help from the cc community I of course will give credit for your code

Link to comment
Share on other sites

I did test this in game and it looks like I was correct. Yes it is possible to do this by inputting the location of the computer but that can make things less user friendly and less streamlined. I want this program to be easy to use, and the more times the program asks for inputs the higher the chance for mistakes on the user's end. Instead of worrying about using a specific radius why not just use the new key feature I added? That way you can just have the door open at any radius (as long as its in sensor range, which can be massive if using a mark 4 card).

Link to comment
Share on other sites

i can see your point about user friendliness however if like your key it could simply be an optional feature it would eliminate that problem and i can see your point about mistakes however i don't think your giving enough credit to ppl yes there are some complete idiots out there with barely enough brains to breath let alone come in from the rain

however it is my opinion that if the question were posed by the computer in a matter of fact way it would be simple enough for most players to muddle through with very few errors and would make it more customizable and suitable for a larger variety of uses aside from a door lock and opener however i respect your decision to go in a different direction with it and only ask permission to take your code as it is now and expand on it to the ends that i wish to see it accomplish with the help of the cc community all credit for the original code will still go to you

one more note i am certainly not knocking your work or your code i think it was very well written i just believe it can do more then it currently is i am not trying to take anything from you or your work

thanks

Link to comment
Share on other sites

i think what im going for is something using your code that i could have run multiple things like open the door turn on me system turn on light all depending on where i was in the building esentially creating a smart home in minecraft at least that my vision

Link to comment
Share on other sites

So I tried to replicate this, used the correct pastebin information however the sensor computer appears to have an issue detecting me, the door never opens. Any thoughts on this problem or ways to troubleshoot? and yes the password and port are identical.

Link to comment
Share on other sites

cases are all the same, I've detected no errors on the user side that I can see, and since others are using the code fine, it's either a placement error( I doubt it, tested a setup identical to OP's video) or I'm encountering some sort of problem with a mod or two.

Link to comment
Share on other sites

nope, just not opening, as though either not detecting me, or not sending the signal to the computer above to turn off the signal. Is there a way to change it so it will open when any player is near? this is SSP so I'm not too concerned with the other players issue.

Link to comment
Share on other sites

Ok heres an imgur album of what Ive got building, I popped one of the redstone up so you could see the interior, and if it looks like more than the OP did, I double sided the door, so it is clean on both sides which shouldn't affect the switch one bit. Viola

Something I noticed I don't know if it means anything, but the modem on the top computer has a red ring around it and the one on the bottom does not. may be nothing though.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...