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

Peripherals++ Player Sensor Door Lock

Started by Ninja8370, 30 April 2015 - 01:51 PM
Ninja8370 #1
Posted 30 April 2015 - 03:51 PM
I have been fooling around with this code for a while and it just won't work. I have a feeling I'm missing one very important thing.
I've tried Google searches on how to use Peripheral++ Player Sensors but I can never get any good results :(/>

Here's the code:


term.clear()
term.setCursorPos(1,1)

--os.loadAPI("/disk/sapi")

oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw

owner = "Ninja8370"
c = peripheral.wrap("top")

while true do
  term.clear()
  term.setCursorPos(1,1)

  a = c.getNearbyPlayers(4)
	
  intruder = false
	
	
	for i = 1, #a do
	
	  if a[i].players ~= owner then
		intruder = true
	  elseif a[i].players == owner and intruder == false then
		rs.setOutput("right",true)
		sleep(4)
		rs.setOutput("right",false)
		intruder = false
	  end

	end
  sleep(.5)
end

os.pullEvent = oldPull

Any help on making this work would be appreciated!
Edited on 30 April 2015 - 01:53 PM
KingofGamesYami #2
Posted 30 April 2015 - 03:55 PM
I found the wiki.
Ninja8370 #3
Posted 30 April 2015 - 04:04 PM
Okay, thankyou. (I think I found that wiki before, it gives barely enough info)

I added


for players, distance in pairs(a) do
   ...
end

It still does not work, any advice?
Edited on 30 April 2015 - 02:05 PM
KingofGamesYami #4
Posted 30 April 2015 - 06:06 PM
That is not how it works, the table returned by .getNearbyPlayers will look like this:

{
[1] = {player="KingofGamesYami", distance = 10}
}

Or, it might not have any keys:


{}


OFC, I haven't actually tried to use the sensor. I'm going off the wiki, which is kind of vague. I might make a PR to improve it.

Edit: After poking around, github doesn't allow PRs for wikis. How stupid :(/>
Edited on 30 April 2015 - 04:10 PM
Ninja8370 #5
Posted 01 May 2015 - 02:01 AM
Okay, thankyou! Someone else fixed up the program for me on the server I'm on. :)/>