Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Simple OpenCCSensors player detector by wok86
- --based on code found in various places, like
- --CC forums and reddit.
- --Make sure you change the bits in the
- --editable section to suit before you start.
- --Version 0.6
- -------------------------------------------------
- --Start of editable section
- -------------------------------------------------
- --The players to detect
- local usersAllowed = {
- ["Player1"] = true,
- ["Player2"] = true,
- ["Player3"] = true
- }
- --The side the Sensor is on
- local sensorSide = "top"
- --The side to output the Redstone (RS) signal
- local rsSide = "right"
- --Time to sleep between iterations
- --Used for delay (how long to stay on/off)
- --Minimum value is 0.5
- local sleepTime = 0.5
- --Scanning range to activate RS signal
- --Value is radius spherical
- local radius = 5
- --Change these values if you want to offset the
- --center of the scanning area. Values should be
- --relative to the sensor, in whole numbers
- local offset = {
- X = 0,
- Y = 0,
- Z = 0
- }
- -------------------------------------------------
- --End of editable section
- -------------------------------------------------
- --Load the OCS Sensor API
- os.loadAPI("ocs/apis/sensor")
- --Set the variable "s" to the sensor
- local s = sensor.wrap(sensorSide)
- --Work out the position of things with 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
- --The meaty bit.
- while true do
- local pir = {}
- local signal = false
- local targets = s.getTargets()
- for target in pairs(targets) do
- local info = s.getTargetDetails(target)
- if info ~= nil then
- if info.Name == "Player" then
- if distance(info.Position) < radius then
- table.insert(pir, info.Username)
- end
- end
- end
- end
- for _,name in pairs(pir) do
- if usersAllowed[name] then
- signal = true
- else
- signal = false
- end
- end
- rs.setOutput(rsSide, signal)
- sleep(sleepTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement