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

OpenPeripherals Sensors

Started by Kekkers, 30 November 2015 - 02:16 AM
Kekkers #1
Posted 30 November 2015 - 03:16 AM
Hi all.

I am playing on a FTB Infinity Evolved server. I am living along side my group inside a large walled off compound.

There are many hostile players around, so we would like to use the sensors from OpenPeripherals in a large network going around the outer wall to detect approaching players.

Is it:
a) Possible to network sensors and still display relative coordinates of a detected player?
B)/> Possible to display all detected players (and their coordinates) on a monitor?
c) Possible to select a player off the list of players in range, to show more info about that player?
d) Possible to create a redstone pulse when a new player moves in range?

How often do sensors update?

Apologies if this is in the wrong section. I am not familiar with ComputerCraft, but am willing to learn how to do it so long as what I want to do is possible.

Thanks very much in advance.
Dragon53535 #2
Posted 30 November 2015 - 06:03 AM
This is in the right section, and I believe all of those are possible to do. As for how often sensors update, I don't remember, someone else will have to answer that.

If you have the coordinates of a sensor, and the relative coordinates of the players, you can easily add the difference to find their absolute coordinates.

Getting more info about a player, could possibly be more difficult. It's doable, but you'd have to remember which sensor that player is near in order to ask that sensor for more data.

The redstone pulse, probably easy if you have everything else done. The only problem I see that might come into effect is when they leave the range.
Bomb Bloke #3
Posted 30 November 2015 - 07:28 AM
The exact code varies a bit depending on what version of OpenPeripherals you're using. For what it's worth, I made a script along these lines here. There's quite a bit of reliance on tables to help organise the gathered info (which you may or may not be familiar with, but they're definitely worth reading up on if not), and I assume you'd prefer to write something to fit your actual needs - but it may give you some ideas, perhaps.

In my case the server owner extended the range of the sensors so that I only needed the one to cover the whole area. Rigging it to poll multiple sensors and collate the results indeed wouldn't be too difficult.

The basic tasks the script performs are to:

1) Detect when certain players are near a certain area of the base, and send a redstone signal to open a hidden door if so (revealing access to the computer running the sensor script).

2) Detect players in the area, and display their stats on attached monitors (I just automatically displayed the first however many players the sensors returned on however many monitors I hooked up; I stuck them in a row within my wall).

3) Detect when non-whitelisted players are in the base, and send a swarm of turtles running this script after them if so (which hid themselves in the flooring when they were otherwise inactive).

So it's fairly similar to what you're wanting to do.

I requested data from the sensors once per second, though that may've been overkill. The server in concern didn't have a lot of processing load to contend with so I didn't feel too guilty.
Kekkers #4
Posted 30 November 2015 - 03:32 PM
If a player is between two sensors at once, would it then be possible to only have one name show on the monitor?

How will the program know which sensor is which?
Dragon53535 #5
Posted 30 November 2015 - 04:15 PM
Each sensor has a name, "sensor_1" or whatever, you can save that, and compare the name with what you already have in a table you can see if the name already exists, and if no sensors see that player anymore then remove it.