Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- -- the location of the redstone lamp relative to the sensor
- local offset = {
- X = 0,
- Y = -2,
- 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
- function zu()
- for i = 1,5 do
- rs.setOutput("right", true)
- sleep(0.5)
- rs.setOutput("right", false)
- sleep(0.5)
- end
- end
- function auf()
- for i = 1,5 do
- rs.setOutput("left", true)
- sleep(0.5)
- rs.setOutput("left", false)
- sleep(0.5)
- end
- end
- local proximity = sensor.wrap("top")
- while true do
- local signal = false
- local targets = proximity.getTargets()
- for k, v in pairs(targets) do
- if not rs.getInput("bottom", true) then
- if k ~= "MagmaLP" then
- zu()
- end
- end
- if distance(v.Position) < radius then
- if k == "MagmaLP" then
- auf()
- end
- end
- end
- if not rs.getInput("front", true) then
- zu()
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement