Advertisement
furest

Sensor door (buggy)

Aug 22nd, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. print("start")
  2. whitelist = {"furest","arthuremen1"}
  3. print("whitelist done")
  4. os.loadAPI("ocs/apis/sensor")
  5. mysensor = sensor.wrap("left")
  6.  
  7. -- vérifie si le joueur détecté est whitelist
  8. function checkexist(nickname)
  9.   for key, nom in pairs(whitelist) do
  10.     if nom == nickname then
  11.       return true
  12.     end
  13.   end
  14. return false
  15. end
  16.  
  17. --Ouvre la porte
  18. function Ouvre()
  19. rs.setOutput("bottom", true)
  20. sleep(0.2)
  21. rs.setOutput("bottom", false)
  22. return true
  23. end
  24.  
  25. --Ferme la porte
  26. function Ferme()
  27. rs.setOutput("right", true)
  28. sleep(0.2)
  29. rs.setOutput("right", false)
  30. return true
  31. end
  32.  
  33.  
  34. --Distance du centre de détection
  35. local offset = {
  36. X = 0,
  37. Y = 8,
  38. Z = 0
  39. }
  40. local rayon = 3
  41.  
  42. --Calcule la distance
  43. function distance(pos)
  44.   local xd = pos.X - offset.X
  45.   local yd = pos.Y - offset.Y
  46.   local zd = pos.Z - offset.Z
  47.   return math.sqrt(xd*xd + yd*yd + zd*zd)
  48. end
  49.  
  50. function nearby()
  51.     print("check")
  52.     t = mysensor.getTargets()
  53.     print("targets got")
  54.     for name, details in pairs(t) do
  55.         print(name)
  56.         if details.Name == "Player" then
  57.             local x = mysensor.getTargetDetails(name)
  58.             print(x.Username)
  59.             if checkexist(x.Username) and distance(details.Position) < rayon then
  60.                 print(x.Username .. " is there!")
  61.                 return true
  62.             else
  63.             return false
  64.             end
  65.         else
  66.             return false
  67.         end
  68.     end
  69. end
  70. while true do
  71. proche = nearby()
  72.     if proche then
  73.         Ouvre()
  74.     else
  75.         Ferme()
  76.     end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement