Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Demo Motion Detector
- term.clear()
- term.setCursorPos(1,1)
- write("Press Ctrl+T to stop watching and try the 'ocs/programs/sensorview' tool. Also view the sensorDetailed examples in /disk/.")
- os.loadAPI("ocs/apis/sensor")
- -- the location of the redstone lamp relative to the sensor
- local offset = {
- X = 0,
- Y = 0,
- 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
- -- cruise through the targets to see about mob vs player
- local proximity = sensor.wrap("back")
- while true do
- local playersignal = false
- local mobsignal = false
- local targets = proximity.getTargets()
- for k, v in pairs(targets) do
- if distance(v.Position) < radius then
- if (v.Name == "Player") then
- playersignal = true
- else
- mobsignal = true
- end
- end
- end
- rs.setOutput("right", playersignal)
- rs.setOutput("left", mobsignal)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement