Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("start")
- whitelist = {"furest","arthuremen1"}
- print("whitelist done")
- os.loadAPI("ocs/apis/sensor")
- mysensor = sensor.wrap("left")
- -- vérifie si le joueur détecté est whitelist
- function checkexist(nickname)
- for key, nom in pairs(whitelist) do
- if nom == nickname then
- return true
- end
- end
- return false
- end
- --Ouvre la porte
- function Ouvre()
- rs.setOutput("bottom", true)
- sleep(0.2)
- rs.setOutput("bottom", false)
- return true
- end
- --Ferme la porte
- function Ferme()
- rs.setOutput("right", true)
- sleep(0.2)
- rs.setOutput("right", false)
- return true
- end
- --Distance du centre de détection
- local offset = {
- X = 0,
- Y = 8,
- Z = 0
- }
- local rayon = 3
- --Calcule la distance
- 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 nearby()
- print("check")
- t = mysensor.getTargets()
- print("targets got")
- for name, details in pairs(t) do
- print(name)
- if details.Name == "Player" then
- local x = mysensor.getTargetDetails(name)
- print(x.Username)
- if checkexist(x.Username) and distance(details.Position) < rayon then
- print(x.Username .. " is there!")
- return true
- else
- return false
- end
- else
- return false
- end
- end
- end
- while true do
- proche = nearby()
- if proche then
- Ouvre()
- else
- Ferme()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement