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

Sensor Alarm

Started by hbomb79, 30 June 2014 - 01:24 AM
hbomb79 #1
Posted 30 June 2014 - 03:24 AM
I have a tunnel system which has several bulkheads which close when I issue their closure through a PDA, although I want a alarm that detects intruders and send the signal to the master computer, I can handle the rednet stuff if someone can help me code a device to check who the sensor detects, I'm playing the mindcrack crackpack and I think the sensor is from opens peripherals addon… I don't know where to start


I understand this isn't somewhere for people to give code but your time will be greatly appreciated.
Bomb Bloke #2
Posted 30 June 2014 - 03:33 AM
You'll first want to determine how to use the peripheral. This guide should teach you how to figure that out.

If the device is a recentish OpenPeripheral block, you may also be able to get further information about the commands it grants you by entering into the prompt:

openp/docs <side> <methodname>
hbomb79 #3
Posted 30 June 2014 - 06:34 AM
… That doesnt help, I know how to use peripherals its just the tables and stuff i dont understand
Bomb Bloke #4
Posted 30 June 2014 - 07:19 AM
Righto then.
NanoBob #5
Posted 30 June 2014 - 10:24 AM
You can use sensor.getPlayerNames() (Ofcourse sensor. would be your wrap for the peripheral)
This will reutrn a table of all people withing sensor range. Then this way you can loop through them:
 for i,player in pairs(sensor.getPlayerNames) do
 
end
Then to check whether or not he is an intruder you could set up a whitelist using a table

whitelist={
["playerName"]=true,
["anoterName"]=true,
["nameyName"]=true,
}
function checkPlayers()
 for id,player in pairs(sensor.getPlayerNames) do
  if not whitelist[player] then
   --Your code to sound the alarm
  end
 end
end