Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local range = 1
- local height = 3
- local doorx = nil
- local doory = nil
- local doorz = nil
- local doorlog = 0
- local users = {}
- local close = 0
- rednet.open("bottom")
- while not doorx do
- doorx,doory,doorz = gps.locate()
- if not doorx then
- print("error, cant find doors location")
- else
- print("doors location: "..doorx..", "..doory..", "..doorz)
- end
- end
- function inRange(num,num2,min,max)
- local numdif = num - num2
- if numdif > min and numdif < max then
- return true
- else
- return false
- end
- end
- function checkPos(index)
- --data = textutils.unserialize(users[index])
- local message = users[index]
- data = textutils.unserialize(message)
- --print(message[1])
- if inRange(data[1],doorx,-range,range) and inRange(data[2],doory,-height,height) and inRange(data[3],doorz,-range,range) then
- close = close +1
- --print("Door opened for "..data[4].." "..close)
- end
- end
- function getMessage(timeout)
- --users = {}
- local senderId, packet, protocol = rednet.receive("GCP",timeout)
- if senderId and protocol == "GCP" then
- users[senderId] = packet
- --print(" "..senderId.."stored to users")
- return true
- else
- return false
- end
- end
- function printsomthing(index)
- --print(index)
- end
- while true do
- if getMessage(5) then
- table.foreach(users, checkPos)
- table.foreach(users, printsomthing)
- if close > 0 then
- --print("close="..close)
- redstone.setOutput("left",false)
- redstone.setOutput("right",false)
- else
- --print("far="..close)
- redstone.setOutput("left",true)
- redstone.setOutput("right",true)
- end
- close = 0
- else
- print("timeout, no location ping received")
- redstone.setOutput("left",true)
- redstone.setOutput("right",true)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement